@cloudbase/cli 2.10.0-beta.0 → 2.11.0-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 (205) hide show
  1. package/lib/auth/login.js +51 -65
  2. package/lib/auth/logout.js +3 -14
  3. package/lib/commands/account/login.js +136 -149
  4. package/lib/commands/account/logout.js +3 -14
  5. package/lib/commands/ag/base.js +203 -0
  6. package/lib/commands/ag/create.js +301 -0
  7. package/lib/commands/ag/debug/index.html +699 -0
  8. package/lib/commands/ag/delete.js +200 -0
  9. package/lib/commands/ag/deploy.js +185 -0
  10. package/lib/commands/ag/detail.js +113 -0
  11. package/lib/commands/ag/index.js +22 -0
  12. package/lib/commands/ag/list.js +155 -0
  13. package/lib/commands/ag/run.js +644 -0
  14. package/lib/commands/ai/index.js +76 -95
  15. package/lib/commands/cloudfunction/base.js +182 -203
  16. package/lib/commands/cloudrun/base.js +578 -603
  17. package/lib/commands/common.js +48 -63
  18. package/lib/commands/config/delete.js +16 -27
  19. package/lib/commands/config/get.js +13 -24
  20. package/lib/commands/config/list.js +16 -27
  21. package/lib/commands/config/set.js +33 -44
  22. package/lib/commands/db/base.js +221 -240
  23. package/lib/commands/env/base.js +36 -49
  24. package/lib/commands/env/domain.js +79 -94
  25. package/lib/commands/env/login.js +120 -135
  26. package/lib/commands/framework/index.js +32 -49
  27. package/lib/commands/fun/base.js +223 -244
  28. package/lib/commands/functions/alias/getRoute.js +33 -44
  29. package/lib/commands/functions/alias/setRoute.js +36 -47
  30. package/lib/commands/functions/code-download.js +43 -54
  31. package/lib/commands/functions/code-update.js +23 -34
  32. package/lib/commands/functions/concurrency/delete.js +11 -22
  33. package/lib/commands/functions/concurrency/list.js +20 -31
  34. package/lib/commands/functions/concurrency/set.js +13 -24
  35. package/lib/commands/functions/config-update.js +30 -41
  36. package/lib/commands/functions/copy.js +12 -23
  37. package/lib/commands/functions/delete.js +30 -41
  38. package/lib/commands/functions/deploy.js +184 -202
  39. package/lib/commands/functions/detail.js +23 -34
  40. package/lib/commands/functions/invoke.js +69 -75
  41. package/lib/commands/functions/layer/bind.js +102 -105
  42. package/lib/commands/functions/layer/create.js +29 -35
  43. package/lib/commands/functions/layer/delete.js +42 -48
  44. package/lib/commands/functions/layer/download.js +52 -58
  45. package/lib/commands/functions/layer/list.js +44 -50
  46. package/lib/commands/functions/layer/sort.js +39 -45
  47. package/lib/commands/functions/list.js +25 -36
  48. package/lib/commands/functions/log.js +65 -73
  49. package/lib/commands/functions/run.js +118 -116
  50. package/lib/commands/functions/trigger-create.js +32 -43
  51. package/lib/commands/functions/trigger-delete.js +50 -61
  52. package/lib/commands/functions/version/list.js +29 -40
  53. package/lib/commands/functions/version/publish.js +11 -22
  54. package/lib/commands/gateway/create.js +50 -61
  55. package/lib/commands/gateway/delete.js +38 -49
  56. package/lib/commands/gateway/domain.js +65 -80
  57. package/lib/commands/gateway/list.js +31 -42
  58. package/lib/commands/gateway/switch.js +48 -61
  59. package/lib/commands/helpers/init.js +226 -249
  60. package/lib/commands/helpers/new.js +35 -46
  61. package/lib/commands/helpers/open.js +22 -33
  62. package/lib/commands/hosting/hosting.js +157 -178
  63. package/lib/commands/index.js +1 -0
  64. package/lib/commands/lowcode/app.js +114 -144
  65. package/lib/commands/lowcode/comps.js +136 -127
  66. package/lib/commands/lowcode/utils.js +11 -22
  67. package/lib/commands/pull/pull.js +33 -46
  68. package/lib/commands/run/delete.js +35 -46
  69. package/lib/commands/run/image/delete.js +32 -39
  70. package/lib/commands/run/image/download.js +26 -33
  71. package/lib/commands/run/image/list.js +41 -48
  72. package/lib/commands/run/image/upload.js +26 -33
  73. package/lib/commands/run/list.js +32 -43
  74. package/lib/commands/run/service/config.js +17 -28
  75. package/lib/commands/run/service/deploy.js +15 -26
  76. package/lib/commands/run/service/list.js +48 -59
  77. package/lib/commands/run/service/update.js +7 -18
  78. package/lib/commands/run/standalonegateway/create.js +35 -42
  79. package/lib/commands/run/standalonegateway/destroy.js +23 -30
  80. package/lib/commands/run/standalonegateway/list.js +19 -26
  81. package/lib/commands/run/standalonegateway/package.js +31 -38
  82. package/lib/commands/run/standalonegateway/turn.js +27 -34
  83. package/lib/commands/run/version/create.js +198 -205
  84. package/lib/commands/run/version/delete.js +31 -38
  85. package/lib/commands/run/version/list.js +42 -49
  86. package/lib/commands/run/version/modify.js +27 -34
  87. package/lib/commands/run/version/update.js +201 -208
  88. package/lib/commands/runf/base.js +216 -237
  89. package/lib/commands/self-update.js +59 -72
  90. package/lib/commands/smart.js +66 -79
  91. package/lib/commands/storage/storage.js +192 -219
  92. package/lib/commands/third/thirdAttach.js +16 -27
  93. package/lib/commands/utils.js +119 -149
  94. package/lib/db/index.js +48 -67
  95. package/lib/decorators/captureError.js +10 -21
  96. package/lib/decorators/guard.js +11 -22
  97. package/lib/decorators/injectParams.js +29 -40
  98. package/lib/decorators/params/common.js +5 -2
  99. package/lib/decorators/params/index.js +3 -12
  100. package/lib/env/domain.js +13 -28
  101. package/lib/env/index.js +25 -44
  102. package/lib/env/login.js +30 -45
  103. package/lib/function/alias.js +31 -44
  104. package/lib/function/base.js +187 -215
  105. package/lib/function/code.js +8 -19
  106. package/lib/function/concurrency.js +43 -58
  107. package/lib/function/create.js +43 -53
  108. package/lib/function/delete.js +22 -35
  109. package/lib/function/layer/attach.js +33 -46
  110. package/lib/function/layer/create.js +34 -45
  111. package/lib/function/layer/delete.js +5 -16
  112. package/lib/function/layer/download.js +11 -22
  113. package/lib/function/layer/list.js +12 -25
  114. package/lib/function/layer/sort.js +6 -17
  115. package/lib/function/trigger.js +65 -82
  116. package/lib/function/update.js +24 -32
  117. package/lib/function/version.js +29 -42
  118. package/lib/function/vpc.js +12 -25
  119. package/lib/gateway/index.js +77 -104
  120. package/lib/hosting.js +157 -188
  121. package/lib/run/delete.js +3 -12
  122. package/lib/run/image/build.js +6 -15
  123. package/lib/run/image/delete.js +3 -12
  124. package/lib/run/image/info.js +3 -12
  125. package/lib/run/image/list.js +6 -15
  126. package/lib/run/list.js +19 -30
  127. package/lib/run/repo.js +6 -15
  128. package/lib/run/service/common.js +160 -173
  129. package/lib/run/service/config.js +44 -57
  130. package/lib/run/service/deployPackage.js +33 -44
  131. package/lib/run/service/list.js +8 -14
  132. package/lib/run/service/showLogs.js +69 -90
  133. package/lib/run/service/update.js +50 -63
  134. package/lib/run/standalonegateway/create.js +3 -12
  135. package/lib/run/standalonegateway/destroy.js +3 -12
  136. package/lib/run/standalonegateway/list.js +3 -12
  137. package/lib/run/standalonegateway/package/list.js +3 -12
  138. package/lib/run/standalonegateway/turn/off.js +3 -12
  139. package/lib/run/standalonegateway/turn/on.js +3 -12
  140. package/lib/run/version/create.js +41 -31
  141. package/lib/run/version/delete.js +3 -12
  142. package/lib/run/version/list.js +3 -12
  143. package/lib/run/version/modify.js +3 -12
  144. package/lib/run/version/repo.js +6 -15
  145. package/lib/run/version/update.js +37 -26
  146. package/lib/storage.js +62 -93
  147. package/lib/third/index.js +6 -17
  148. package/lib/utils/ai/banner.js +49 -60
  149. package/lib/utils/ai/claudeWindows.js +2 -2
  150. package/lib/utils/ai/config.js +169 -206
  151. package/lib/utils/ai/ensureFiles.js +6 -17
  152. package/lib/utils/ai/env.js +16 -27
  153. package/lib/utils/ai/envLocalManager.js +35 -52
  154. package/lib/utils/ai/router.js +927 -1005
  155. package/lib/utils/ai/setup.js +527 -563
  156. package/lib/utils/auth.js +3 -14
  157. package/lib/utils/checkTcbrEnv.js +20 -31
  158. package/lib/utils/cli-table.js +6 -1
  159. package/lib/utils/config.js +4 -13
  160. package/lib/utils/dts.js +98 -113
  161. package/lib/utils/env.js +154 -175
  162. package/lib/utils/function-packer.js +29 -42
  163. package/lib/utils/log.js +10 -21
  164. package/lib/utils/mcp-config-modifier.js +105 -120
  165. package/lib/utils/net/cloud-api-request.js +15 -23
  166. package/lib/utils/net/credential.js +26 -39
  167. package/lib/utils/net/http-request.js +63 -80
  168. package/lib/utils/net/manager-service.js +22 -35
  169. package/lib/utils/notice.js +16 -27
  170. package/lib/utils/output/loading.js +3 -12
  171. package/lib/utils/parallel.js +32 -43
  172. package/lib/utils/platform/mac.js +4 -15
  173. package/lib/utils/platform/port.js +4 -15
  174. package/lib/utils/prompt/select.js +6 -15
  175. package/lib/utils/report.js +28 -33
  176. package/lib/utils/reporter/agree.js +11 -22
  177. package/lib/utils/reporter/download.js +17 -28
  178. package/lib/utils/reporter/usage.js +12 -23
  179. package/lib/utils/store/auth.js +17 -30
  180. package/lib/utils/store/config.js +11 -25
  181. package/lib/utils/store/db.js +17 -36
  182. package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
  183. package/lib/utils/template-manager.js +215 -242
  184. package/lib/utils/template.js +81 -96
  185. package/lib/utils/tools/common.js +45 -56
  186. package/lib/utils/tools/time.js +5 -16
  187. package/lib/utils/url.js +10 -4
  188. package/package.json +2 -2
  189. package/specs/ag-command/design.md +421 -0
  190. package/specs/ag-command/doc.md +204 -0
  191. package/specs/ag-command/requirements.md +173 -0
  192. package/specs/ag-command/summary.md +174 -0
  193. package/specs/ag-command/tasks.md +197 -0
  194. package/specs/ag-command/usage-guide.md +420 -0
  195. package/tsconfig.json +1 -1
  196. package/types/commands/ag/base.d.ts +44 -0
  197. package/types/commands/ag/create.d.ts +25 -0
  198. package/types/commands/ag/delete.d.ts +32 -0
  199. package/types/commands/ag/deploy.d.ts +31 -0
  200. package/types/commands/ag/detail.d.ts +28 -0
  201. package/types/commands/ag/index.d.ts +6 -0
  202. package/types/commands/ag/list.d.ts +35 -0
  203. package/types/commands/ag/run.d.ts +52 -0
  204. package/types/commands/cloudrun/base.d.ts +10 -0
  205. package/types/commands/index.d.ts +1 -0
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -47,45 +38,43 @@ let DeleteFunction = class DeleteFunction extends common_1.Command {
47
38
  desc: (0, i18n_1.t)('删除云函数')
48
39
  };
49
40
  }
50
- execute(ctx, params) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const name = params === null || params === void 0 ? void 0 : params[0];
53
- const { envId, config: { functions } } = ctx;
54
- const functionService = yield (0, function_1.getFunctionService)(envId);
55
- let isBatchDelete = false;
56
- if (!name) {
57
- const answer = yield inquirer_1.default.prompt({
41
+ async execute(ctx, params) {
42
+ const name = params === null || params === void 0 ? void 0 : params[0];
43
+ const { envId, config: { functions } } = ctx;
44
+ const functionService = await (0, function_1.getFunctionService)(envId);
45
+ let isBatchDelete = false;
46
+ if (!name) {
47
+ const answer = await inquirer_1.default.prompt({
48
+ type: 'confirm',
49
+ name: 'isBatch',
50
+ message: (0, i18n_1.t)('无云函数名称,是否需要删除配置文件中的全部云函数?'),
51
+ default: false
52
+ });
53
+ if (answer.isBatch) {
54
+ const { reConfirm } = await inquirer_1.default.prompt({
58
55
  type: 'confirm',
59
- name: 'isBatch',
60
- message: (0, i18n_1.t)('无云函数名称,是否需要删除配置文件中的全部云函数?'),
56
+ name: 'reConfirm',
57
+ message: (0, i18n_1.t)('确定要删除配置文件中的全部云函数?'),
61
58
  default: false
62
59
  });
63
- if (answer.isBatch) {
64
- const { reConfirm } = yield inquirer_1.default.prompt({
65
- type: 'confirm',
66
- name: 'reConfirm',
67
- message: (0, i18n_1.t)('确定要删除配置文件中的全部云函数?'),
68
- default: false
69
- });
70
- isBatchDelete = reConfirm;
71
- }
72
- if (!isBatchDelete) {
73
- throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要删除的云函数名称!'));
74
- }
60
+ isBatchDelete = reConfirm;
75
61
  }
76
- if (isBatchDelete) {
77
- const names = functions.map((item) => item.name);
78
- return functionService.batchDeleteFunctions({
79
- names
80
- });
62
+ if (!isBatchDelete) {
63
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要删除的云函数名称!'));
81
64
  }
82
- const loading = (0, utils_1.loadingFactory)();
83
- loading.start((0, i18n_1.t)('删除函数 [{{name}}] 中...', { name }));
84
- yield functionService.deleteFunction({
85
- name
65
+ }
66
+ if (isBatchDelete) {
67
+ const names = functions.map((item) => item.name);
68
+ return functionService.batchDeleteFunctions({
69
+ names
86
70
  });
87
- loading.succeed((0, i18n_1.t)('删除函数 [{{name}}] 成功!', { name }));
71
+ }
72
+ const loading = (0, utils_1.loadingFactory)();
73
+ loading.start((0, i18n_1.t)('删除函数 [{{name}}] 中...', { name }));
74
+ await functionService.deleteFunction({
75
+ name
88
76
  });
77
+ loading.succeed((0, i18n_1.t)('删除函数 [{{name}}] 成功!', { name }));
89
78
  }
90
79
  };
91
80
  __decorate([
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -77,236 +68,227 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
77
68
  desc: (0, i18n_1.t)('部署云函数')
78
69
  };
79
70
  }
80
- execute(ctx, params, log) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- const { envId, config, options } = ctx;
83
- const { functions } = config;
84
- const { force, codeSecret, path: access, all, dir } = options;
85
- const functionRootPath = path_1.default.join(process.cwd(), config.functionRoot);
86
- const name = params === null || params === void 0 ? void 0 : params[0];
87
- if (access && (0, utils_1.checkFullAccess)(access)) {
88
- log.warn((0, i18n_1.t)('--path 参数已更换为HTTP 访问服务路径,请使用 --dir 指定部署函数的文件夹路径'));
89
- }
90
- if (access && access[0] !== '/') {
91
- throw new error_1.CloudBaseError((0, i18n_1.t)('HTTP 访问服务路径必须以 / 开头'));
92
- }
93
- if ((!name && !dir) || all) {
94
- return this.deployAllFunction({
95
- all,
96
- envId,
97
- force,
98
- access,
99
- functions,
100
- codeSecret,
101
- functionRootPath
102
- });
103
- }
104
- if (dir) {
105
- (0, utils_1.checkFullAccess)(dir, true);
106
- if (!(0, utils_1.isDirectory)(dir)) {
107
- throw new error_1.CloudBaseError((0, i18n_1.t)('--dir 参数必须指定为云函数的文件夹路径'));
108
- }
109
- }
110
- let newFunction;
111
- if (functions && functions.length > 0) {
112
- newFunction = functions.find((item) => item.name === name);
71
+ async execute(ctx, params, log) {
72
+ const { envId, config, options } = ctx;
73
+ const { functions } = config;
74
+ const { force, codeSecret, path: access, all, dir } = options;
75
+ const functionRootPath = path_1.default.join(process.cwd(), config.functionRoot);
76
+ const name = params === null || params === void 0 ? void 0 : params[0];
77
+ if (access && (0, utils_1.checkFullAccess)(access)) {
78
+ log.warn((0, i18n_1.t)('--path 参数已更换为HTTP 访问服务路径,请使用 --dir 指定部署函数的文件夹路径'));
79
+ }
80
+ if (access && access[0] !== '/') {
81
+ throw new error_1.CloudBaseError((0, i18n_1.t)('HTTP 访问服务路径必须以 / 开头'));
82
+ }
83
+ if ((!name && !dir) || all) {
84
+ return this.deployAllFunction({
85
+ all,
86
+ envId,
87
+ force,
88
+ access,
89
+ functions,
90
+ codeSecret,
91
+ functionRootPath
92
+ });
93
+ }
94
+ if (dir) {
95
+ (0, utils_1.checkFullAccess)(dir, true);
96
+ if (!(0, utils_1.isDirectory)(dir)) {
97
+ throw new error_1.CloudBaseError((0, i18n_1.t)('--dir 参数必须指定为云函数的文件夹路径'));
113
98
  }
114
- if (!newFunction || !newFunction.name) {
115
- log.info((0, i18n_1.t)('未找到函数发布配置,使用默认配置 => 运行时:Nodejs10.15/在线安装依赖'));
116
- newFunction = Object.assign({ name }, constant_1.DefaultFunctionDeployConfig);
99
+ }
100
+ let newFunction;
101
+ if (functions && functions.length > 0) {
102
+ newFunction = functions.find((item) => item.name === name);
103
+ }
104
+ if (!newFunction || !newFunction.name) {
105
+ log.info((0, i18n_1.t)('未找到函数发布配置,使用默认配置 => 运行时:Nodejs10.15/在线安装依赖'));
106
+ newFunction = {
107
+ name,
108
+ ...constant_1.DefaultFunctionDeployConfig
109
+ };
110
+ }
111
+ const loading = (0, utils_1.loadingFactory)();
112
+ loading.start((0, i18n_1.t)('云函数部署中...'));
113
+ try {
114
+ await (0, function_1.createFunction)({
115
+ force,
116
+ envId,
117
+ codeSecret,
118
+ functionRootPath,
119
+ func: newFunction,
120
+ accessPath: access,
121
+ functionPath: dir
122
+ });
123
+ loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功!', { name: newFunction.name }));
124
+ this.printSuccessTips(envId);
125
+ }
126
+ catch (e) {
127
+ loading.stop();
128
+ await this.handleDeployFail(e, {
129
+ envId,
130
+ codeSecret,
131
+ functionRootPath,
132
+ func: newFunction,
133
+ accessPath: access,
134
+ functionPath: dir
135
+ });
136
+ }
137
+ if (access || newFunction.path) {
138
+ const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access || newFunction.path}`);
139
+ console.log((0, i18n_1.t)('\n云函数HTTP 访问服务访问链接:{{link}}', { link }));
140
+ }
141
+ }
142
+ async deployAllFunction(options) {
143
+ const { functions = [], envId, force, codeSecret, functionRootPath, all, access } = options;
144
+ if (!all) {
145
+ const { isBatch } = await inquirer_1.default.prompt({
146
+ type: 'confirm',
147
+ name: 'isBatch',
148
+ message: (0, i18n_1.t)('没有指定需要部署的云函数,是否部署配置文件中的全部云函数?'),
149
+ default: false
150
+ });
151
+ if (!isBatch) {
152
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要部署的云函数的名称或通过 --path 参数指定需要部署的函数的路径!'));
117
153
  }
118
- const loading = (0, utils_1.loadingFactory)();
119
- loading.start((0, i18n_1.t)('云函数部署中...'));
154
+ }
155
+ const loading = (0, utils_1.loadingFactory)();
156
+ const tasks = functions.map((func) => async () => {
157
+ loading.start((0, i18n_1.t)('云函数部署中'));
120
158
  try {
121
- yield (0, function_1.createFunction)({
122
- force,
159
+ await (0, function_1.createFunction)({
160
+ func,
123
161
  envId,
162
+ force,
124
163
  codeSecret,
125
164
  functionRootPath,
126
- func: newFunction,
127
- accessPath: access,
128
- functionPath: dir
165
+ accessPath: access
129
166
  });
130
- loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功!', { name: newFunction.name }));
131
- this.printSuccessTips(envId);
167
+ loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功', { name: func.name }));
132
168
  }
133
169
  catch (e) {
134
170
  loading.stop();
135
- yield this.handleDeployFail(e, {
171
+ await this.handleDeployFail(e, {
172
+ func,
136
173
  envId,
137
174
  codeSecret,
138
175
  functionRootPath,
139
- func: newFunction,
140
- accessPath: access,
141
- functionPath: dir
176
+ accessPath: access
142
177
  });
143
178
  }
144
- if (access || newFunction.path) {
145
- const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access || newFunction.path}`);
146
- console.log((0, i18n_1.t)('\n云函数HTTP 访问服务访问链接:{{link}}', { link }));
147
- }
148
179
  });
180
+ if (tasks.length > 5) {
181
+ utils_1.logger.info((0, i18n_1.t)('函数数量较多,将使用队列部署'));
182
+ }
183
+ const asyncTaskController = new utils_1.AsyncTaskParallelController(5, 50);
184
+ asyncTaskController.loadTasks(tasks);
185
+ const results = await asyncTaskController.run();
186
+ const success = results.filter((_) => !_);
187
+ utils_1.logger.success((0, i18n_1.t)('成功部署 {{count}} 个函数', { count: success === null || success === void 0 ? void 0 : success.length }));
188
+ const err = results.filter((_) => _);
189
+ (err === null || err === void 0 ? void 0 : err.length) && utils_1.logger.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: err === null || err === void 0 ? void 0 : err.length }));
149
190
  }
150
- deployAllFunction(options) {
151
- return __awaiter(this, void 0, void 0, function* () {
152
- const { functions = [], envId, force, codeSecret, functionRootPath, all, access } = options;
153
- if (!all) {
154
- const { isBatch } = yield inquirer_1.default.prompt({
155
- type: 'confirm',
156
- name: 'isBatch',
157
- message: (0, i18n_1.t)('没有指定需要部署的云函数,是否部署配置文件中的全部云函数?'),
158
- default: false
159
- });
160
- if (!isBatch) {
161
- throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要部署的云函数的名称或通过 --path 参数指定需要部署的函数的路径!'));
162
- }
163
- }
164
- const loading = (0, utils_1.loadingFactory)();
165
- const tasks = functions.map((func) => () => __awaiter(this, void 0, void 0, function* () {
166
- loading.start((0, i18n_1.t)('云函数部署中'));
191
+ async handleDeployFail(e, options) {
192
+ const { envId, codeSecret, functionRootPath, func, functionPath, accessPath } = options;
193
+ const loading = (0, utils_1.loadingFactory)();
194
+ if (e.code === 'ResourceInUse.FunctionName' || e.code === 'ResourceInUse.Function') {
195
+ const { force } = await inquirer_1.default.prompt({
196
+ type: 'confirm',
197
+ name: 'force',
198
+ message: (0, i18n_1.t)('存在同名云函数:[{{name}}],是否覆盖原函数代码与配置', { name: func.name }),
199
+ default: false
200
+ });
201
+ const { triggers } = func;
202
+ if (force) {
203
+ loading.start((0, i18n_1.t)('云函数更新部署中...'));
167
204
  try {
168
- yield (0, function_1.createFunction)({
205
+ await (0, function_2.updateFunctionCode)({
169
206
  func,
170
207
  envId,
171
- force,
172
208
  codeSecret,
173
- functionRootPath,
174
- accessPath: access
209
+ functionRootPath
210
+ });
211
+ await this.waitForFunctionReady(envId, func.name, loading);
212
+ loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
213
+ await (0, function_2.updateFunctionConfig)({
214
+ envId,
215
+ functionName: func.name,
216
+ config: func
175
217
  });
176
- loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功', { name: func.name }));
218
+ loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
219
+ await this.printSuccessTips(envId);
177
220
  }
178
221
  catch (e) {
179
222
  loading.stop();
180
- yield this.handleDeployFail(e, {
181
- func,
182
- envId,
183
- codeSecret,
184
- functionRootPath,
185
- accessPath: access
186
- });
223
+ throw e;
187
224
  }
188
- }));
189
- if (tasks.length > 5) {
190
- utils_1.logger.info((0, i18n_1.t)('函数数量较多,将使用队列部署'));
225
+ return;
191
226
  }
192
- const asyncTaskController = new utils_1.AsyncTaskParallelController(5, 50);
193
- asyncTaskController.loadTasks(tasks);
194
- const results = yield asyncTaskController.run();
195
- const success = results.filter((_) => !_);
196
- utils_1.logger.success((0, i18n_1.t)('成功部署 {{count}} 个函数', { count: success === null || success === void 0 ? void 0 : success.length }));
197
- const err = results.filter((_) => _);
198
- (err === null || err === void 0 ? void 0 : err.length) && utils_1.logger.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: err === null || err === void 0 ? void 0 : err.length }));
199
- });
227
+ }
228
+ throw e;
200
229
  }
201
- handleDeployFail(e, options) {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- const { envId, codeSecret, functionRootPath, func, functionPath, accessPath } = options;
204
- const loading = (0, utils_1.loadingFactory)();
205
- if (e.code === 'ResourceInUse.FunctionName' || e.code === 'ResourceInUse.Function') {
206
- const { force } = yield inquirer_1.default.prompt({
207
- type: 'confirm',
208
- name: 'force',
209
- message: (0, i18n_1.t)('存在同名云函数:[{{name}}],是否覆盖原函数代码与配置', { name: func.name }),
210
- default: false
211
- });
212
- const { triggers } = func;
213
- if (force) {
214
- loading.start((0, i18n_1.t)('云函数更新部署中...'));
215
- try {
216
- yield (0, function_2.updateFunctionCode)({
217
- func,
218
- envId,
219
- codeSecret,
220
- functionRootPath
221
- });
222
- yield this.waitForFunctionReady(envId, func.name, loading);
223
- loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
224
- yield (0, function_2.updateFunctionConfig)({
225
- envId,
226
- functionName: func.name,
227
- config: func
228
- });
229
- loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
230
- yield this.printSuccessTips(envId);
230
+ async waitForFunctionReady(envId, functionName, loading, timeoutMinutes = 5) {
231
+ const scfService = await (0, function_2.getFunctionService)(envId);
232
+ const timeoutMs = timeoutMinutes * 60 * 1000;
233
+ return new Promise((resolve, reject) => {
234
+ let intervalId = null;
235
+ const timeoutId = setTimeout(() => {
236
+ clearInterval(intervalId);
237
+ reject(new error_1.CloudBaseError((0, i18n_1.t)('[{{functionName}}] 等待函数更新超时,已等待 {{timeoutMinutes}} 分钟', { functionName, timeoutMinutes })));
238
+ }, timeoutMs);
239
+ intervalId = setInterval(async () => {
240
+ try {
241
+ const functionInfo = await scfService.getFunctionDetail(functionName);
242
+ if ((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) === 'Active') {
243
+ clearTimeout(timeoutId);
244
+ clearInterval(intervalId);
245
+ loading.succeed((0, i18n_1.t)('[{{functionName}}] 云函数代码已更新!', { functionName }));
246
+ resolve();
231
247
  }
232
- catch (e) {
233
- loading.stop();
234
- throw e;
248
+ else {
249
+ loading.text = (0, i18n_1.t)('正在更新[{{functionName}}] 云函数代码... 当前状态: {{status}}', { functionName, status: (functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) || (0, i18n_1.t)('未知') });
235
250
  }
236
- return;
237
251
  }
238
- }
239
- throw e;
240
- });
241
- }
242
- waitForFunctionReady(envId, functionName, loading, timeoutMinutes = 5) {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- const scfService = yield (0, function_2.getFunctionService)(envId);
245
- const timeoutMs = timeoutMinutes * 60 * 1000;
246
- return new Promise((resolve, reject) => {
247
- let intervalId = null;
248
- const timeoutId = setTimeout(() => {
249
- clearInterval(intervalId);
250
- reject(new error_1.CloudBaseError((0, i18n_1.t)('[{{functionName}}] 等待函数更新超时,已等待 {{timeoutMinutes}} 分钟', { functionName, timeoutMinutes })));
251
- }, timeoutMs);
252
- intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
253
- try {
254
- const functionInfo = yield scfService.getFunctionDetail(functionName);
255
- if ((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) === 'Active') {
256
- clearTimeout(timeoutId);
257
- clearInterval(intervalId);
258
- loading.succeed((0, i18n_1.t)('[{{functionName}}] 云函数代码已更新!', { functionName }));
259
- resolve();
260
- }
261
- else {
262
- loading.text = (0, i18n_1.t)('正在更新[{{functionName}}] 云函数代码... 当前状态: {{status}}', { functionName, status: (functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) || (0, i18n_1.t)('未知') });
263
- }
264
- }
265
- catch (error) {
266
- loading.text = (0, i18n_1.t)('获取[{{functionName}}] 云函数状态失败,重试中...', { functionName });
267
- }
268
- }), 2000);
269
- });
252
+ catch (error) {
253
+ loading.text = (0, i18n_1.t)('获取[{{functionName}}] 云函数状态失败,重试中...', { functionName });
254
+ }
255
+ }, 2000);
270
256
  });
271
257
  }
272
- printSuccessTips(envId, log) {
273
- return __awaiter(this, void 0, void 0, function* () {
274
- let url = `${utils_1.EUrl.TcbConsole}/scf?envId=${envId}`;
275
- const region = yield (0, toolbox_1.getRegion)();
276
- url += `&rid=${regionIdMap[region]}`;
277
- const link = (0, utils_1.genClickableLink)(url);
278
- log.breakLine();
279
- log.info((0, i18n_1.t)('控制台查看函数详情或创建HTTP 访问服务链接 🔗:{{link}}', { link }));
280
- log.info((0, i18n_1.t)('使用 {{command}} 命令查看已部署云函数', { command: (0, utils_1.highlightCommand)('cloudbase functions:list') }));
281
- });
258
+ async printSuccessTips(envId, log) {
259
+ let url = `${utils_1.EUrl.TcbConsole}/scf?envId=${envId}`;
260
+ const region = await (0, toolbox_1.getRegion)();
261
+ url += `&rid=${regionIdMap[region]}`;
262
+ const link = (0, utils_1.genClickableLink)(url);
263
+ log.breakLine();
264
+ log.info((0, i18n_1.t)('控制台查看函数详情或创建HTTP 访问服务链接 🔗:{{link}}', { link }));
265
+ log.info((0, i18n_1.t)('使用 {{command}} 命令查看已部署云函数', { command: (0, utils_1.highlightCommand)('cloudbase functions:list') }));
282
266
  }
283
- genApiGateway(envId, name) {
267
+ async genApiGateway(envId, name) {
284
268
  var _a, _b;
285
- return __awaiter(this, void 0, void 0, function* () {
286
- const loading = (0, utils_1.loadingFactory)();
287
- const res = yield (0, gateway_1.queryGateway)({
269
+ const loading = (0, utils_1.loadingFactory)();
270
+ const res = await (0, gateway_1.queryGateway)({
271
+ name,
272
+ envId
273
+ });
274
+ if ((res === null || res === void 0 ? void 0 : res.EnableService) === false)
275
+ return;
276
+ loading.start((0, i18n_1.t)('生成云函数HTTP 访问服务中...'));
277
+ let path;
278
+ if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
279
+ path = (_b = res.APISet[0]) === null || _b === void 0 ? void 0 : _b.Path;
280
+ }
281
+ else {
282
+ path = `/${(0, utils_1.random)(12)}`;
283
+ await (0, gateway_1.createGateway)({
284
+ envId,
288
285
  name,
289
- envId
286
+ path
290
287
  });
291
- if ((res === null || res === void 0 ? void 0 : res.EnableService) === false)
292
- return;
293
- loading.start((0, i18n_1.t)('生成云函数HTTP 访问服务中...'));
294
- let path;
295
- if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
296
- path = (_b = res.APISet[0]) === null || _b === void 0 ? void 0 : _b.Path;
297
- }
298
- else {
299
- path = `/${(0, utils_1.random)(12)}`;
300
- yield (0, gateway_1.createGateway)({
301
- envId,
302
- name,
303
- path
304
- });
305
- }
306
- loading.stop();
307
- const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${path}`);
308
- console.log((0, i18n_1.t)('\n云函数HTTP 访问服务链接:{{link}}', { link }));
309
- });
288
+ }
289
+ loading.stop();
290
+ const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${path}`);
291
+ console.log((0, i18n_1.t)('\n云函数HTTP 访问服务链接:{{link}}', { link }));
310
292
  }
311
293
  };
312
294
  __decorate([
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
- return new (P || (P = Promise))(function (resolve, reject) {
17
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
- step((generator = generator.apply(thisArg, _arguments || [])).next());
21
- });
22
- };
23
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -58,32 +49,30 @@ let FunctionDetail = class FunctionDetail extends common_1.Command {
58
49
  desc: (0, i18n_1.t)('获取云函数信息')
59
50
  };
60
51
  }
61
- execute(ctx, params) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- const { envId, options } = ctx;
64
- const { codeSecret } = options;
65
- const name = params === null || params === void 0 ? void 0 : params[0];
66
- if (!name) {
67
- throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
68
- }
69
- const loading = (0, utils_1.loadingFactory)();
70
- loading.start((0, i18n_1.t)('获取函数信息中...'));
71
- const functionService = yield (0, function_1.getFunctionService)(envId);
72
- try {
73
- const data = yield functionService.getFunctionDetail(name, codeSecret);
74
- loading.stop();
75
- this.logDetail(data, name);
76
- }
77
- catch (e) {
78
- if (e.code === 'ResourceNotFound.FunctionName') {
79
- throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 函数不存在', { name }));
80
- }
81
- throw e;
82
- }
83
- finally {
84
- loading.stop();
52
+ async execute(ctx, params) {
53
+ const { envId, options } = ctx;
54
+ const { codeSecret } = options;
55
+ const name = params === null || params === void 0 ? void 0 : params[0];
56
+ if (!name) {
57
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
58
+ }
59
+ const loading = (0, utils_1.loadingFactory)();
60
+ loading.start((0, i18n_1.t)('获取函数信息中...'));
61
+ const functionService = await (0, function_1.getFunctionService)(envId);
62
+ try {
63
+ const data = await functionService.getFunctionDetail(name, codeSecret);
64
+ loading.stop();
65
+ this.logDetail(data, name);
66
+ }
67
+ catch (e) {
68
+ if (e.code === 'ResourceNotFound.FunctionName') {
69
+ throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 函数不存在', { name }));
85
70
  }
86
- });
71
+ throw e;
72
+ }
73
+ finally {
74
+ loading.stop();
75
+ }
87
76
  }
88
77
  logDetail(info, name, log) {
89
78
  const ResMap = {