CLI and schema as code
The bytecontent CLI keeps your content model in version control. Export the schema to JSON files, review changes in pull requests, and push them to any environment with a preview first.
Setup
Build the workspace once (pnpm build), then run the CLI with Node.js:
bash
node packages/cli/dist/index.js --helpConnect it with environment variables or flags:
bash
export BYTECONTENT_URL=https://cms.example.com
export BYTECONTENT_API_KEY=bcms_xxxxxxxx_secret # scopes: metadata:read, metadata:writeCommands
| Command | Description |
|---|---|
bytecontent entities:list | List entities with field counts, versions and status |
bytecontent export [-d dir] | Write the schema to <dir>/entities/<key>.json |
bytecontent schema:diff [-d dir] [--prune] | Show what a push would change (read-only) |
bytecontent schema:push [-d dir] [--prune] [-y] [--allow-destructive] | Show the plan, confirm and apply it atomically (import is an alias) |
bytecontent types [-o file] | Generate TypeScript interfaces for your entities |
Schema as code
Each entity is one JSON file. Relations reference their target by entity key, so files are portable between environments:
json
{
"key": "article",
"name": "Article",
"titleField": "title",
"publicRead": true,
"publishField": "status",
"publishValue": "published",
"fields": [
{ "key": "title", "label": "Title", "type": "text", "required": true, "isPublic": true },
{
"key": "status", "label": "Status", "type": "select", "defaultValue": "draft",
"config": { "options": [{ "value": "draft", "label": "Draft" }, { "value": "published", "label": "Published" }] }
},
{ "key": "author", "label": "Author", "type": "relation", "config": { "targetEntity": "author" } }
]
}A typical workflow
- Run
bytecontent exportagainst development and commit theentities/folder. - Change files (or change the schema in the Admin Studio and export again) and open a pull request.
- In staging or production, run
bytecontent schema:diffto review the plan, thenbytecontent schema:push.
text
$ bytecontent schema:push
Plan: 3 change(s)
+ createEntity event
+ createField event.title
~ updateField article.title (label)
Apply these changes? [y/N] y
Applied 3 change(s).Safety rules
schema:diffnever changes anything.- A push is atomic: if any change fails, nothing is applied.
- Without
--prune, entities and fields missing from the files are left alone. - With
--prune, deletions are destructive and require--allow-destructive. - Field type changes are reported as conflicts and never applied automatically.
- Entities that still have records cannot be deleted.
The same operations are available over HTTP: GET /api/v1/admin/config/export, POST /api/v1/admin/config/diff?prune=true and POST /api/v1/admin/config/apply (body: the document plus prune and confirmDestructive).
Generate types
bash
bytecontent types --out src/cms-types.tsts
// src/cms-types.ts (generated)
export interface Article {
/** Title */
title: string;
/** Status */
status: "draft" | "published" | null;
/** Author */
author: string | null;
}Use them with the SDK: cms.records<Article>('article').