Get started

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 --help

Connect 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:write

Commands

CommandDescription
bytecontent entities:listList 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

  1. Run bytecontent export against development and commit the entities/ folder.
  2. Change files (or change the schema in the Admin Studio and export again) and open a pull request.
  3. In staging or production, run bytecontent schema:diff to review the plan, then bytecontent 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:diff never 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.ts
ts
// 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').

ByteContent by ByteRings is open source under the MIT License. Edit on GitHub