@cnbcool/cnb-api-generate 2.7.0 → 2.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/built/skills-tools/resolve-quick-commands.js +35 -6
- package/built/skills.js +1 -1
- package/client/core.ts +1 -1
- package/client/shortcuts.ts +1 -1
- package/package.json +2 -1
- package/quick-commands.json +33 -0
|
@@ -5,10 +5,39 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveQuickCommands = resolveQuickCommands;
|
|
7
7
|
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
const
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const logger = (0, debug_1.default)('csg:quick-commands');
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* 内置快捷命令配置文件路径——位于包根的 `quick-commands.json`,随 npm 包发布。
|
|
13
|
+
*
|
|
14
|
+
* 路径推导:
|
|
15
|
+
* - 源码态:`src/skills-tools/resolve-quick-commands.ts` → `../../quick-commands.json`
|
|
16
|
+
* - 编译后:`built/skills-tools/resolve-quick-commands.js` → `../../quick-commands.json`
|
|
17
|
+
* 两态都正确指向包根。
|
|
18
|
+
*/
|
|
19
|
+
const QUICK_COMMANDS_JSON_PATH = path_1.default.join(__dirname, '../../quick-commands.json');
|
|
20
|
+
/**
|
|
21
|
+
* 加载内置快捷命令清单。该文件由本仓库维护、随 npm 包发布,
|
|
22
|
+
* 使用方无需在 cag.config.js 中重复声明。
|
|
23
|
+
*
|
|
24
|
+
* 文件不存在时返回空对象(不阻断构建,仅相当于未配置任何快捷命令)。
|
|
25
|
+
*/
|
|
26
|
+
function loadQuickCommandsJson() {
|
|
27
|
+
if (!fs_1.default.existsSync(QUICK_COMMANDS_JSON_PATH)) {
|
|
28
|
+
logger(`quick-commands.json not found at ${QUICK_COMMANDS_JSON_PATH}`);
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
const raw = fs_1.default.readFileSync(QUICK_COMMANDS_JSON_PATH, 'utf8');
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(raw);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new Error(`[quickCommands] 解析 ${QUICK_COMMANDS_JSON_PATH} 失败:${e.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 把内置 quick-commands.json + helpData 元数据,
|
|
12
41
|
* 解析为下游(client 产物 / SKILL.md 渲染)共用的结构化数据。
|
|
13
42
|
*
|
|
14
43
|
* 关键校验:
|
|
@@ -18,8 +47,8 @@ const logger = (0, debug_1.default)('csg:quick-commands');
|
|
|
18
47
|
* 不强制要求 module 名等于 swagger category)。
|
|
19
48
|
*/
|
|
20
49
|
function resolveQuickCommands(helpData) {
|
|
21
|
-
const
|
|
22
|
-
if (!quickCommands)
|
|
50
|
+
const quickCommands = loadQuickCommandsJson();
|
|
51
|
+
if (!quickCommands || !Object.keys(quickCommands).length)
|
|
23
52
|
return {};
|
|
24
53
|
const { modulesHelp } = helpData;
|
|
25
54
|
// 建一个 realTool → true 的全局集合,便于 O(1) 校验
|
|
@@ -32,7 +61,7 @@ function resolveQuickCommands(helpData) {
|
|
|
32
61
|
const result = {};
|
|
33
62
|
for (const [moduleName, items] of Object.entries(quickCommands)) {
|
|
34
63
|
if (!Array.isArray(items)) {
|
|
35
|
-
throw new Error(`[quickCommands] 模块 "${moduleName}" 的值必须是数组,请检查
|
|
64
|
+
throw new Error(`[quickCommands] 模块 "${moduleName}" 的值必须是数组,请检查 quick-commands.json。`);
|
|
36
65
|
}
|
|
37
66
|
const resolved = [];
|
|
38
67
|
for (const item of items) {
|
|
@@ -43,7 +72,7 @@ function resolveQuickCommands(helpData) {
|
|
|
43
72
|
// custom 命令跳过 swagger 校验
|
|
44
73
|
if (!item.custom && !allTools.has(item.realTool)) {
|
|
45
74
|
throw new Error(`[quickCommands] 命令 "${moduleName} ${item.shortName}" 的 realTool="${item.realTool}" ` +
|
|
46
|
-
`在 swagger 生成结果中不存在。请检查
|
|
75
|
+
`在 swagger 生成结果中不存在。请检查 quick-commands.json 是否与最新 swagger 同步,` +
|
|
47
76
|
`或对自定义命令显式标记 custom: true。`);
|
|
48
77
|
}
|
|
49
78
|
resolved.push({ ...item, module: moduleName });
|
package/built/skills.js
CHANGED
|
@@ -33,7 +33,7 @@ async function start() {
|
|
|
33
33
|
const helpData = (0, generate_skill_cli_help_1.generateSkillCliHelp)(requestMap, defintionsMap);
|
|
34
34
|
// 编译core
|
|
35
35
|
await (0, printer_skills_client_core_1.printerSkillsClientCore)(helpData);
|
|
36
|
-
// 解析快捷命令配置(
|
|
36
|
+
// 解析快捷命令配置(quick-commands.json → 校验 → 结构化),同时驱动 client 运行时数据与 SKILL.md 文档
|
|
37
37
|
const quickCommandsByModule = (0, resolve_quick_commands_1.resolveQuickCommands)(helpData);
|
|
38
38
|
// 写入 client 运行时配置(core/shortcuts.config.json),替代 client/shortcuts.ts 中的硬编码常量
|
|
39
39
|
await (0, generate_shortcuts_config_1.generateShortcutsConfig)(quickCommandsByModule);
|
package/client/core.ts
CHANGED
|
@@ -136,7 +136,7 @@ async function clientFetch(data: any): Promise<any> {
|
|
|
136
136
|
Authorization: `Bearer ${token}`,
|
|
137
137
|
Accept: 'application/vnd.cnb.api+json',
|
|
138
138
|
// 当请求体存在时,附加 Content-Type,避免后端无法识别 JSON body
|
|
139
|
-
...(data.data ? { 'Content-Type': 'application/
|
|
139
|
+
...(data.data ? { 'Content-Type': 'application/json' } : {}),
|
|
140
140
|
...(data?.header || {}),
|
|
141
141
|
},
|
|
142
142
|
});
|
package/client/shortcuts.ts
CHANGED
|
@@ -77,7 +77,7 @@ function getPRNumber(): string {
|
|
|
77
77
|
// 快捷命令定义
|
|
78
78
|
// ============================================================
|
|
79
79
|
//
|
|
80
|
-
// 数据由 csg
|
|
80
|
+
// 数据由 csg 构建期从仓库内置的 quick-commands.json(随 npm 包发布)派生,
|
|
81
81
|
// 写入同级目录下的 shortcuts.config.json。本文件仅负责加载并暴露给
|
|
82
82
|
// 其它模块(register-modules.ts / execute-action.ts / utils/upload.ts)。
|
|
83
83
|
//
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cnbcool/cnb-api-generate",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.1",
|
|
4
4
|
"main": "./built/index.js",
|
|
5
5
|
"module": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"package.json",
|
|
73
73
|
"skills-template",
|
|
74
74
|
"client",
|
|
75
|
+
"quick-commands.json",
|
|
75
76
|
"README.md"
|
|
76
77
|
]
|
|
77
78
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"issues": [
|
|
3
|
+
{ "shortName": "get", "realTool": "get-issue", "description": "获取详情" },
|
|
4
|
+
{ "shortName": "list-comments", "realTool": "list-issue-comments", "description": "获取评论列表" },
|
|
5
|
+
{ "shortName": "comment", "realTool": "post-issue-comment", "description": "评论", "dataTip": "--body 内容" },
|
|
6
|
+
{ "shortName": "close", "realTool": "update-issue", "description": "关闭", "autoData": { "state": "closed", "state_reason": "completed" } },
|
|
7
|
+
{ "shortName": "open", "realTool": "update-issue", "description": "打开", "autoData": { "state": "open", "state_reason": "reopened" } },
|
|
8
|
+
{ "shortName": "list-labels", "realTool": "list-issue-labels", "description": "查看标签" },
|
|
9
|
+
{ "shortName": "add-labels", "realTool": "post-issue-labels", "description": "添加标签", "dataTip": "--labels bug --labels feature" },
|
|
10
|
+
{ "shortName": "list-assignees", "realTool": "list-issue-assignees", "description": "查看处理人" },
|
|
11
|
+
{ "shortName": "add-assignees", "realTool": "post-issue-assignees", "description": "添加处理人", "dataTip": "--assignees username" },
|
|
12
|
+
{ "shortName": "upload-file", "realTool": "post-issue-comment-file-asset-upload-url", "description": "上传 issue 评论文件", "upload": true, "kind": "file", "dataTip": "--file 文件路径" },
|
|
13
|
+
{ "shortName": "upload-image", "realTool": "post-issue-comment-image-asset-upload-url","description": "上传 issue 评论图片", "upload": true, "kind": "image", "dataTip": "--file 图片路径" },
|
|
14
|
+
{ "shortName": "create-upload-file", "realTool": "post-asset-group", "description": "创建 issue 时上传文件", "upload": true, "kind": "file", "dataTip": "--file 文件路径" },
|
|
15
|
+
{ "shortName": "create-upload-image", "realTool": "post-asset-group", "description": "创建 issue 时上传图片", "upload": true, "kind": "image", "dataTip": "--file 图片路径" }
|
|
16
|
+
],
|
|
17
|
+
"pulls": [
|
|
18
|
+
{ "shortName": "get", "realTool": "get-pull", "description": "获取详情" },
|
|
19
|
+
{ "shortName": "list-files", "realTool": "list-pull-files", "description": "获取文件变更" },
|
|
20
|
+
{ "shortName": "list-commits", "realTool": "list-pull-commits", "description": "获取提交记录" },
|
|
21
|
+
{ "shortName": "list-comments", "realTool": "list-pull-comments", "description": "获取评论列表" },
|
|
22
|
+
{ "shortName": "comment", "realTool": "post-pull-comment", "description": "评论", "dataTip": "--body 内容" },
|
|
23
|
+
{ "shortName": "list-labels", "realTool": "list-pull-labels", "description": "查看标签" },
|
|
24
|
+
{ "shortName": "add-labels", "realTool": "post-pull-labels", "description": "添加标签", "dataTip": "--labels ready --labels approved" },
|
|
25
|
+
{ "shortName": "check-status", "realTool": "list-pull-commit-statuses", "description": "查看 CI 状态" },
|
|
26
|
+
{ "shortName": "list-reviews", "realTool": "list-pull-reviews", "description": "查看评审列表" },
|
|
27
|
+
{ "shortName": "list-assignees", "realTool": "list-pull-assignees", "description": "查看处理人" },
|
|
28
|
+
{ "shortName": "upload-file", "realTool": "upload-files", "description": "上传文件", "repoOnly": true, "upload": true, "dataTip": "--file 文件路径" },
|
|
29
|
+
{ "shortName": "upload-image", "realTool": "upload-imgs", "description": "上传图片", "repoOnly": true, "upload": true, "dataTip": "--file 图片路径" },
|
|
30
|
+
{ "shortName": "get-ci-logs", "realTool": "__get-ci-logs__", "description": "获取 CI 失败日志", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" },
|
|
31
|
+
{ "shortName": "get-ci-timing", "realTool": "__get-ci-timing__", "description": "分析 CI 耗时瓶颈", "repoOnly": true, "custom": true, "dataTip": "--sn 构建号(可选)" }
|
|
32
|
+
]
|
|
33
|
+
}
|