@cnbcool/cnb-cli 1.2.2 → 1.2.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-cli",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "CNB OpenAPI 命令行工具,基于 CNB 平台 Swagger 自动生成,支持 Issues、PR、Git、组织管理等全部 API 操作",
5
5
  "main": "skills/cnb-api/scripts/core/index.js",
6
6
  "bin": {
@@ -34,9 +34,7 @@
34
34
  "author": "",
35
35
  "license": "MIT",
36
36
  "devDependencies": {
37
+ "@cnbcool/cnb-api-generate": "^2.2.1",
37
38
  "skills": "^1.4.4"
38
- },
39
- "dependencies": {
40
- "@cnbcool/cnb-api-generate": "^2.2.0"
41
39
  }
42
40
  }
@@ -11,6 +11,32 @@ var _upload = require("../utils/upload");
11
11
  var _formatParams = require("./format-params");
12
12
  var _formatOutput = require("./format-output");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ /**
15
+ * 加载 tool 模块并返回其 default 导出函数
16
+ */
17
+ function loadToolFunction(moduleName, toolName) {
18
+ const toolPath = _path.default.join(__dirname, '../../modules', `${moduleName}/${toolName}.js`);
19
+ if (!_fs.default.existsSync(toolPath)) {
20
+ console.error(`工具文件不存在: ${toolPath}`);
21
+ process.exit(1);
22
+ }
23
+ const toolModule = require(toolPath);
24
+ const toolFunction = toolModule.default;
25
+ if (!toolFunction) {
26
+ console.error(`工具函数不存在`);
27
+ process.exit(1);
28
+ }
29
+ return toolFunction;
30
+ }
31
+
32
+ /**
33
+ * 处理上传命令的独立分支
34
+ * 上传命令只需要 --file 和自动注入的 path 参数,不经过 formatParams
35
+ */
36
+ async function executeUpload(shortcut, opts) {
37
+ const toolFunction = loadToolFunction(shortcut.module, shortcut.tool);
38
+ return (0, _upload.handleUpload)(shortcut, opts.file, toolFunction, shortcut.autoPath);
39
+ }
14
40
  async function executeAction(moduleArg, toolArg, opts, parentCmd) {
15
41
  // Commander 已解析好所有 option,直接构建 params
16
42
  const params = {};
@@ -49,18 +75,17 @@ async function executeAction(moduleArg, toolArg, opts, parentCmd) {
49
75
  if (!params.tool) {
50
76
  parentCmd.help();
51
77
  }
52
- const formattedParams = (0, _formatParams.formatParams)(params);
53
- const toolPath = _path.default.join(__dirname, '../../modules', `${formattedParams.module}/${formattedParams.tool}.js`);
54
- if (!_fs.default.existsSync(toolPath)) {
55
- console.error(`工具文件不存在: ${toolPath}`);
56
- process.exit(1);
57
- }
58
- const toolModule = require(toolPath);
59
- const toolFunction = toolModule.default;
60
- if (!toolFunction) {
61
- console.error(`工具函数不存在`);
62
- process.exit(1);
78
+
79
+ // 上传命令走独立分支:只需 --file + autoPath,跳过 formatParams 常规流程
80
+ if (shortcut?.upload) {
81
+ const data = await executeUpload(shortcut, opts);
82
+ const toolKey = `${shortcut.module}/${shortcut.tool}`;
83
+ const isVerbose = !!opts.verbose;
84
+ console.log((0, _formatOutput.formatOutput)(data, isVerbose, !isVerbose, toolKey));
85
+ return;
63
86
  }
87
+ const formattedParams = (0, _formatParams.formatParams)(params);
88
+ const toolFunction = loadToolFunction(formattedParams.module, formattedParams.tool);
64
89
  const toolsParam = [];
65
90
  let pathAndQueryParams = null;
66
91
  if (formattedParams.path && Object.keys(formattedParams.path).length === 1 && !formattedParams.query) {
@@ -81,15 +106,10 @@ async function executeAction(moduleArg, toolArg, opts, parentCmd) {
81
106
  if (pathAndQueryParams) {
82
107
  toolsParam.push(pathAndQueryParams);
83
108
  }
84
- let data;
85
- if (shortcut?.upload) {
86
- data = await (0, _upload.handleUpload)(shortcut, formattedParams.data?.file, toolFunction, pathAndQueryParams);
87
- } else {
88
- if (formattedParams.data) {
89
- toolsParam.push(formattedParams.data);
90
- }
91
- data = await toolFunction(...toolsParam);
109
+ if (formattedParams.data) {
110
+ toolsParam.push(formattedParams.data);
92
111
  }
112
+ const data = await toolFunction(...toolsParam);
93
113
  const toolKey = `${formattedParams.module}/${formattedParams.tool}`;
94
114
  const isVerbose = !!formattedParams.verbose;
95
115
  const isSummary = shortcut ? !isVerbose : false;
@@ -95,8 +95,12 @@ function registerModuleCommands(program) {
95
95
  await (0, _executeAction.executeAction)(moduleName, shortcut.shortName, opts, sub);
96
96
  });
97
97
 
98
- // 复用真实 tool 的选项,跳过 path 参数
99
- registerToolOptions(shortcutCmd, moduleName, shortcut.realTool, true);
98
+ // 上传命令只需要 --file,不复用真实 tool body 选项(name/size/content_type 由上传流程自动获取)
99
+ if (!shortcut.upload) {
100
+ registerToolOptions(shortcutCmd, moduleName, shortcut.realTool, true);
101
+ } else {
102
+ shortcutCmd.requiredOption('--file <string>', '本地文件路径。必填。');
103
+ }
100
104
  registeredNames.add(shortcut.shortName);
101
105
  }
102
106
 
@@ -170,7 +170,11 @@ async function handleUpload(shortcut, filePath, toolFunction, pathParams) {
170
170
  name: fileName,
171
171
  size: fileSize
172
172
  };
173
- const uploadResponse = await toolFunction(pathParams, requestBody);
173
+
174
+ // Issue API 签名: fn({ repo, number }, body)
175
+ // PR API 签名: fn(repo, body)
176
+ const apiFirstArg = isIssueUpload ? pathParams : pathParams.repo;
177
+ const uploadResponse = await toolFunction(apiFirstArg, requestBody);
174
178
 
175
179
  // 提取 upload_url
176
180
  const responseData = uploadResponse?.data;