CLI reference

Schema

Introduction of Sanity TypeGen and Tasks Beta

v3.36.0

Installation and upgrading

To initiate a new Studio without installing the CLI globally:

npm create sanity@latest

To upgrade a Sanity Studio, run this command in its folder:

npm install sanity@latest

Sanity TypeGen (beta): Generate types for your schema and GROQ queries

This release comes with Sanity TypeGen, the new tooling in the Sanity CLI that enables extracting the schema into a static representation (schema.json) and to generate TypeScript type definition for it, as well as for GROQ query results.

You can learn more about Sanity TypeGen:

If you try out Sanity TypeGen, do let us know how it went in the #typescript channel in the Sanity community or to your customer success team.

Tasks (beta): Delegate work within Sanity Studio

This update also includes the beta of Tasks for Sanity Studio. It's a way to assign tasks related to documents, delegate them to team members, and track their status across the project.

A screenshot of the studio with the Task drawer open on the right side
Find the new Tasks in the upper right corner of the Studio

If you wish to disable tasks, you can do so by adding the following to sanity.config.ts:

export default defineConfig({
restOfConfig,
  unstable_tasks: {
    enabled: false,
  },
})

Documentation for Tasks is in the works and will be announced when ready.

🐛 Notable bugfixes

  • Fixes a bug where all fields got marked as non-optional when extracting schema with --enforce-required-fields.
  • Fixes a bug where Vision would insert a new line on cmd-return.

Problems with styled-components@5?

If you encounter an error such as TypeError: Cannot read properties of undefined (reading 'div'), please make sure your Studio doesn't depend on styled-components@5. Updating any such dependencies to styled-components@6 should resolve the error:

npm install styled-components@latest

New CLI Commands, Content Migration Tooling, Schema Validation, and Enhanced Localization & Validation Support

v3.27.0

Installation and upgrading

To initiate a new Sanity Studio without installing the CLI globally:

npm create sanity@latest

To upgrade a Sanity Studio, run this command in its folder:

npm install sanity@latest

✨ Highlights

New CLI command sanity migration create|list|run

You can now create, list, and run content migrations from the Sanity CLI. The new tooling lets you scaffold content migrations as code and run them in dry and production mode. It also introduces a new API for defining content migration with helper functions (defineMigration()).

You can explore the documentation for schema and content migrations; or learn more by running the following CLI commands in a Sanity Studio project folder:

sanity migration --help

You can run sanity migration create to explore our new content migration templates.

New CLI command: sanity schema validate

You can now validate a Sanity Studio schema with the CLI command sanity schema validate. Among other things, it will identify problems with your schema-type definitions. This tooling can be useful for running in CI/CD pipelines or debugging your schema configuration.

Learn more by running:

sanity schema validate ---help

Other features

  • Adds Studio UI localization support to the comments plugin
  • Adds support for validating dataset import and export files with sanity documents validate
  • Adds intentUrl in json and ndjson formats for sanity documents validate