datocms-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDatoCMS CLI Skill
DatoCMS CLI 技能
You are an expert at using the DatoCMS CLI (). Follow these steps in order. Do not skip steps.
datocms你是使用DatoCMS CLI()的专家,请按以下步骤操作,不要跳过任何步骤。
datocmsStep 1: Detect Context
步骤1:检测上下文
If the project context is already established in this conversation (CLI
package, config file, token, migrations directory, TypeScript setup), skip
broad detection below. Re-inspect only when a question cannot be answered
from prior context.
CLI + link is a required bootstrap for any repo that interfaces with a
DatoCMS project. The npm package installed + + is how the agent gets visibility into the live project (models,
fields, ids, record state). Missing → fix first, same as or
.
datocmsdatocms logindatocms linkgit initnpm install如果对话中已经明确了项目上下文(CLI包、配置文件、令牌、迁移目录、TypeScript设置),则跳过下面的通用检测。仅当现有上下文无法回答问题时,才重新检查。
对于任何与DatoCMS项目交互的仓库而言,CLI + 项目关联是必需的初始化步骤。 安装 npm包 + 执行 + 是让工具获取项目实时信息(模型、字段、ID、记录状态)的方式。如果缺失,需先修复,这和或的作用类似。
datocmsdatocms logindatocms linkgit initnpm installDetection (do not rely on which datocms
— the CLI runs via npx
)
which datocmsnpx检测方式(不要依赖which datocms
—— CLI可通过npx
运行)
which datocmsnpx- in
datocmsdevDependencies → CLI available. If missing, install it (package.json) — never fall back to pasted tokens or manual Dashboard steps.npm install --save-dev datocms - with a
datocms.config.jsonon the active profile → linked. If missing, drive the bootstrap below.siteId - succeeds → OAuth session active.
npx datocms whoami - directory → migrations already scaffolded.
migrations/ - or
tsconfig.json→ TypeScript migrations convention.migrations.tsconfig
- 的devDependencies中存在
package.json→ CLI可用。如果缺失,请安装它(datocms)—— 切勿使用粘贴令牌或手动操作控制台的方式替代。npm install --save-dev datocms - 的活跃配置文件中包含
datocms.config.json→ 已关联项目。如果缺失,请按照下面的初始化流程操作。siteId - 执行成功 → OAuth会话已激活。
npx datocms whoami - 存在目录 → 已搭建迁移脚手架。
migrations/ - 存在或
tsconfig.json→ 遵循TypeScript迁移约定。migrations.tsconfig
Bootstrap flow (CLI available but not linked)
初始化流程(CLI可用但未关联项目)
Only needs a terminal; the rest runs in non-TTY.
datocms loginbash
npx datocms login # user, one-time, interactive
npx datocms projects:list [hint] --json # agent discovers siteId
npx datocms link --site-id=<ID> [--organization-id=<ID>] # agent linksAlways confirm the target project with the user before running , even when returns a single candidate. Show the
candidate(s) (name, id, organization) and wait for an explicit yes. Do not
treat "only one result" as consent — the user may have access to a project
they did not mean to wire to this repo, and fixing a mis-linked project
later is painful.
datocms linkprojects:listdatocms link--site-id--site-iddatocms login只有需要交互式终端;其余步骤可在非TTY环境下运行。
datocms loginbash
npx datocms login # 用户仅需执行一次,交互式操作
npx datocms projects:list [hint] --json # 工具自动发现siteId
npx datocms link --site-id=<ID> [--organization-id=<ID>] # 工具关联项目在执行前,务必与用户确认目标项目,即使只返回一个候选项目。展示候选项目的信息(名称、ID、组织)并等待用户明确确认。不要将“仅一个结果”视为同意——用户可能有权访问并非想要关联到当前仓库的项目,后续修正错误关联会非常麻烦。
datocms linkprojects:list不带参数执行需要终端环境。在非TTY环境下,该命令会正常退出并提示传入参数;请勿在未传入该参数的情况下重试。当凭据缺失时也是如此——请先让用户执行。
--site-iddatocms link--site-iddatocms loginAuthentication policy
认证策略
- Interactive task (publish, delete, fix, backfill, introspect,
etc.): OAuth via +
loginis the mechanism. Never ask the user to paste a token or addlinktoDATOCMS_CMA_TOKEN=...for this case..env - Unattended execution (CI, cron, server-side app, shared scripts
without an OAuth session): CMA-enabled token via env var. Read-only
CDA tokens (,
DATOCMS_READONLY_API_TOKEN) will not work — flag that a separate CMA-enabled token is needed. The agent itself still needs CLI + link at development time for visibility.NEXT_PUBLIC_DATOCMS_API_TOKEN
Token resolution order the CLI uses:
- flag
--api-token - Linked project (OAuth-backed, the default after +
login)link - Env var: (default profile),
DATOCMS_API_TOKEN(named), or customDATOCMS_<PROFILE>_PROFILE_API_TOKENapiTokenEnvName - Profile override via
DATOCMS_PROFILE
- 交互式任务(发布、删除、修复、回填、内省等):使用+
login的OAuth认证机制。在这种情况下,切勿要求用户粘贴令牌或在link中添加.env。DATOCMS_CMA_TOKEN=... - 无人值守执行(CI、定时任务、服务器端应用、无OAuth会话的共享脚本):通过环境变量使用支持CMA的令牌。只读CDA令牌(、
DATOCMS_READONLY_API_TOKEN)无法生效——需告知用户需要单独的支持CMA的令牌。工具在开发阶段仍需要CLI + 项目关联来获取项目信息。NEXT_PUBLIC_DATOCMS_API_TOKEN
CLI使用的令牌解析顺序:
- 参数
--api-token - 已关联项目(基于OAuth,+
login后的默认方式)link - 环境变量:(默认配置文件)、
DATOCMS_API_TOKEN(命名配置文件)或自定义DATOCMS_<PROFILE>_PROFILE_API_TOKENapiTokenEnvName - 通过覆盖配置文件
DATOCMS_PROFILE
Step 2: Understand the Task
步骤2:理解任务
Classify the user's task into one or more categories:
| Category | Examples |
|---|---|
| CLI setup | Install CLI, authenticate ( |
| Schema changes | Add, modify, or remove models, fields, fieldsets, or block models — via a migration script (default) or a direct CMA operation against a chosen environment |
| Creating migrations | Scaffold new migration scripts, autogenerate from environment diffs, custom templates (sub-task of schema changes once the migration approach is chosen) |
| Running migrations | Execute pending migrations, dry-run, fork-and-run, in-place execution |
| Schema generation | Run |
| Direct CMA calls | Use |
| Environment management | Fork, promote, rename, destroy, list environments via CLI commands |
| Deployment workflow | Maintenance mode, safe deployment sequences, CI/CD integration |
| Multi-project sync | Shared migrations across blueprint/client projects via CLI profiles |
| Importing content | WordPress import, Contentful import |
| CLI plugin management | Install, remove, update, list, inspect, link, or reset CLI plugins ( |
将用户的任务归类为以下一个或多个类别:
| 类别 | 示例 |
|---|---|
| CLI设置 | 安装CLI、认证( |
| Schema变更 | 添加、修改或删除模型、字段、字段集或区块模型 —— 通过迁移脚本(默认方式)或针对指定环境的直接CMA操作 |
| 创建迁移 | 搭建新的迁移脚本、根据环境差异自动生成、自定义模板(选择迁移方式后,属于Schema变更的子任务) |
| 运行迁移 | 执行待处理的迁移、试运行、分支运行、原地执行 |
| Schema生成 | 执行 |
| 直接CMA调用 | 使用 |
| 环境管理 | 通过CLI命令分支、升级、重命名、销毁、列出环境 |
| 部署工作流 | 维护模式、安全部署流程、CI/CD集成 |
| 多项目同步 | 通过CLI配置文件在蓝图/客户端项目间共享迁移 |
| 内容导入 | WordPress导入、Contentful导入 |
| CLI插件管理 | 安装、移除、更新、列出、检查、关联或重置CLI插件( |
Step 2.5: Collect Critical Inputs Before You Commit To Commands
步骤2.5:执行命令前收集关键信息
Do not skip questions merely because the category is obvious. Skip follow-up
questions only if the request already includes the critical inputs for the
relevant category, or the repo inspection answers them safely.
Ask the minimum targeted question set needed to avoid flattening a real
workflow decision.
不要仅仅因为类别明确就跳过提问。仅当请求中已包含对应类别所需的关键信息,或仓库检查已安全获取这些信息时,才跳过后续提问。
提出最少的针对性问题,避免简化实际工作流决策。
Category-specific inputs live in the reference files
特定类别的信息参考对应文档
Each category reference loaded in Step 3 opens with an "Inputs to confirm
before running commands" section — that is the per-category equivalent of
this step. Do not skip loading the reference for the task's category: it
carries the workflow decisions this step is designed to protect. If you
skip it, you skip the checklist.
步骤3中加载的每个类别参考文档开头都有一个**“执行命令前需确认的信息”**部分——这是对应类别的检查清单。不要跳过加载任务所属类别的参考文档:它包含了本步骤旨在保护的工作流决策逻辑。如果跳过,就等于跳过了检查清单。
Schema changes — decide the approach with the user
Schema变更 —— 与用户确认操作方式
DatoCMS schema operations fall into four buckets. The choice of approach
is not automatic — ask the user when the bucket is not obvious from the
request, because reversibility and workflow preference matter more than
which tool performs the mutation.
| Situation | What it covers | Approach |
|---|---|---|
| Destructive schema change | DROP a field, DROP a model, | Migration via |
| Reversible schema change | Add a field, add a model or block, rename a field, toggle | Ask the user. Both approaches are safe; pick by preference and context. Lean to a migration ( |
| User-requested one-off | Phrases like "quickly, without a migrations workflow", "just patch this", "one-off", "don't scaffold migrations for this" | Honor the opt-out. Use direct mutation via |
| Content operation | Publish, unpublish, delete individual records, fix slugs, bulk update a field value, re-tag uploads | No migration needed. Prefer |
Regardless of which skill is loaded, the question to ask the user is
the same for a reversible schema change: "Do you want this as a
reviewable migration, or a direct mutation against a sandbox?" The
answer determines which skill owns the follow-up — not which skill was
loaded first.
Cross-skill routing.
- Destructive schema changes and the migration branch of a reversible
schema change are this skill's core: ,
migrations:new, fork-and-run, safe deployment. Stay here and loadmigrations:run+creating-migrations.md.running-migrations.md - User-requested one-offs, content operations, and the direct-mutation
branch of a reversible schema change are better covered by
datocms-cma. Switch when the user has opted out of migrations,
when the task is a content mutation (publish, delete, fix), or when
the user wants a or a checked-in
cma:scriptscript. The handoff is loading the sibling skill's references — do not bounce the user.buildClient() - Unattended runtime code (CI, app server, webhook, long-lived
automation) is a separate scenario — that is where a checked-in
script belongs, and datocms-cma owns that pattern.
buildClient()
DatoCMS的Schema操作分为四类。操作方式不是自动选择的——当请求中无法明确类别时,请询问用户,因为可逆性和工作流偏好比使用哪个工具执行变更更重要。
| 场景 | 覆盖范围 | 操作方式 |
|---|---|---|
| 破坏性Schema变更 | 删除字段、删除模型、 | 通过 |
| 可逆Schema变更 | 添加字段、添加模型或区块、重命名字段、切换 | 询问用户。两种方式都是安全的;根据偏好和上下文选择。当仓库已使用迁移工作流或用户在次要分支上时,优先选择迁移( |
| 用户要求的一次性操作 | 类似“快速操作,无需迁移工作流”、“直接修复这个”、“一次性操作”、“不要搭建迁移脚手架”的表述 | 尊重用户选择。使用 |
| 内容操作 | 发布、取消发布、删除单个记录、修复别名、批量更新字段值、重新标记上传资源 | 无需迁移。单次调用优先使用 |
无论加载的是哪个技能,对于可逆Schema变更,向用户提出的问题都是相同的:“你希望将此操作为可审核的迁移,还是直接在沙箱环境中执行变更?” 用户的回答决定后续使用哪个技能——而非最初加载的技能。
跨技能路由
- 破坏性Schema变更和可逆Schema变更的迁移分支是本技能的核心:、
migrations:new、分支运行、安全部署。留在本技能并加载migrations:run+creating-migrations.md。running-migrations.md - 用户要求的一次性操作、内容操作以及可逆Schema变更的直接变更分支更适合使用datocms-cma。当用户选择不使用迁移、任务是内容变更(发布、删除、修复)或用户需要或已签入的
cma:script脚本时,切换到该技能。切换方式为加载对应技能的参考文档——无需让用户重新发起请求。buildClient() - 无人值守运行代码(CI、应用服务器、Webhook、长期自动化)是单独的场景——这种情况下应使用已签入的脚本,由datocms-cma负责该模式。
buildClient()
Destructive and production-sensitive confirmations
破坏性和生产敏感操作的确认
Destructive schema changes always require these confirmations; the list
below also covers non-schema destructive commands.
If context is missing, ask for explicit confirmation before proposing final commands for:
environments:destroyenvironments:promote- imports into a non-obviously disposable target
- on a primary-like environment
migrations:run --in-place maintenance:on --forceenvironments:fork --fast --force- with
cma:call,destroy, orbulk_destroymethodspromote - direct schema mutations (via or
cma:call) targeting a primary-like environment instead of a migration on a forked sandboxcma:script - (removes all user-installed and linked CLI plugins)
plugins:reset
破坏性Schema变更始终需要以下确认;以下列表也涵盖非Schema的破坏性命令。
如果上下文缺失,在提出最终命令前,请明确确认以下操作:
environments:destroyenvironments:promote- 导入到非明显可丢弃的目标环境
- 在类主环境中执行
migrations:run --in-place maintenance:on --forceenvironments:fork --fast --force- 使用、
destroy或bulk_destroy方法的promotecma:call - 针对类主环境的直接Schema变更(通过或
cma:call),而非在分支沙箱环境中执行迁移cma:script - (移除所有用户安装和关联的CLI插件)
plugins:reset
Step 3: Load References
步骤3:加载参考文档
Based on the task classification, read the appropriate reference files from the directory next to this skill file. Only load what is relevant.
references/Always load:
- — Installation, configuration, profiles, global flags, token resolution
references/cli-setup.md
Load per category:
| Task category | Reference file |
|---|---|
| Creating migrations | |
| Running migrations | |
| Schema generation | |
| Direct CMA calls | |
| Environment management | |
| Deployment workflow | |
| Multi-project sync | |
| Importing content | |
| CLI plugin management | |
Load cross-cutting references when needed:
- If creating + running migrations together -> load both and
creating-migrations.mdrunning-migrations.md - If schema generation is followed by typed CMA code changes -> also load guidance for consuming the generated types
datocms-cma - If a direct CMA call grows beyond a one-off command -> switch to for reusable code
datocms-cma - If deployment involves environment commands -> also load
environment-commands.md - If multi-project sync involves rollout execution -> also load
running-migrations.md - If a CLI plugin install is specifically for WordPress/Contentful import -> also load
importing-content.md
根据任务分类,读取本技能文件旁目录中的对应参考文档。仅加载相关文档。
references/必须加载:
- —— 安装、配置、配置文件、全局参数、令牌解析
references/cli-setup.md
按类别加载:
| 任务类别 | 参考文档 |
|---|---|
| 创建迁移 | |
| 运行迁移 | |
| Schema生成 | |
| 直接CMA调用 | |
| 环境管理 | |
| 部署工作流 | |
| 多项目同步 | |
| 内容导入 | |
| CLI插件管理 | |
按需加载跨领域参考文档:
- 如果同时创建和运行迁移 -> 同时加载和
creating-migrations.mdrunning-migrations.md - 如果Schema生成后需要修改带类型的CMA代码 -> 同时加载关于使用生成类型的指南
datocms-cma - 如果直接CMA调用超出一次性命令的范围 -> 切换到编写可复用代码
datocms-cma - 如果部署涉及环境命令 -> 同时加载
environment-commands.md - 如果多项目同步涉及发布执行 -> 同时加载
running-migrations.md - 如果CLI插件安装是专门用于WordPress/Contentful导入 -> 同时加载
importing-content.md
Step 4: Generate Code
步骤4:生成代码
Write commands and scripts following these mandatory rules:
遵循以下强制规则编写命令和脚本:
Command Prefix
命令前缀
- Respect the repo's existing package-manager execution style when one is already established (,
npm run ...,pnpm exec ...)bunx ... - Otherwise default to so the local CLI version is used
npx datocms - Example:
npx datocms migrations:new "add blog model" --ts
- 当仓库已有明确的包管理器执行风格时,遵循该风格(、
npm run ...、pnpm exec ...)bunx ... - 否则默认使用,以确保使用本地CLI版本
npx datocms - 示例:
npx datocms migrations:new "add blog model" --ts
Migration File Templates
迁移文件模板
- When generating migration file content, use the exact function signatures from the reference files
- TypeScript:
export default async function(client: Client): Promise<void> - JavaScript:
module.exports = async (client) => {} - Import for TypeScript migrations:
import { Client } from 'datocms/lib/cma-client-node'
- 生成迁移文件内容时,使用参考文档中的精确函数签名
- TypeScript:
export default async function(client: Client): Promise<void> - JavaScript:
module.exports = async (client) => {} - TypeScript迁移的导入语句:
import { Client } from 'datocms/lib/cma-client-node'
File Naming
文件命名
- Migration files are automatically named:
{unix_timestamp}_{camelCaseName}.ts|.js - Do not manually create migration files — always use
npx datocms migrations:new
- 迁移文件自动命名为:
{unix_timestamp}_{camelCaseName}.ts|.js - 不要手动创建迁移文件 —— 始终使用
npx datocms migrations:new
Migration Script Bodies
迁移脚本主体
- For the CMA API calls inside migration scripts (creating models, fields, records, uploads), defer to the datocms-cma reference patterns
- The parameter in migrations is the same CMA client from
client@datocms/cma-client-node
- 迁移脚本中的CMA API调用(创建模型、字段、记录、上传资源)遵循datocms-cma的参考模式
- 迁移中的参数与
client中的CMA客户端相同@datocms/cma-client-node
Schema Generation
Schema生成
- Use to generate TypeScript schema definitions
npx datocms schema:generate <filename> - Use to narrow the output when the user only needs specific models
--item-types - Use when the generated types must reflect a sandbox or staging environment
--environment - Route the follow-up code changes that consume those types to
datocms-cma
- 使用生成TypeScript Schema定义
npx datocms schema:generate <filename> - 当用户仅需要特定模型时,使用缩小输出范围
--item-types - 当生成的类型必须反映沙箱或 staging 环境时,使用
--environment - 将使用这些类型的后续代码修改任务路由到
datocms-cma
Direct CMA Calls
直接CMA调用
- Use to look up endpoint details (request body, parameters, examples) before constructing a command
npx datocms cma:docs <resource> <action> - Use for single-method ad-hoc CMA operations
npx datocms cma:call <resource> <method> [...pathArgs] - Pass request bodies with and query parameters with
--data '{...}'--params '{...}' - Add when the call must target a sandbox environment
--environment - is positional (
cma:call+ URL placeholders as extra positional args). It is not a REST wrapper: there is no<RESOURCE> <METHOD>,--endpoint,--method, or--query-paramsflag — do not invent these--body
Concrete shape, with JSON5 accepted in / :
--data--paramsbash
npx datocms cma:call items list --params='{filter: {type: "article"}}'
npx datocms cma:call items find <ITEM_ID>
npx datocms cma:call items update <ITEM_ID> --data='{title: "Updated"}'
npx datocms cma:call items publish <ITEM_ID>
npx datocms cma:call fields create <ITEM_TYPE_ID> --data='{label: "Title", api_key: "title", field_type: "string"}'Run for the full list of built-in examples, or for body schema and required fields.
npx datocms cma:call --helpnpx datocms cma:docs <resource> <action>- Use when the task needs loops, branching, multiple dependent calls, or typed
npx datocms cma:scriptrecords, but the code does not need to live in the repoSchema.* - stdin-mode (heredoc / pipe / redirect): top-level await only, ambient and
client,Schematype-checks before execution, pre-installed packages available. Zero setuptsc --noEmit - file-mode (file on disk):
.ts- Signature: with
export default async function (client: Client)imported fromClient— same import as migrations, so a file-mode script can be promoted with a plaindatocms/lib/cma-client-nodeintomv.migrations/ - Validation: no CLI-side typecheck; rely on your editor LSP against your , or an explicit
tsconfig.json. Typedtsc --noEmitis opt-in viaSchema.*.datocms schema:generate ./datocms-schema.ts - Placement: gitignored scratch dir (,
tmp/scripts/). Prefer a migration for anything you want to commit, version, and replay across environments.scratch/
- Signature:
- Redirect when piping stdin-mode stdout into
2>/dev/nulljq - Switch to datocms-cma when the task needs reusable code checked into the repo for unattended runtime (CI, app server, webhook, long-lived automation)
- Schema changes: default to scaffolding a migration. Only propose or
cma:callfor schema mutations after the user has explicitly opted out of the migration workflow, and never propose a direct schema mutation against a primary-like environment without an explicit confirmation from the usercma:script
- 在构造命令前,使用查看端点详情(请求体、参数、示例)
npx datocms cma:docs <resource> <action> - 使用执行单次临时CMA操作
npx datocms cma:call <resource> <method> [...pathArgs] - 使用传递请求体,使用
--data '{...}'传递查询参数--params '{...}' - 当调用必须针对沙箱环境时,添加
--environment - 是位置参数式(
cma:call+ URL占位符作为额外位置参数)。它不是REST包装器:没有<RESOURCE> <METHOD>、--endpoint、--method或--query-params参数 —— 请勿自行添加这些参数--body
具体格式, / 中支持JSON5:
--data--paramsbash
npx datocms cma:call items list --params='{filter: {type: "article"}}'
npx datocms cma:call items find <ITEM_ID>
npx datocms cma:call items update <ITEM_ID> --data='{title: "Updated"}'
npx datocms cma:call items publish <ITEM_ID>
npx datocms cma:call fields create <ITEM_TYPE_ID> --data='{label: "Title", api_key: "title", field_type: "string"}'执行查看完整内置示例,或执行查看请求体 Schema 和必填字段。
npx datocms cma:call --helpnpx datocms cma:docs <resource> <action>- 当任务需要循环、分支、多个依赖调用或带类型记录,但代码无需存入仓库时,使用
Schema.*npx datocms cma:script - 标准输入模式(heredoc / 管道 / 重定向):仅支持顶层await,提供环境和
client,执行前会通过Schema进行类型检查,可使用预安装包。无需任何设置tsc --noEmit - 文件模式(磁盘上的文件):
.ts- 签名:,
export default async function (client: Client)从Client导入 —— 与迁移的导入语句相同,因此文件模式脚本可通过简单的datocms/lib/cma-client-node命令移入mv目录。migrations/ - 验证:CLI端不进行类型检查;依赖编辑器LSP结合,或显式执行
tsconfig.json。带类型的tsc --noEmit需通过Schema.*手动启用。datocms schema:generate ./datocms-schema.ts - 存放位置:Git忽略的临时目录(、
tmp/scripts/)。对于需要提交、版本控制并在多个环境中重放的操作,优先使用迁移。scratch/ - 当将标准输入模式的标准输出通过管道传入时,添加
jq2>/dev/null - 当任务需要存入仓库的可复用代码用于无人值守运行(CI、应用服务器、Webhook、长期自动化)时,切换到datocms-cma
- Schema变更:默认搭建迁移。仅当用户明确选择不使用迁移工作流时,才建议使用或
cma:call执行Schema变更;且在未获得用户明确确认的情况下,切勿建议针对类主环境执行直接Schema变更cma:script
- 签名:
CLI Plugin Commands
CLI插件命令
- Use to discover official CLI plugins before installing
npx datocms plugins:available - Use to install a CLI plugin by npm package name or GitHub URL
npx datocms plugins:add <PLUGIN> - Use only for local plugin development
npx datocms plugins:link <PATH> - These commands manage CLI extensions, not DatoCMS project plugins — route project plugin work to datocms-plugin-builder
- 在安装前,使用发现官方CLI插件
npx datocms plugins:available - 使用通过npm包名或GitHub URL安装CLI插件
npx datocms plugins:add <PLUGIN> - 仅在本地插件开发时使用
npx datocms plugins:link <PATH> - 这些命令用于管理CLI扩展,而非DatoCMS项目插件——项目插件相关工作请路由到datocms-plugin-builder
Environment Safety
环境安全
- Always specify when running migrations to be explicit about the target
--source - Use first to preview changes before applying
--dry-run - Prefer fork-and-run (default) over for production environments
--in-place - Treat as an explicit override, not a default
--force
- 运行迁移时始终指定,明确目标环境
--source - 先使用预览变更,再实际应用
--dry-run - 对于生产环境,优先选择分支运行(默认方式)而非
--in-place - 将视为显式覆盖参数,而非默认参数
--force
Step 5: Verify
步骤5:验证
Before presenting the final commands or scripts:
- API token — Confirm a CMA-enabled token is available (via env var or flag)
--api-token - Config file — If using profiles, verify exists and has the right profile
datocms.config.json - Migrations directory — Confirm the migrations directory exists or will be created by the command
- TypeScript config — If generating TS migrations, ensure exists or
tsconfig.jsonis set--migrations-tsconfig - Schema generation scope — If using , verify the output file path plus any
schema:generate/--item-typesscope match the request--environment - Direct CMA calls — If using , verify positional args,
cma:call,--data, and--paramsalign with the targeted method. If using--environment, verify the script usescma:scripttypes (notSchema.*/any), imports only from the pre-installed package list, and targets the intended environmentunknown - Environment targeting — Verify the correct /
--sourceenvironment is specified--destination - Safety checks — For destructive operations (promote, destroy, destructive usage, risky imports, maintenance-mode force), confirm the user intends to target the right environment. For schema mutations, confirm the chosen approach (migration vs direct) and — if direct — the target environment (sandbox vs primary) before issuing commands
cma:call - CLI plugin commands — If using commands, verify the plugin name is correct and distinguish CLI plugins from DatoCMS project plugins
plugins:*
在展示最终命令或脚本前:
- API令牌 —— 确认支持CMA的令牌可用(通过环境变量或参数)
--api-token - 配置文件 —— 如果使用配置文件,验证存在且包含正确的配置文件
datocms.config.json - 迁移目录 —— 确认迁移目录存在,或命令会自动创建该目录
- TypeScript配置 —— 如果生成TS迁移,确保存在或已设置
tsconfig.json--migrations-tsconfig - Schema生成范围 —— 如果使用,验证输出文件路径以及
schema:generate/--item-types范围符合请求--environment - 直接CMA调用 —— 如果使用,验证位置参数、
cma:call、--data和--params与目标方法一致。如果使用--environment,验证脚本使用cma:script类型(而非Schema.*/any),仅从预安装包列表导入,且针对预期环境unknown - 环境目标 —— 验证指定的/
--source环境正确--destination - 安全检查 —— 对于破坏性操作(升级、销毁、危险的使用、高风险导入、强制启用维护模式),确认用户意图针对正确的环境。对于Schema变更,确认选择的操作方式(迁移 vs 直接变更);如果是直接变更,在发布命令前确认目标环境(沙箱 vs 主环境)
cma:call - CLI插件命令 —— 如果使用命令,验证插件名称正确,并区分CLI插件与DatoCMS项目插件
plugins:*
Cross-Skill Routing
跨技能路由
This skill covers CLI commands, flags, configuration, workflows, and migration file scaffolding. If the task involves any of the following, activate the companion skill:
| Condition | Route to |
|---|---|
| CMA API calls inside migration script bodies (records, schema, uploads) | datocms-cma |
Programmatic environment management via | datocms-cma |
| Consuming generated schema types inside application code or reusable scripts | datocms-cma |
| Querying content with GraphQL for frontend display | datocms-cda |
| Setting up framework integration, draft mode, or real-time updates | datocms-frontend-integrations |
| Building a DatoCMS plugin | datocms-plugin-builder |
本技能涵盖CLI命令、参数、配置、工作流以及迁移文件搭建。如果任务涉及以下任何内容,请激活配套技能:
| 条件 | 路由到 |
|---|---|
| 迁移脚本主体中的CMA API调用(记录、Schema、上传资源) | datocms-cma |
通过代码中的 | datocms-cma |
| 在应用代码或可复用脚本中使用生成的Schema类型 | datocms-cma |
| 使用GraphQL查询内容用于前端展示 | datocms-cda |
| 设置框架集成、草稿模式或实时更新 | datocms-frontend-integrations |
| 构建DatoCMS插件 | datocms-plugin-builder |