The TinaCMS CLI


The TinaCMS CLI can be used to set up your project with TinaCMS schema configuration, and run a local version of the TinaCMS API (using your file system's content). For a real-world example of how this is being used checkout the Tina Cloud Starter.

Installation

The CLI can be installed as a dev dependency in your project.

Npm:

npm install --save-dev @tinacms/cli

Yarn:

yarn add --dev @tinacms/cli

Usage

> yarn run tinacms

Usage: @tinacms/cli command [options]

Options:
  -V, --version             output the version number
  -h, --help                display help for command

Commands:
  server:start [options]    Start Filesystem Graphql Server
  schema:compile [options]  Compile schema into static files for the server
  schema:types [options]    Generate a GraphQL query for your site's schema,
                            (and optionally Typescript types)
  init [options]            Add TinaCMS to an existing project
  help [command]            display help for command

Getting started

The simplest way to get started is to add a .tina/schema.ts file

mkdir .tina && touch .tina/schema.ts

defineSchema

defineSchema tells the CMS how to build your content API.

// .tina/schema.ts
import { defineSchema } from '@tinacms/cli'

export default defineSchema({
  collections: [
    {
      label: 'Blog Posts',
      name: 'post',
      path: 'content/posts',
      fields: [
        {
          type: 'string'
          label: 'Title',
          name: 'title',
        },
      ],
    },
  ],
})

Run the local GraphQL server

Let's add some content so we can test out the GraphQL server

Add an author

mkdir content && mkdir content/authors && touch content/authors/napoleon.md

Now let's add some content to the author

---
name: Napoleon
---

Add a post

mkdir content/posts && touch content/posts/voteForPedro.md

Now we add some content to the post

---
title: Vote For Pedro
author: content/authors/napoleon.md
---

You should really vote for Pedro.

Start the filesystem server

> yarn run tinacms server:start

Started Filesystem GraphQL server on port: 4001
Visit the playground at http://localhost:4001/altair/
Generating Tina config
...

The below query can be run against your locally-running GraphQL server

Next Steps

Enable live-editing on your Next.js site

Deep dive on the Tina schema

Learn all about the GraphQL API