CLI Configuration
Relevant source files
The following files were used as context for generating this wiki page:
CLI Configuration in this project facilitates the interaction between the local development environment and the Sanity Content Lake. It defines how the Sanity CLI identifies the specific project and dataset to target during administrative tasks, schema extractions, and type generation.
The configuration ensures that developers can execute commands to manage content structures and sync environment variables across different hosting providers like Vercel or Netlify. This setup is critical for maintaining a "Native Authoring Experience" where the Studio and frontend remain in sync through shared configuration constants.
Sources: README.md:1-10, sanity.cli.ts
Core Configuration and Environment Variables
The primary CLI configuration is housed in sanity.cli.ts. This file utilizes a defineCliConfig function to export the project's identifying credentials. These credentials are consumed from environment variables to support multi-environment deployments (local, staging, production).
Identification Parameters
The CLI relies on two mandatory identifiers:
- Project ID: A unique identifier for the Sanity project.
- Dataset: The specific content partition (e.g., "production") within the project.
Sources: sanity/lib/api.ts:8-17, sanity.cli.ts
CLI Initialization Flow
The following diagram illustrates how the Sanity CLI initializes using the project configuration and environment variables.
The flow ensures that any CLI command executed locally targets the correct remote Sanity project.
Sources: sanity.cli.ts, sanity/lib/api.ts:8-17
Development Scripts and Automation
The project uses the CLI to automate repetitive tasks such as TypeScript definition generation and schema manifests. These are defined as NPM scripts.
| Script Name | Command | Purpose |
|---|---|---|
typegen | sanity schema extract && sanity typegen generate | Extracts the schema to JSON and generates TypeScript interfaces. |
build | next build --turbopack && sanity manifest extract... | Builds the frontend and extracts a Sanity manifest for the Studio. |
predev | npm run typegen | Ensures types are up-to-date before starting the dev server. |
Sources: package.json:7-17
Integration with Hosting Platforms
CLI configuration extends to how environment variables are synchronized with deployment platforms. The CLI tools provided by Vercel and Sanity are used in tandem to link local codebases to remote services.
Vercel Linkage
Developers use the Vercel CLI to pull environment variables that match the Sanity CLI configuration, ensuring the NEXT_PUBLIC_SANITY_PROJECT_ID is consistent across all layers.
Sources: vercel-installation-instructions.md:21-28
Netlify Configuration
For Netlify deployments, the netlify.toml file defines the expected environment variables that the Sanity CLI and API client require.
[template.environment]
NEXT_PUBLIC_SANITY_PROJECT_ID="Your Sanity Project Id"
NEXT_PUBLIC_SANITY_DATASET="Your Sanity Dataset"
Sources: netlify.toml:4-7
Schema Management via CLI
The Sanity CLI is the primary vehicle for evolving the content model. It provides the mechanism to "extract" the schema, which is then used by the TypeGen system to produce the sanity.types.ts file.
This process ensures that manual changes to files like sanity/schemas/documents/project.ts are reflected in the application's type system.
Sources: package.json:17, README.md:73-77
Summary of CLI Configuration
The CLI configuration acts as the bridge between local development and the Sanity backend. By centralizing credentials in sanity.cli.ts and leveraging NPM scripts for automation, the project maintains a robust workflow for schema evolution and type safety. Consistently applying these configurations across Vercel and Netlify ensures the personal website functions correctly in both development and production environments.