The TinaCMS CLI can be used to set up your project with a TinaCMS schema configuration, and run a local version of the TinaCMS GraphQL API (using your filesystem's content). For a real-world example of how this is being used checkout the TinaCloud Starter.
The @tinacms/cli
package will be installed as a dev dependency with the tina init command.
npx @tinacms/cli init
This will setup a dummy tina/config.{js,ts}
in your site, and install any required Tina dependencies.
tinacms dev
will compile the schema into static files, generate typescript types for you to use in your project, and start a GraphQL server on http://localhost:4001
This command also takes an argument (-c
) that allows you to run a command as a child process. This is very helpful for running a dev server and building your next.js app. The scripts portion of your package.json should look like this.
"scripts": {"dev": "tinacms dev -c \"next dev\"","build": "tinacms build && next build","start": "tinacms build && next start",...},
The reason we want to run the GraphQL API with our site is so that:
Now if you run the updated dev
script with:
npm run dev
or
yarn dev
Your live site will run, but so will a local version of the GraphQL Content API.
Your console might show something like:
> yarn devStarted Filesystem GraphQL server on port: 4001Visit the playground at http://localhost:3000/admin/index.html#/graphqlGenerating Tina config...
Once the graphql server is running, you can start to explore your graphQL content through the Altair client at http://localhost:3000/admin/index.html#/graphql
© TinaCMS 2019–2024