@cloudbase/cli 2.9.9 → 2.9.10-beta.0

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.
Files changed (164) hide show
  1. package/bin/cloudbase.js +2 -1
  2. package/bin/tcb.js +35 -28
  3. package/lib/auth/login.js +21 -13
  4. package/lib/commands/account/login.js +43 -42
  5. package/lib/commands/account/logout.js +3 -2
  6. package/lib/commands/ai/index.js +13 -12
  7. package/lib/commands/cloudfunction/base.js +24 -26
  8. package/lib/commands/cloudrun/base.js +87 -96
  9. package/lib/commands/common.js +11 -10
  10. package/lib/commands/config/delete.js +72 -0
  11. package/lib/commands/config/get.js +69 -0
  12. package/lib/commands/config/index.js +21 -0
  13. package/lib/commands/config/interface.js +24 -0
  14. package/lib/commands/config/list.js +72 -0
  15. package/lib/commands/config/set.js +89 -0
  16. package/lib/commands/db/base.js +33 -32
  17. package/lib/commands/env/base.js +12 -11
  18. package/lib/commands/env/domain.js +24 -23
  19. package/lib/commands/env/login.js +31 -30
  20. package/lib/commands/fun/base.js +37 -36
  21. package/lib/commands/functions/alias/getRoute.js +5 -4
  22. package/lib/commands/functions/alias/setRoute.js +7 -6
  23. package/lib/commands/functions/code-download.js +15 -11
  24. package/lib/commands/functions/code-update.js +8 -7
  25. package/lib/commands/functions/concurrency/delete.js +5 -4
  26. package/lib/commands/functions/concurrency/list.js +6 -5
  27. package/lib/commands/functions/concurrency/set.js +5 -4
  28. package/lib/commands/functions/config-update.js +8 -7
  29. package/lib/commands/functions/copy.js +7 -6
  30. package/lib/commands/functions/delete.js +8 -7
  31. package/lib/commands/functions/deploy.js +35 -34
  32. package/lib/commands/functions/detail.js +32 -31
  33. package/lib/commands/functions/invoke.js +16 -15
  34. package/lib/commands/functions/layer/bind.js +26 -25
  35. package/lib/commands/functions/layer/common.js +2 -1
  36. package/lib/commands/functions/layer/create.js +7 -6
  37. package/lib/commands/functions/layer/delete.js +9 -8
  38. package/lib/commands/functions/layer/download.js +10 -9
  39. package/lib/commands/functions/layer/list.js +10 -9
  40. package/lib/commands/functions/layer/sort.js +9 -8
  41. package/lib/commands/functions/list.js +9 -8
  42. package/lib/commands/functions/log.js +28 -27
  43. package/lib/commands/functions/run.js +21 -20
  44. package/lib/commands/functions/trigger-create.js +9 -8
  45. package/lib/commands/functions/trigger-delete.js +10 -9
  46. package/lib/commands/functions/version/list.js +9 -8
  47. package/lib/commands/functions/version/publish.js +5 -4
  48. package/lib/commands/gateway/create.js +14 -13
  49. package/lib/commands/gateway/delete.js +10 -9
  50. package/lib/commands/gateway/domain.js +25 -24
  51. package/lib/commands/gateway/list.js +11 -10
  52. package/lib/commands/gateway/switch.js +22 -19
  53. package/lib/commands/helpers/init.js +38 -37
  54. package/lib/commands/helpers/new.js +7 -6
  55. package/lib/commands/helpers/open.js +7 -6
  56. package/lib/commands/hosting/hosting.js +45 -44
  57. package/lib/commands/index.js +1 -0
  58. package/lib/commands/pull/pull.js +12 -11
  59. package/lib/commands/run/delete.js +16 -15
  60. package/lib/commands/run/image/common.js +2 -1
  61. package/lib/commands/run/image/delete.js +10 -9
  62. package/lib/commands/run/image/download.js +8 -7
  63. package/lib/commands/run/image/list.js +11 -10
  64. package/lib/commands/run/image/upload.js +9 -8
  65. package/lib/commands/run/list.js +10 -9
  66. package/lib/commands/run/service/config.js +13 -12
  67. package/lib/commands/run/service/deploy.js +24 -23
  68. package/lib/commands/run/service/list.js +10 -9
  69. package/lib/commands/run/service/update.js +22 -21
  70. package/lib/commands/run/standalonegateway/common.js +2 -1
  71. package/lib/commands/run/standalonegateway/create.js +14 -13
  72. package/lib/commands/run/standalonegateway/destroy.js +9 -8
  73. package/lib/commands/run/standalonegateway/list.js +7 -6
  74. package/lib/commands/run/standalonegateway/package.js +7 -6
  75. package/lib/commands/run/standalonegateway/turn.js +10 -9
  76. package/lib/commands/run/version/common.js +2 -1
  77. package/lib/commands/run/version/create.js +41 -40
  78. package/lib/commands/run/version/delete.js +10 -9
  79. package/lib/commands/run/version/list.js +13 -12
  80. package/lib/commands/run/version/modify.js +13 -12
  81. package/lib/commands/run/version/update.js +57 -54
  82. package/lib/commands/runf/base.js +42 -40
  83. package/lib/commands/self-update.js +11 -10
  84. package/lib/commands/smart.js +5 -4
  85. package/lib/commands/storage/storage.js +61 -56
  86. package/lib/commands/third/thirdAttach.js +6 -5
  87. package/lib/commands/utils.js +8 -5
  88. package/lib/constant.js +18 -17
  89. package/lib/decorators/deprecate.js +2 -1
  90. package/lib/function/alias.js +3 -2
  91. package/lib/function/base.js +9 -8
  92. package/lib/function/concurrency.js +4 -3
  93. package/lib/function/create.js +5 -4
  94. package/lib/function/delete.js +2 -1
  95. package/lib/function/layer/attach.js +2 -1
  96. package/lib/function/layer/create.js +2 -1
  97. package/lib/function/layer/download.js +2 -1
  98. package/lib/function/trigger.js +6 -5
  99. package/lib/function/update.js +3 -2
  100. package/lib/function/version.js +3 -2
  101. package/lib/help.js +22 -20
  102. package/lib/hosting.js +18 -17
  103. package/lib/i18n/index.js +81 -0
  104. package/lib/run/service/common.js +14 -13
  105. package/lib/run/service/config.js +4 -3
  106. package/lib/run/service/deployPackage.js +6 -5
  107. package/lib/run/service/showLogs.js +3 -2
  108. package/lib/run/service/update.js +7 -6
  109. package/lib/run/standalonegateway/list.js +5 -1
  110. package/lib/storage.js +2 -1
  111. package/lib/utils/ai/banner.js +12 -11
  112. package/lib/utils/ai/claudeWindows.js +5 -3
  113. package/lib/utils/ai/config.js +3 -2
  114. package/lib/utils/ai/const.js +4 -3
  115. package/lib/utils/ai/env.js +3 -2
  116. package/lib/utils/ai/envLocalManager.js +6 -5
  117. package/lib/utils/ai/nodeVersion.js +5 -1
  118. package/lib/utils/ai/router.js +129 -106
  119. package/lib/utils/ai/setup.js +95 -91
  120. package/lib/utils/checkTcbrEnv.js +22 -21
  121. package/lib/utils/cli-table.js +2 -1
  122. package/lib/utils/commonParamsCheck.js +4 -3
  123. package/lib/utils/debug-logger.js +2 -1
  124. package/lib/utils/dts.js +4 -3
  125. package/lib/utils/env.js +23 -21
  126. package/lib/utils/fs/index.js +5 -4
  127. package/lib/utils/function-packer.js +3 -2
  128. package/lib/utils/index.js +1 -0
  129. package/lib/utils/mcp-config-modifier.js +18 -17
  130. package/lib/utils/net/cloud-api-request.js +2 -1
  131. package/lib/utils/net/credential.js +2 -1
  132. package/lib/utils/net/http-request.js +2 -1
  133. package/lib/utils/progress-bar.js +2 -1
  134. package/lib/utils/prompt/select.js +8 -6
  135. package/lib/utils/store/auth.js +3 -2
  136. package/lib/utils/store/config.js +49 -0
  137. package/lib/utils/store/db.js +5 -0
  138. package/lib/utils/store/index.js +1 -1
  139. package/lib/utils/tcbrApi/callTcbrApi.js +2 -1
  140. package/lib/utils/template-manager.js +37 -36
  141. package/lib/utils/template.js +10 -9
  142. package/lib/utils/tools/common.js +3 -2
  143. package/lib/utils/url.js +19 -0
  144. package/lib/utils/validator.js +12 -4
  145. package/locales/README.md +160 -0
  146. package/locales/i18next-scanner.config.js +206 -0
  147. package/locales/langs/en.json +1235 -0
  148. package/locales/langs/zh.json +1235 -0
  149. package/locales/mapping.json +1235 -0
  150. package/package.json +9 -2
  151. package/types/commands/config/delete.d.ts +13 -0
  152. package/types/commands/config/get.d.ts +13 -0
  153. package/types/commands/config/index.d.ts +5 -0
  154. package/types/commands/config/interface.d.ts +17 -0
  155. package/types/commands/config/list.d.ts +13 -0
  156. package/types/commands/config/set.d.ts +13 -0
  157. package/types/commands/index.d.ts +1 -0
  158. package/types/i18n/index.d.ts +3 -0
  159. package/types/utils/ai/const.d.ts +1 -1
  160. package/types/utils/index.d.ts +1 -0
  161. package/types/utils/store/config.d.ts +8 -0
  162. package/types/utils/store/db.d.ts +2 -0
  163. package/types/utils/store/index.d.ts +1 -1
  164. package/types/utils/url.d.ts +18 -0
@@ -19,6 +19,7 @@ const logger_1 = require("../logger");
19
19
  const error_1 = require("../error");
20
20
  const vpc_1 = require("./vpc");
21
21
  const toolbox_1 = require("@cloudbase/toolbox");
22
+ const i18n_1 = require("../i18n");
22
23
  const scfService = utils_1.CloudApiService.getInstance('scf');
23
24
  function getFunctionService(envId) {
24
25
  return __awaiter(this, void 0, void 0, function* () {
@@ -85,7 +86,7 @@ function listAllFunctions(options) {
85
86
  currentOffset += pageSize;
86
87
  }
87
88
  catch (error) {
88
- throw new error_1.CloudBaseError(`获取函数列表失败: ${error.message}`);
89
+ throw new error_1.CloudBaseError((0, i18n_1.t)('获取函数列表失败: {{error}}', { error: error.message }));
89
90
  }
90
91
  }
91
92
  const data = [];
@@ -150,7 +151,7 @@ function batchGetFunctionsDetail({ names, envId, codeSecret }) {
150
151
  data.push(info);
151
152
  }
152
153
  catch (e) {
153
- throw new error_1.CloudBaseError(`${name} 获取信息失败:${e.message}`);
154
+ throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 获取信息失败:{{error}}', { name, error: e.message }));
154
155
  }
155
156
  }))());
156
157
  yield Promise.all(promises);
@@ -193,10 +194,10 @@ function batchUpdateFunctionConfig(options) {
193
194
  config: func,
194
195
  envId
195
196
  });
196
- log && (0, logger_1.successLog)(`[${func.name}] 更新云函数配置成功!`);
197
+ log && (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 更新云函数配置成功!', { name: func.name }));
197
198
  }
198
199
  catch (e) {
199
- throw new error_1.CloudBaseError(`${func.name} 更新配置失败:${e.message}`);
200
+ throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 更新配置失败:{{error}}', { name: func.name, error: e.message }));
200
201
  }
201
202
  }))());
202
203
  yield Promise.all(promises);
@@ -217,7 +218,7 @@ function invokeFunction(options) {
217
218
  return Result;
218
219
  }
219
220
  catch (e) {
220
- throw new error_1.CloudBaseError(`[${functionName}] 调用失败:\n${e.message}`);
221
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 调用失败:\n{{error}}', { name: functionName, error: e.message }));
221
222
  }
222
223
  });
223
224
  }
@@ -233,13 +234,13 @@ function batchInvokeFunctions(options) {
233
234
  envId
234
235
  });
235
236
  if (log) {
236
- (0, logger_1.successLog)(`[${func.name}] 调用成功\n响应结果:\n`);
237
+ (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 调用成功\n响应结果:\n', { name: func.name }));
237
238
  console.log(result);
238
239
  }
239
240
  return result;
240
241
  }
241
242
  catch (e) {
242
- throw new error_1.CloudBaseError(`${func.name} 函数调用失败:${e.message}`);
243
+ throw new error_1.CloudBaseError((0, i18n_1.t)('{{name}} 函数调用失败:{{error}}', { name: func.name, error: e.message }));
243
244
  }
244
245
  }))());
245
246
  return Promise.all(promises);
@@ -250,7 +251,7 @@ function copyFunction(options) {
250
251
  return __awaiter(this, void 0, void 0, function* () {
251
252
  const { envId, functionName, newFunctionName, targetEnvId, force, codeSecret } = options;
252
253
  if (!envId || !functionName || !newFunctionName) {
253
- throw new error_1.CloudBaseError('参数缺失');
254
+ throw new error_1.CloudBaseError((0, i18n_1.t)('参数缺失'));
254
255
  }
255
256
  yield scfService.request('CopyFunction', {
256
257
  FunctionName: functionName,
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.deleteProvisionedConcurrencyConfig = exports.getProvisionedConcurrencyConfig = exports.setProvisionedConcurrencyConfig = void 0;
13
13
  const error_1 = require("../error");
14
14
  const base_1 = require("./base");
15
+ const i18n_1 = require("../i18n");
15
16
  function setProvisionedConcurrencyConfig(options) {
16
17
  return __awaiter(this, void 0, void 0, function* () {
17
18
  const { envId, functionName, qualifier, versionProvisionedConcurrencyNum } = options;
@@ -24,7 +25,7 @@ function setProvisionedConcurrencyConfig(options) {
24
25
  });
25
26
  }
26
27
  catch (e) {
27
- throw new error_1.CloudBaseError(`[${functionName}] 设置函数预置并发失败: ${e.message}`, {
28
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 设置函数预置并发失败: {{error}}', { name: functionName, error: e.message }), {
28
29
  code: e.code
29
30
  });
30
31
  }
@@ -42,7 +43,7 @@ function getProvisionedConcurrencyConfig(options) {
42
43
  });
43
44
  }
44
45
  catch (e) {
45
- throw new error_1.CloudBaseError(`[${functionName}] 查看函数预置并发信息失败: ${e.message}`, {
46
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 查看函数预置并发信息失败: {{error}}', { name: functionName, error: e.message }), {
46
47
  code: e.code
47
48
  });
48
49
  }
@@ -60,7 +61,7 @@ function deleteProvisionedConcurrencyConfig(options) {
60
61
  });
61
62
  }
62
63
  catch (e) {
63
- throw new error_1.CloudBaseError(`[${functionName}] 删除函数预置并发失败: ${e.message}`, {
64
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 删除函数预置并发失败: {{error}}', { name: functionName, error: e.message }), {
64
65
  code: e.code
65
66
  });
66
67
  }
@@ -13,6 +13,7 @@ exports.batchCreateFunctions = exports.createFunction = void 0;
13
13
  const utils_1 = require("../utils");
14
14
  const error_1 = require("../error");
15
15
  const base_1 = require("./base");
16
+ const i18n_1 = require("../i18n");
16
17
  function createFunction(options) {
17
18
  var _a;
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -34,7 +35,7 @@ function createFunction(options) {
34
35
  }
35
36
  catch (e) {
36
37
  if (e.message && !force) {
37
- throw new error_1.CloudBaseError(`[${funcName}] 部署失败,${e.message}`, {
38
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 部署失败,{{error}}', { name: funcName, error: e.message }), {
38
39
  code: e.code,
39
40
  original: e
40
41
  });
@@ -50,7 +51,7 @@ function batchCreateFunctions(options) {
50
51
  const promises = functions.map((func) => (() => __awaiter(this, void 0, void 0, function* () {
51
52
  const loading = (0, utils_1.loadingFactory)();
52
53
  try {
53
- log && loading.start(`[${func.name}] 函数部署中...`);
54
+ log && loading.start((0, i18n_1.t)('[{{name}}] 函数部署中...', { name: func.name }));
54
55
  yield createFunction({
55
56
  func,
56
57
  envId,
@@ -58,10 +59,10 @@ function batchCreateFunctions(options) {
58
59
  codeSecret,
59
60
  functionRootPath
60
61
  });
61
- log && loading.succeed(`[${func.name}] 函数部署成功`);
62
+ log && loading.succeed((0, i18n_1.t)('[{{name}}] 函数部署成功', { name: func.name }));
62
63
  }
63
64
  catch (e) {
64
- log && loading.fail(`[${func.name}] 函数部署失败`);
65
+ log && loading.fail((0, i18n_1.t)('[{{name}}] 函数部署失败', { name: func.name }));
65
66
  throw new error_1.CloudBaseError(e.message);
66
67
  }
67
68
  }))());
@@ -14,6 +14,7 @@ const logger_1 = require("../logger");
14
14
  const error_1 = require("../error");
15
15
  const utils_1 = require("../utils");
16
16
  const gateway_1 = require("../gateway");
17
+ const i18n_1 = require("../i18n");
17
18
  const scfService = utils_1.CloudApiService.getInstance('scf');
18
19
  function deleteFunction({ functionName, envId }) {
19
20
  var _a;
@@ -40,7 +41,7 @@ function batchDeleteFunctions({ names, envId }) {
40
41
  const promises = names.map(name => (() => __awaiter(this, void 0, void 0, function* () {
41
42
  try {
42
43
  yield deleteFunction({ functionName: name, envId });
43
- (0, logger_1.successLog)(`[${name}] 函数删除成功!`);
44
+ (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 函数删除成功!', { name }));
44
45
  }
45
46
  catch (e) {
46
47
  throw new error_1.CloudBaseError(e.message);
@@ -16,6 +16,7 @@ exports.unAttachLayer = exports.attachLayer = void 0;
16
16
  const lodash_1 = __importDefault(require("lodash"));
17
17
  const utils_1 = require("../../utils");
18
18
  const error_1 = require("../../error");
19
+ const i18n_1 = require("../../i18n");
19
20
  const __1 = require("../");
20
21
  const scfService = new utils_1.CloudApiService('scf');
21
22
  function attachLayer(options) {
@@ -45,7 +46,7 @@ function unAttachLayer(options) {
45
46
  Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
46
47
  const index = Layers.findIndex(item => item.LayerName === layerName && item.LayerVersion === layerVersion);
47
48
  if (index === -1) {
48
- throw new error_1.CloudBaseError('层不存在');
49
+ throw new error_1.CloudBaseError((0, i18n_1.t)('层不存在'));
49
50
  }
50
51
  Layers.splice(index, 1);
51
52
  const apiParams = {
@@ -17,6 +17,7 @@ const fs_1 = __importDefault(require("fs"));
17
17
  const path_1 = __importDefault(require("path"));
18
18
  const toolbox_1 = require("@cloudbase/toolbox");
19
19
  const utils_1 = require("../../utils");
20
+ const i18n_1 = require("../../i18n");
20
21
  const scfService = new utils_1.CloudApiService('scf');
21
22
  function createLayer(options) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -44,7 +45,7 @@ function createLayer(options) {
44
45
  else {
45
46
  const fileType = path_1.default.extname(contentPath);
46
47
  if (fileType !== '.zip') {
47
- throw new toolbox_1.CloudBaseError('文件类型不正确,目前只支持 ZIP 文件!');
48
+ throw new toolbox_1.CloudBaseError((0, i18n_1.t)('文件类型不正确,目前只支持 ZIP 文件!'));
48
49
  }
49
50
  const fileBuffer = yield fs_1.default.promises.readFile(contentPath);
50
51
  base64 = fileBuffer.toString('base64');
@@ -17,6 +17,7 @@ const path_1 = __importDefault(require("path"));
17
17
  const utils_1 = require("../../utils");
18
18
  const error_1 = require("../../error");
19
19
  const common_1 = require("../../utils/tools/common");
20
+ const i18n_1 = require("../../i18n");
20
21
  const scfService = new utils_1.CloudApiService('scf');
21
22
  function downloadLayer(options) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -28,7 +29,7 @@ function downloadLayer(options) {
28
29
  const url = res === null || res === void 0 ? void 0 : res.Location;
29
30
  const zipPath = path_1.default.join(destPath, `${name}-${version}.zip`);
30
31
  if ((0, utils_1.checkFullAccess)(zipPath)) {
31
- throw new error_1.CloudBaseError(`文件已存在:${zipPath}`);
32
+ throw new error_1.CloudBaseError((0, i18n_1.t)('文件已存在:{{path}}', { path: zipPath }));
32
33
  }
33
34
  return (0, common_1.downloadAndExtractRemoteZip)(url, destPath);
34
35
  });
@@ -13,13 +13,14 @@ exports.batchDeleteTriggers = exports.deleteFunctionTrigger = exports.batchCreat
13
13
  const utils_1 = require("../utils");
14
14
  const logger_1 = require("../logger");
15
15
  const error_1 = require("../error");
16
+ const i18n_1 = require("../i18n");
16
17
  const scfService = utils_1.CloudApiService.getInstance('scf');
17
18
  function createFunctionTriggers(options) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
19
20
  const { functionName, triggers = [], envId } = options;
20
21
  const parsedTriggers = triggers.map(item => {
21
22
  if (item.type !== 'timer') {
22
- throw new error_1.CloudBaseError(`不支持的触发器类型 [${item.type}],目前仅支持定时触发器(timer)!`);
23
+ throw new error_1.CloudBaseError((0, i18n_1.t)('不支持的触发器类型 [{{type}}],目前仅支持定时触发器(timer)!', { type: item.type }));
23
24
  }
24
25
  return {
25
26
  TriggerName: item.name,
@@ -36,7 +37,7 @@ function createFunctionTriggers(options) {
36
37
  });
37
38
  }
38
39
  catch (e) {
39
- throw new error_1.CloudBaseError(`[${functionName}] 创建触发器失败:${e.message}`, {
40
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 创建触发器失败:{{error}}', { name: functionName, error: e.message }), {
40
41
  action: e.action,
41
42
  code: e.code
42
43
  });
@@ -54,7 +55,7 @@ function batchCreateTriggers(options) {
54
55
  triggers: func.triggers,
55
56
  envId
56
57
  });
57
- (0, logger_1.successLog)(`[${func.name}] 创建云函数触发器成功!`);
58
+ (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 创建云函数触发器成功!', { name: func.name }));
58
59
  }
59
60
  catch (e) {
60
61
  throw new error_1.CloudBaseError(e.message);
@@ -74,10 +75,10 @@ function deleteFunctionTrigger(options) {
74
75
  TriggerName: triggerName,
75
76
  Type: 'timer'
76
77
  });
77
- (0, logger_1.successLog)(`[${functionName}] 删除云函数触发器 ${triggerName} 成功!`);
78
+ (0, logger_1.successLog)((0, i18n_1.t)('[{{name}}] 删除云函数触发器 {{trigger}} 成功!', { name: functionName, trigger: triggerName }));
78
79
  }
79
80
  catch (e) {
80
- throw new error_1.CloudBaseError(`[${functionName}] 删除触发器失败:${e.message}`);
81
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 删除触发器失败:{{error}}', { name: functionName, error: e.message }));
81
82
  }
82
83
  });
83
84
  }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.updateFunctionCode = void 0;
13
13
  const error_1 = require("../error");
14
14
  const base_1 = require("./base");
15
+ const i18n_1 = require("../i18n");
15
16
  function updateFunctionCode(options) {
16
17
  var _a;
17
18
  return __awaiter(this, void 0, void 0, function* () {
@@ -19,7 +20,7 @@ function updateFunctionCode(options) {
19
20
  const func = Object.assign(Object.assign({}, (_a = options === null || options === void 0 ? void 0 : options.func) === null || _a === void 0 ? void 0 : _a.config), options.func);
20
21
  const funcName = func.name;
21
22
  if (codeSecret && !/^[A-Za-z0-9+=/]{1,160}$/.test(codeSecret)) {
22
- throw new error_1.CloudBaseError('CodeSecret 格式错误,格式为 1-160 位大小字母,数字+=/');
23
+ throw new error_1.CloudBaseError((0, i18n_1.t)('CodeSecret 格式错误,格式为 1-160 位大小字母,数字+=/'));
23
24
  }
24
25
  const scfService = yield (0, base_1.getFunctionService)(envId);
25
26
  try {
@@ -31,7 +32,7 @@ function updateFunctionCode(options) {
31
32
  });
32
33
  }
33
34
  catch (e) {
34
- throw new error_1.CloudBaseError(`[${funcName}] 函数代码更新失败: ${e.message}`, {
35
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 函数代码更新失败: {{error}}', { name: funcName, error: e.message }), {
35
36
  code: e.code
36
37
  });
37
38
  }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.listFunctionVersions = exports.publishVersion = void 0;
13
13
  const error_1 = require("../error");
14
14
  const base_1 = require("./base");
15
+ const i18n_1 = require("../i18n");
15
16
  function publishVersion(options) {
16
17
  return __awaiter(this, void 0, void 0, function* () {
17
18
  const { envId, functionName, description = '' } = options;
@@ -23,7 +24,7 @@ function publishVersion(options) {
23
24
  });
24
25
  }
25
26
  catch (e) {
26
- throw new error_1.CloudBaseError(`[${functionName}] 函数发布新版本失败: ${e.message}`, {
27
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 函数发布新版本失败: {{error}}', { name: functionName, error: e.message }), {
27
28
  code: e.code
28
29
  });
29
30
  }
@@ -42,7 +43,7 @@ function listFunctionVersions(options) {
42
43
  });
43
44
  }
44
45
  catch (e) {
45
- throw new error_1.CloudBaseError(`[${functionName}] 查看寒函数版本列表失败: ${e.message}`, {
46
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 查看函数版本列表失败: {{error}}', { name: functionName, error: e.message }), {
46
47
  code: e.code
47
48
  });
48
49
  }
package/lib/help.js CHANGED
@@ -5,35 +5,37 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.outputHelpInfo = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
+ const i18n_1 = require("./i18n");
8
9
  const outputHelpInfo = () => {
9
10
  const commands = `
10
- 命令
11
- ai -- [cmd] 开启 AI 全栈开发体验
12
- login [options] 登录腾讯云账号
13
- logout 登出腾讯云账号
14
- env [cmd] 环境管理操作
15
- fn [cmd] 操作函数
16
- hosting [cmd] 静态托管资源管理操作
17
- storage [cmd] 云存储资源管理操作
18
- service [cmd] HTTP 访问服务管理操作
19
- cloudrun [cmd] 云托管服务管理操作`;
11
+ ${(0, i18n_1.t)('命令')}
12
+ ai -- [cmd] ${(0, i18n_1.t)('开启 AI 全栈开发体验')}
13
+ login [options] ${(0, i18n_1.t)('登录腾讯云账号')}
14
+ logout ${(0, i18n_1.t)('登出腾讯云账号')}
15
+ env [cmd] ${(0, i18n_1.t)('环境管理操作')}
16
+ fn [cmd] ${(0, i18n_1.t)('操作函数')}
17
+ hosting [cmd] ${(0, i18n_1.t)('静态托管资源管理操作')}
18
+ storage [cmd] ${(0, i18n_1.t)('云存储资源管理操作')}
19
+ service [cmd] ${(0, i18n_1.t)('HTTP 访问服务管理操作')}
20
+ cloudrun [cmd] ${(0, i18n_1.t)('云托管服务管理操作`')}
21
+ `;
20
22
  const options = `
21
- 选项
23
+ ${(0, i18n_1.t)('选项')}
22
24
 
23
- --verbose 打印出内部运行信息
24
- -r, --region <region> 指定环境地域
25
- --mode <mode> 指定加载 env 文件的环境
26
- --config-file <path> 指定配置文件路径
27
- -v, --version 输出当前版本
28
- -h, --help 查看命令帮助信息`;
25
+ --verbose ${(0, i18n_1.t)('打印出内部运行信息')}
26
+ -r, --region <region> ${(0, i18n_1.t)('指定环境地域')}
27
+ --mode <mode> ${(0, i18n_1.t)('指定加载 env 文件的环境')}
28
+ --config-file <path> ${(0, i18n_1.t)('指定配置文件路径')}
29
+ -v, --version ${(0, i18n_1.t)('输出当前版本')}
30
+ -h, --help ${(0, i18n_1.t)('查看命令帮助信息')}`;
29
31
  const tips = `
30
- Tips:
32
+ ${(0, i18n_1.t)('Tips')}:
31
33
 
32
- ${chalk_1.default.gray('–')} 登录
34
+ ${chalk_1.default.gray('–')} ${(0, i18n_1.t)('登录')}
33
35
 
34
36
  ${chalk_1.default.cyan('$ tcb login')}
35
37
 
36
- ${chalk_1.default.gray('–')} 使用 AI 全栈开发部署
38
+ ${chalk_1.default.gray('–')} ${(0, i18n_1.t)('使用 AI 全栈开发部署')}
37
39
 
38
40
  ${chalk_1.default.cyan('$ tcb ai')}
39
41
  `;
package/lib/hosting.js CHANGED
@@ -18,14 +18,15 @@ const utils_1 = require("./utils");
18
18
  const error_1 = require("./error");
19
19
  const inquirer_1 = __importDefault(require("inquirer"));
20
20
  const constant_1 = require("./constant");
21
+ const i18n_1 = require("./i18n");
21
22
  const HostingStatusMap = {
22
- init: '初始化中',
23
- process: '处理中',
24
- online: '上线',
25
- destroying: '销毁中',
26
- offline: '下线',
27
- create_fail: '初始化失败',
28
- destroy_fail: '销毁失败'
23
+ init: (0, i18n_1.t)('初始化中'),
24
+ process: (0, i18n_1.t)('处理中'),
25
+ online: (0, i18n_1.t)('上线'),
26
+ destroying: (0, i18n_1.t)('销毁中'),
27
+ offline: (0, i18n_1.t)('下线'),
28
+ create_fail: (0, i18n_1.t)('初始化失败'),
29
+ destroy_fail: (0, i18n_1.t)('销毁失败')
29
30
  };
30
31
  const tcbService = utils_1.CloudApiService.getInstance('tcb');
31
32
  function getHostingInfo(options) {
@@ -47,24 +48,24 @@ function initHosting(options) {
47
48
  const { confirm } = yield inquirer_1.default.prompt({
48
49
  type: 'confirm',
49
50
  name: 'confirm',
50
- message: '您还未开通静态托管,是否立即开通?'
51
+ message: (0, i18n_1.t)('您还未开通静态托管,是否立即开通?')
51
52
  });
52
53
  if (confirm) {
53
54
  const res = yield subscribeHosting({ envId });
54
55
  if (!res.code) {
55
- utils_1.logger.success('开通静态托管成功!资源正在初始化中,请稍候3~5分钟再试...');
56
+ utils_1.logger.success((0, i18n_1.t)('开通静态托管成功!资源正在初始化中,请稍候3~5分钟再试...'));
56
57
  return;
57
58
  }
58
59
  else {
59
- throw new error_1.CloudBaseError(`开通静态托管失败\n request id: ${res.requestId}`);
60
+ throw new error_1.CloudBaseError((0, i18n_1.t)('开通静态托管失败\n request id: {{requestId}}', { requestId: res.requestId }));
60
61
  }
61
62
  }
62
63
  else
63
64
  return;
64
65
  }
65
66
  else {
66
- const link = (0, utils_1.genClickableLink)('https://console.cloud.tencent.com/tcb');
67
- throw new error_1.CloudBaseError(`您还没有开启静态网站服务,请先到云开发控制台开启静态网站服务!\n👉 ${link}`, {
67
+ const link = (0, utils_1.genClickableLink)(utils_1.EUrl.TcbConsole);
68
+ throw new error_1.CloudBaseError((0, i18n_1.t)('您还没有开启静态网站服务,请先到云开发控制台开启静态网站服务!\n👉 {{link}}', { link }), {
68
69
  code: 'INVALID_OPERATION'
69
70
  });
70
71
  }
@@ -80,7 +81,7 @@ function checkHostingStatus(envId) {
80
81
  }
81
82
  const website = hostings.data[0];
82
83
  if (website.status !== 'online') {
83
- throw new error_1.CloudBaseError(`静态网站服务【${HostingStatusMap[website.status]}】,无法进行此操作!`, {
84
+ throw new error_1.CloudBaseError((0, i18n_1.t)('静态网站服务【{{status}}】,无法进行此操作!', { status: HostingStatusMap[website.status] }), {
84
85
  code: 'INVALID_OPERATION'
85
86
  });
86
87
  }
@@ -96,7 +97,7 @@ function enableHosting(options) {
96
97
  if ((_a = hostings === null || hostings === void 0 ? void 0 : hostings.data) === null || _a === void 0 ? void 0 : _a.length) {
97
98
  const website = hostings.data[0];
98
99
  if (website.status !== 'offline') {
99
- throw new error_1.CloudBaseError('静态网站服务已开启,请勿重复操作!');
100
+ throw new error_1.CloudBaseError((0, i18n_1.t)('静态网站服务已开启,请勿重复操作!'));
100
101
  }
101
102
  }
102
103
  const res = yield tcbService.request('CreateStaticStore', {
@@ -155,19 +156,19 @@ function destroyHosting(options) {
155
156
  const { envId } = options;
156
157
  const files = yield hostingList(options);
157
158
  if (files === null || files === void 0 ? void 0 : files.length) {
158
- throw new error_1.CloudBaseError('静态网站文件不为空,无法销毁!', {
159
+ throw new error_1.CloudBaseError((0, i18n_1.t)('静态网站文件不为空,无法销毁!'), {
159
160
  code: 'INVALID_OPERATION'
160
161
  });
161
162
  }
162
163
  const hostings = yield getHostingInfo(options);
163
164
  if (!hostings.data || !hostings.data.length) {
164
- throw new error_1.CloudBaseError('静态网站服务未开启!', {
165
+ throw new error_1.CloudBaseError((0, i18n_1.t)('静态网站服务未开启!'), {
165
166
  code: 'INVALID_OPERATION'
166
167
  });
167
168
  }
168
169
  const website = hostings.data[0];
169
170
  if (website.status !== 'online' && website.status !== 'destroy_fail') {
170
- throw new error_1.CloudBaseError(`静态网站服务【${HostingStatusMap[website.status]}】,无法进行此操作!`, {
171
+ throw new error_1.CloudBaseError((0, i18n_1.t)('静态网站服务【{{status}}】,无法进行此操作!', { status: HostingStatusMap[website.status] }), {
171
172
  code: 'INVALID_OPERATION'
172
173
  });
173
174
  }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isIntl = exports.getLanguage = exports.t = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const os_locale_1 = __importDefault(require("os-locale"));
10
+ const db_1 = require("../utils/store/db");
11
+ let i18n;
12
+ const configDB = (0, db_1.getSyncDB)('config');
13
+ const AVAILABLE_LANGS = ['zh', 'en'];
14
+ class I18n {
15
+ constructor() {
16
+ this.lang = getLanguage();
17
+ if (this.lang !== 'zh') {
18
+ this.loadLanguage();
19
+ this.loadMapping();
20
+ }
21
+ }
22
+ t(key, options) {
23
+ if (this.lang === 'zh') {
24
+ return this.replaceVars(key, options);
25
+ }
26
+ const mappedKey = this.mapping[key];
27
+ if (mappedKey) {
28
+ return this.replaceVars(this.data[mappedKey], options);
29
+ }
30
+ return key;
31
+ }
32
+ loadLanguage() {
33
+ const langPath = path_1.default.resolve(I18n.langDir, `${this.lang}.json`);
34
+ const langData = fs_1.default.readFileSync(langPath, 'utf-8');
35
+ this.data = JSON.parse(langData);
36
+ }
37
+ replaceVars(str, vars) {
38
+ let result = str;
39
+ if (!vars) {
40
+ return result;
41
+ }
42
+ Object.entries(vars).forEach(([key, value]) => {
43
+ result = result.replace(`{{${key}}}`, value);
44
+ });
45
+ return result;
46
+ }
47
+ loadMapping() {
48
+ const mappingPath = path_1.default.resolve(__dirname, '../../locales/mapping.json');
49
+ const mappingStr = fs_1.default.readFileSync(mappingPath, 'utf-8');
50
+ this.mapping = JSON.parse(mappingStr);
51
+ }
52
+ }
53
+ I18n.langDir = path_1.default.resolve(__dirname, '../../locales/langs');
54
+ function t(key, options) {
55
+ if (!i18n) {
56
+ i18n = new I18n();
57
+ }
58
+ return i18n.t(key, options);
59
+ }
60
+ exports.t = t;
61
+ function getLanguage() {
62
+ let lang = 'zh';
63
+ const configLang = configDB.get('lang').value();
64
+ if (AVAILABLE_LANGS.includes(configLang)) {
65
+ lang = configLang;
66
+ }
67
+ else {
68
+ const systemLang = os_locale_1.default.sync();
69
+ lang = systemLang.startsWith('zh') ? 'zh' : 'en';
70
+ }
71
+ return lang;
72
+ }
73
+ exports.getLanguage = getLanguage;
74
+ let intl;
75
+ function isIntl() {
76
+ if (intl === undefined) {
77
+ intl = configDB.get('isIntl').value() || process.env.TCB_IS_INTL === 'true' || false;
78
+ }
79
+ return intl;
80
+ }
81
+ exports.isIntl = isIntl;