Strapi CLI
$ strapi 官方出品 中风险Strapi CLI(strapi,内置于 @strapi/strapi)负责编排本地 Strapi 开发服务(develop)、生产管理后台构建(build)、TypeScript 类型生成(ts:generate-types)及数据导出/导入/传输,定位为项目内 Node.js 工程命令而非无状态 API 查询工具。
npm install @strapi/strapi strapi 负责编译本地 React 管理后台、监听本地内容模型并生成 ./types/ TypeScript 定义,属于本地工程任务。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
绑定本地项目的工程型 CLI,缺少全局 --json 输出,且 generate 等命令依赖交互式问答。
- No global
--jsonoutput mode acrossstrapisubcommands strapi generaterelies on interactive Inquirer prompts
诊断与构建命令仅影响本地,import/transfer 覆写数据库时需显式 --force 或令牌确认。
- Local schema typegen and
routes:listdo not mutate remote state
随 @strapi/strapi 通过 npm/npx 在 macOS、Linux 与 Windows 运行,但需在完整项目中执行。
- Runs via
npx strapiinside@strapi/strapiprojects
承担后台构建、ts:generate-types、路由排查与加密数据导出/迁移的核心职责。
- Covers
develop,build,ts:generate-types, andexport/transfer
Strapi 官方仓库(strapi/strapi),社区版 MIT 开源,企业特性位于 ee/ 商业授权目录。
- Official Strapi repository
docs.strapi.io/cms/cli 文档完整,但 v4 与 v5 之间部分命令参数存在差异。
- Official docs at
docs.strapi.io/cms/cli
安全边界、鉴权与放权指南
从项目 .env 与 config/ 目录读取数据库及应用密钥;strapi transfer 使用 --to-token / --from-token 传入或交互输入传输令牌。
社区版采用 MIT 开源协议免费;Enterprise 企业版功能与 Strapi Cloud 为商业授权。
# Strapi CLI (strapi) Agent Rules - Run `npx strapi` inside a valid Strapi project root; avoid long-running `strapi develop` without a background task. - Never run `strapi import` or `strapi transfer` against a production database without explicit backup confirmation. - Pass explicit flags to `strapi admin:create-user` or `strapi export` to avoid interactive prompts.
Agent 高频安全命令配方
只读查询(安全推荐)
npx strapi routes:list
输出本地 Strapi 项目中所有内容模型与插件注册的 REST 路由列表。
npx strapi ts:generate-types --debug
将本地 Strapi 内容模型与组件的 TypeScript 接口写入 types/ 目录。
受控写入与预演
npx strapi build
将 Strapi 管理后台静态资源编译到 dist//build/ 目录,而不启动常驻服务。
核心优势
- +
ts:generate-types与routes:list能让编码 Agent 快速掌握本地 CMS 模型与接口。 - + 内置
export/import/transfer方便跨环境迁移内容数据。
注意事项与踩坑点
- ! 并非独立全局 SaaS CLI,必须在 Strapi 项目根目录下执行。
- ! 缺少全局
--json输出支持,且strapi generate与create-strapi默认偏向交互提示。