brand-cli
v0.1.24
Published
类型安全(来自自动 OpenAPI)的 brand-context 管理端 CLI
Readme
brand-cli
类型安全(来自自动 OpenAPI)的 brand-context 管理端 CLI。
仅供 brand-context 后端使用。它只连你自己的后端实例,对第三方无作用。
安装
npm install -g brand-cli或本地用 npx:
npx brand-cli --help配置(环境变量)
| 变量 | 说明 | 默认 |
| --- | --- | --- |
| BRANDCLI_BASE | 后端地址 | http://localhost:3100 |
| BRANDCLI_TOKEN | 管理端 token(Bearer) | 空 |
| ADMIN_TOKEN | 兜底读取 .env 的 ADMIN_TOKEN | 空 |
--token <t> 命令行参数可覆盖环境变量。
命令
# 读
brand-cli entities list [--category X] [--includeArchived]
brand-cli entity get <id>
brand-cli coverage [--includeArchived]
brand-cli products list [--includeArchived]
# 实体:写
brand-cli entity data get <id|key> [--locale en] # 读取某语言层 JSON(只读,key 自动解析为 id;输出为裸 JSON)
brand-cli entity create --key K [--category C] [--recordLabel R] [--source S] [--schemaHint @file.json] # key 必须 ^[a-z0-9_]+$(非法字符 400)
brand-cli entity update <id> [--category C] [--status S] [--recordLabel R] [--source S] [--schemaHint @file] [--if-match V]
brand-cli entity delete <id> # 软删(archived);自动 If-Match: *
brand-cli entity data set <id> --locale en --data @file.json | -d '{...}' | -d - # data 必须【嵌套在实体 key 下】,扁平 JSON → 400
brand-cli entity data rm <id> --locale en # 默认 If-Match: * 通配走 LWW(服务端 2026-08-19 起接受)
brand-cli entity recompute <id>
brand-cli entity rename-field <id> --from F --to T
# 产物:写 + 发布生命周期
brand-cli product create --slug S [--name N] [--sourceDir D] [--defaultLocales en,cn]
brand-cli product update <id> [--name N] [--description D] [--defaultLocales en,cn] [--status S] [--if-match V]
brand-cli product delete <id>
brand-cli product publish <id> [--locales en,cn]
brand-cli product unpublish <id>
brand-cli product add-item <id> --entity <entityId>
brand-cli product rm-item <id> <itemId>
brand-cli product reorder <id> --order id1,id2,id3
# 分类
brand-cli category create --key K [--label L] [--color #hex] [--order N]
brand-cli category update <key> [--label L] [--color #hex] [--order N]
brand-cli category delete <key>
brand-cli --help写操作默认自动带 If-Match 乐观锁(last-write-wins);CLI 发 If-Match: * 通配 + x-vercel-bypass: 1 绕过 Vercel CDN ETag 412;--if-match <v> 可显式覆盖。
本地开发(在 brand-context 主仓库内)
主仓库用 npm run cli -- <cmd>(tsx 直跑);本目录是独立可发布的打包产物,发布前:
cd brand-cli
npm install # 装 esbuild(devDependency)
npm run build # 编译 src/cli.ts -> dist/cli.js
npm publish # 公开发包响应类型来自主仓库 src/api-types.d.ts(由 npm run gen:types 重新生成)。src/cli.ts 以 import type 引用,构建时被 esbuild 擦除,故 dist/cli.js 是自带运行时的自包含产物,无需把类型文件复制到此目录。
