@cnbcool/cnb-api-generate 2.15.0 → 2.15.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.
@@ -9,14 +9,34 @@ import { buildToolParams } from './build-tool-params';
9
9
  import { skillsList } from './skills-list';
10
10
  // @ts-ignore
11
11
  import {getLoader} from '../../loader';
12
+
13
+ /**
14
+ * 构建“工具函数不存在”的双语报错信息。
15
+ */
16
+ function buildToolNotFoundMessage(moduleName: string, toolName: string, cnbVersion: string): string {
17
+ const lines: string[] = [];
18
+ // 中文提示
19
+ lines.push(`错误:工具函数「${moduleName}/${toolName}」不存在,请检查模块名和工具名是否正确。`);
20
+ lines.push(`可通过 \`cnb ${moduleName} --help\` 查看该模块支持的工具列表,或用 \`cnb --help\` 查看全部模块。`);
21
+ // 英文提示
22
+ lines.push(`Error: tool function "${moduleName}/${toolName}" not found. Please check the module and tool names.`);
23
+ lines.push(`Run \`cnb ${moduleName} --help\` to list tools of this module, or \`cnb --help\` for all modules.`);
24
+ // 版本信息
25
+ if (cnbVersion) {
26
+ lines.push(`cnb -v: ${cnbVersion}`);
27
+ }
28
+ return lines.join('\n');
29
+ }
30
+
12
31
  /**
13
- * 加载 tool 模块并返回其 default 导出函数
32
+ * 加载 tool 模块并返回其 default 导出函数。
33
+ * 工具函数不存在时,输出明确的双语报错(含工具名与 cnb 版本)后退出。
14
34
  */
15
- function loadToolFunction(moduleName: string, toolName: string): any {
35
+ function loadToolFunction(moduleName: string, toolName: string, parentCmd: Command): any {
16
36
  const toolFunction = getLoader(moduleName, toolName);
17
37
 
18
38
  if (!toolFunction) {
19
- console.error(`工具函数不存在`);
39
+ console.error(buildToolNotFoundMessage(moduleName, toolName, parentCmd.version()));
20
40
  process.exit(1);
21
41
  }
22
42
 
@@ -79,7 +99,7 @@ export async function executeAction(
79
99
  // 上传命令走独立分支:只需 --file + autoPath,跳过 formatParams 常规流程
80
100
  if (shortcut?.upload) {
81
101
  const isVerbose = !!opts.verbose;
82
- const toolFunction = loadToolFunction(shortcut.module, shortcut.tool);
102
+ const toolFunction = loadToolFunction(shortcut.module, shortcut.tool, parentCmd);
83
103
  const pathParams = shortcut.autoPath as UploadPathParams;
84
104
  let data: any;
85
105
 
@@ -127,7 +147,7 @@ export async function executeAction(
127
147
 
128
148
  const formattedParams = formatParams(params);
129
149
 
130
- const toolFunction = loadToolFunction(formattedParams.module, formattedParams.tool);
150
+ const toolFunction = loadToolFunction(formattedParams.module, formattedParams.tool, parentCmd);
131
151
 
132
152
  const toolsParam = buildToolParams(formattedParams);
133
153
  const data = await toolFunction(...toolsParam);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cnbcool/cnb-api-generate",
3
- "version": "2.15.0",
3
+ "version": "2.15.1",
4
4
  "main": "./built/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",