@airdraft/cli
v0.1.34
Published
Airdraft CLI — init, validate, migrate
Readme
@airdraft/cli
Command-line interface for Airdraft. Scaffolds projects, generates TypeScript types from your schema, validates configuration, and authenticates with Airdraft Cloud.
Installation
npm install -g @airdraft/cli
# or run directly
npx airdraft <command>Commands
airdraft init
Interactive project setup. Creates airdraft.config.ts, .env.local, and the Next.js API route handler.
npx airdraft init
npx airdraft init --force # overwrite existing filesModes:
local— local filesystem adapter (LocalAdapter); no GitHub requiredcloud-app— Mode 2: Airdraft Cloud GitHub App (project key from dashboard)own-app-auto— Mode 3: register your own GitHub App via browser flowown-app-manual— Mode 3: enter GitHub App credentials manually
The wizard also prompts for optional plugins (auth, media, seo, audit-log, schema-editor) and optionally scaffolds blog pages using @airdraft/react-content.
airdraft generate-types
Reads your schema and writes strongly-typed TypeScript interfaces to lib/cms-types.ts.
npx airdraft generate-types
npx airdraft generate-types --source ./airdraft.schema.json --out lib/cms-types.ts
npx airdraft generate-types --source https://your-project.airdraft.cloud/api/cms/schema --api-key <key>Options:
| Flag | Default | Description |
|---|---|---|
| --source | ./airdraft.schema.json | Local file path or HTTP(S) URL |
| --out | ./lib/cms-types.ts | Output file path |
| --api-key | — | Sent as x-api-key when fetching from a URL |
Generated output per collection:
- A
{Collection}Datainterface with all fields typed {Field}_url?: stringand{Field}_media?: { key, url?, name?, mimeType?, size? }companion fields forimageand singlemediafields{Field}_urls?: string[]and{Field}_medias?: Array<{...}>formediafields withmultiple: true- Named
{Collection}{Field}Block/{Collection}{Field}BlockIteminterfaces forblocksfields, with sub-fields typed inline - A
{Collection}Entrywrapper interface ({ slug, meta, data }) AnyEntryunion andCollectionNameliteral type
airdraft validate
Validates your airdraft.config.ts (or airdraft.config.json) and schema against the Airdraft spec.
npx airdraft validate
npx airdraft validate --config ./airdraft.config.tsairdraft generate-secret
Prints a cryptographically random 32-byte hex string. Use it to set AIRDRAFT_REVALIDATE_SECRET.
npx airdraft generate-secretairdraft login
Authenticates with Airdraft Cloud and stores a CLI token locally.
npx airdraft loginProgrammatic API
All commands are also importable for use in scripts and tests:
import { initProject, generateTypes, validateConfig, generateSecret } from '@airdraft/cli'| Export | Description |
|---|---|
| initProject(opts) | Runs the full init flow; accepts InitOptions for non-interactive use |
| generateTypes(opts) | Generates TypeScript types from a schema source |
| validateConfig(opts) | Validates config + schema; returns { valid, errors } |
| printSchema(schema) | Formats a CmsSchema as a human-readable string |
| generateSecret() | Returns a random hex string |
Changelog
See CHANGELOG.md.
