@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
  };
@@ -39,7 +30,7 @@ const i18n_1 = require("../../i18n");
39
30
  const nodemon = (() => { try {
40
31
  return require('nodemon');
41
32
  }
42
- catch (_a) {
33
+ catch {
43
34
  return null;
44
35
  } })();
45
36
  const scfService = utils_1.CloudApiService.getInstance('tcb');
@@ -59,39 +50,37 @@ let FunListCommand = class FunListCommand extends common_1.Command {
59
50
  desc: (0, i18n_1.t)('查看函数式托管服务列表')
60
51
  };
61
52
  }
62
- execute(envId, log) {
53
+ async execute(envId, log) {
63
54
  var _a;
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const loading = (0, utils_1.loadingFactory)();
66
- if (!envId) {
67
- envId = yield _selectEnv();
68
- }
69
- else {
70
- log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
71
- }
72
- try {
73
- loading.start((0, i18n_1.t)('获取函数式托管服务列表中…'));
74
- let serverListRes = yield scfService
75
- .request('DescribeCloudBaseRunServers', {
76
- EnvId: envId,
77
- Limit: 100,
78
- Offset: 0
79
- })
80
- .finally(() => loading.stop());
81
- const serverList = (_a = serverListRes.CloudBaseRunServerSet) === null || _a === void 0 ? void 0 : _a.filter((item) => item.Tag === 'function');
82
- const head = [(0, i18n_1.t)('服务名称'), (0, i18n_1.t)('状态'), (0, i18n_1.t)('创建时间'), (0, i18n_1.t)('更新时间')];
83
- const tableData = serverList.map((serverItem) => [
84
- serverItem.ServerName,
85
- serverItem.Status,
86
- serverItem.CreatedTime,
87
- serverItem.UpdatedTime
88
- ]);
89
- (0, utils_1.printHorizontalTable)(head, tableData);
90
- }
91
- catch (e) {
92
- log.error((0, i18n_1.t)('获取函数式托管服务列表失败:{{message}}', { message: e.message }));
93
- }
94
- });
55
+ const loading = (0, utils_1.loadingFactory)();
56
+ if (!envId) {
57
+ envId = await _selectEnv();
58
+ }
59
+ else {
60
+ log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
61
+ }
62
+ try {
63
+ loading.start((0, i18n_1.t)('获取函数式托管服务列表中…'));
64
+ let serverListRes = await scfService
65
+ .request('DescribeCloudBaseRunServers', {
66
+ EnvId: envId,
67
+ Limit: 100,
68
+ Offset: 0
69
+ })
70
+ .finally(() => loading.stop());
71
+ const serverList = (_a = serverListRes.CloudBaseRunServerSet) === null || _a === void 0 ? void 0 : _a.filter((item) => item.Tag === 'function');
72
+ const head = [(0, i18n_1.t)('服务名称'), (0, i18n_1.t)('状态'), (0, i18n_1.t)('创建时间'), (0, i18n_1.t)('更新时间')];
73
+ const tableData = serverList.map((serverItem) => [
74
+ serverItem.ServerName,
75
+ serverItem.Status,
76
+ serverItem.CreatedTime,
77
+ serverItem.UpdatedTime
78
+ ]);
79
+ (0, utils_1.printHorizontalTable)(head, tableData);
80
+ }
81
+ catch (e) {
82
+ log.error((0, i18n_1.t)('获取函数式托管服务列表失败:{{message}}', { message: e.message }));
83
+ }
95
84
  }
96
85
  };
97
86
  __decorate([
@@ -142,142 +131,140 @@ let FunDeployCommand = class FunDeployCommand extends common_1.Command {
142
131
  desc: (0, i18n_1.t)('部署函数式托管代码')
143
132
  };
144
133
  }
145
- execute(envId, log, options) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- let { serviceName, appId, source, includeNodeModules = false } = options;
148
- const target = 'main';
149
- source = path_1.default.resolve(source || process.cwd());
150
- const functionsConfigFile = options.functionsConfigFile || 'cloudbase-functions.json';
151
- let multiFunctionsConfig = null;
152
- if (functionsConfigFile && (yield fs_extra_1.default.exists(path_1.default.resolve(source, functionsConfigFile)))) {
153
- try {
154
- multiFunctionsConfig = (0, functions_framework_1.loadFunctionsConfig)(functionsConfigFile);
155
- }
156
- catch (err) {
157
- log.error((0, i18n_1.t)('多函数定义配置文件 {{functionsConfigFile}} 配置文件有误,请检查', { functionsConfigFile }));
158
- log.error(err);
159
- return;
160
- }
161
- }
162
- if (!envId) {
163
- envId = yield _selectEnv();
164
- }
165
- else {
166
- log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
167
- }
168
- if (!serviceName) {
169
- let pkgName = '';
170
- try {
171
- const pkg = yield fs_extra_1.default.readJSON(path_1.default.join(source, 'package.json'));
172
- pkgName = pkg.name;
173
- }
174
- catch (e) { }
175
- serviceName = yield _inputServiceName(pkgName);
176
- }
177
- if (!appId) {
178
- appId = yield _inputAppId();
134
+ async execute(envId, log, options) {
135
+ let { serviceName, appId, source, includeNodeModules = false } = options;
136
+ const target = 'main';
137
+ source = path_1.default.resolve(source || process.cwd());
138
+ const functionsConfigFile = options.functionsConfigFile || 'cloudbase-functions.json';
139
+ let multiFunctionsConfig = null;
140
+ if (functionsConfigFile && (await fs_extra_1.default.exists(path_1.default.resolve(source, functionsConfigFile)))) {
141
+ try {
142
+ multiFunctionsConfig = (0, functions_framework_1.loadFunctionsConfig)(functionsConfigFile);
179
143
  }
180
- const loading = (0, utils_1.loadingFactory)();
181
- const fetchSvrRes = yield scfService.request('DescribeCloudBaseRunServer', {
182
- EnvId: envId,
183
- ServerName: serviceName,
184
- Limit: 1,
185
- Offset: 0
186
- });
187
- if (fetchSvrRes.ServerName && !_isFunRunService(fetchSvrRes.Tag)) {
188
- log.error((0, i18n_1.t)('{{serviceName}} 服务已存在,但不是一个函数式托管服务,请使用另外的服务名称', { serviceName }));
144
+ catch (err) {
145
+ log.error((0, i18n_1.t)('多函数定义配置文件 {{functionsConfigFile}} 配置文件有误,请检查', { functionsConfigFile }));
146
+ log.error(err);
189
147
  return;
190
148
  }
191
- if (!fetchSvrRes.ServerName) {
192
- try {
193
- loading.start((0, i18n_1.t)('正在创建服务…'));
194
- yield scfService.request('EstablishCloudBaseRunServerWx', {
195
- EnvId: envId,
196
- ServiceName: serviceName,
197
- IsPublic: true,
198
- OpenAccessTypes: ['MINIAPP', 'PUBLIC'],
199
- ServiceBaseConfig: {
200
- PublicAccess: true,
201
- Cpu: 1,
202
- Mem: 2,
203
- MinNum: 0,
204
- MaxNum: 5,
205
- PolicyType: 'cpu',
206
- PolicyThreshold: 60,
207
- CustomLogs: 'stdout',
208
- EnvParams: '',
209
- OperatorRemark: '',
210
- InitialDelaySeconds: 2,
211
- PolicyDetails: [
212
- {
213
- PolicyThreshold: 60,
214
- PolicyType: 'cpu'
215
- }
216
- ],
217
- BuildDir: '',
218
- Dockerfile: 'Dockerfile',
219
- HasDockerfile: true,
220
- InternalAccess: 'open',
221
- Port: 3000,
222
- Tag: 'function'
223
- },
224
- WxBuffer: ''
225
- });
226
- loading.succeed((0, i18n_1.t)('创建服务成功'));
227
- }
228
- catch (e) {
229
- loading.stop();
230
- log.error((0, i18n_1.t)('创建服务失败:{{message}}', { message: e.message }));
231
- return;
232
- }
233
- }
234
- let packageName, packageVersion;
149
+ }
150
+ if (!envId) {
151
+ envId = await _selectEnv();
152
+ }
153
+ else {
154
+ log.info((0, i18n_1.t)('当前环境 Id:{{envId}}', { envId }));
155
+ }
156
+ if (!serviceName) {
157
+ let pkgName = '';
235
158
  try {
236
- loading.start((0, i18n_1.t)('正在上传代码包…'));
237
- const { PackageName, PackageVersion } = yield (0, run_1.packageDeploy)({
238
- envId,
239
- serviceName,
240
- filePath: source,
241
- fileToIgnore: ['logs', 'logs/**/*'].concat(includeNodeModules ? [] : ['node_modules', 'node_modules/**/*'])
242
- });
243
- packageName = PackageName;
244
- packageVersion = PackageVersion;
245
- loading.stop();
246
- }
247
- catch (e) {
248
- loading.stop();
249
- log.error((0, i18n_1.t)('上传代码包失败:{{message}}', { message: e.message }));
250
- return;
159
+ const pkg = await fs_extra_1.default.readJSON(path_1.default.join(source, 'package.json'));
160
+ pkgName = pkg.name;
251
161
  }
162
+ catch (e) { }
163
+ serviceName = await _inputServiceName(pkgName);
164
+ }
165
+ if (!appId) {
166
+ appId = await _inputAppId();
167
+ }
168
+ const loading = (0, utils_1.loadingFactory)();
169
+ const fetchSvrRes = await scfService.request('DescribeCloudBaseRunServer', {
170
+ EnvId: envId,
171
+ ServerName: serviceName,
172
+ Limit: 1,
173
+ Offset: 0
174
+ });
175
+ if (fetchSvrRes.ServerName && !_isFunRunService(fetchSvrRes.Tag)) {
176
+ log.error((0, i18n_1.t)('{{serviceName}} 服务已存在,但不是一个函数式托管服务,请使用另外的服务名称', { serviceName }));
177
+ return;
178
+ }
179
+ if (!fetchSvrRes.ServerName) {
252
180
  try {
253
- loading.start((0, i18n_1.t)('正在创建发布任务…'));
254
- yield scfService.request('SubmitServerRelease', {
181
+ loading.start((0, i18n_1.t)('正在创建服务…'));
182
+ await scfService.request('EstablishCloudBaseRunServerWx', {
255
183
  EnvId: envId,
256
- WxAppId: appId,
257
- ServerName: serviceName,
258
- PackageName: packageName,
259
- PackageVersion: packageVersion,
260
- BuildDir: '.',
261
- DeployType: 'package',
262
- ReleaseType: 'FULL',
263
- HasDockerfile: false,
264
- Dockerfile: '',
265
- Port: 3000,
266
- BuildPacks: {
267
- BaseImage: 'Node.js-LTS',
268
- EntryPoint: 'node index.js',
269
- RepoLanguage: 'Node.js',
270
- UploadFilename: ''
184
+ ServiceName: serviceName,
185
+ IsPublic: true,
186
+ OpenAccessTypes: ['MINIAPP', 'PUBLIC'],
187
+ ServiceBaseConfig: {
188
+ PublicAccess: true,
189
+ Cpu: 1,
190
+ Mem: 2,
191
+ MinNum: 0,
192
+ MaxNum: 5,
193
+ PolicyType: 'cpu',
194
+ PolicyThreshold: 60,
195
+ CustomLogs: 'stdout',
196
+ EnvParams: '',
197
+ OperatorRemark: '',
198
+ InitialDelaySeconds: 2,
199
+ PolicyDetails: [
200
+ {
201
+ PolicyThreshold: 60,
202
+ PolicyType: 'cpu'
203
+ }
204
+ ],
205
+ BuildDir: '',
206
+ Dockerfile: 'Dockerfile',
207
+ HasDockerfile: true,
208
+ InternalAccess: 'open',
209
+ Port: 3000,
210
+ Tag: 'function'
271
211
  },
272
- VersionRemark: ''
212
+ WxBuffer: ''
273
213
  });
274
- loading.succeed((0, i18n_1.t)('发布任务创建成功,请前往 https://cloud.weixin.qq.com/cloudrun/service/{{serviceName}} 查看任务详情', { serviceName }));
214
+ loading.succeed((0, i18n_1.t)('创建服务成功'));
275
215
  }
276
216
  catch (e) {
277
217
  loading.stop();
278
- log.error((0, i18n_1.t)('创建发布任务失败:{{message}}', { message: e.message }));
218
+ log.error((0, i18n_1.t)('创建服务失败:{{message}}', { message: e.message }));
219
+ return;
279
220
  }
280
- });
221
+ }
222
+ let packageName, packageVersion;
223
+ try {
224
+ loading.start((0, i18n_1.t)('正在上传代码包…'));
225
+ const { PackageName, PackageVersion } = await (0, run_1.packageDeploy)({
226
+ envId,
227
+ serviceName,
228
+ filePath: source,
229
+ fileToIgnore: ['logs', 'logs/**/*'].concat(includeNodeModules ? [] : ['node_modules', 'node_modules/**/*'])
230
+ });
231
+ packageName = PackageName;
232
+ packageVersion = PackageVersion;
233
+ loading.stop();
234
+ }
235
+ catch (e) {
236
+ loading.stop();
237
+ log.error((0, i18n_1.t)('上传代码包失败:{{message}}', { message: e.message }));
238
+ return;
239
+ }
240
+ try {
241
+ loading.start((0, i18n_1.t)('正在创建发布任务…'));
242
+ await scfService.request('SubmitServerRelease', {
243
+ EnvId: envId,
244
+ WxAppId: appId,
245
+ ServerName: serviceName,
246
+ PackageName: packageName,
247
+ PackageVersion: packageVersion,
248
+ BuildDir: '.',
249
+ DeployType: 'package',
250
+ ReleaseType: 'FULL',
251
+ HasDockerfile: false,
252
+ Dockerfile: '',
253
+ Port: 3000,
254
+ BuildPacks: {
255
+ BaseImage: 'Node.js-LTS',
256
+ EntryPoint: 'node index.js',
257
+ RepoLanguage: 'Node.js',
258
+ UploadFilename: ''
259
+ },
260
+ VersionRemark: ''
261
+ });
262
+ loading.succeed((0, i18n_1.t)('发布任务创建成功,请前往 https://cloud.weixin.qq.com/cloudrun/service/{{serviceName}} 查看任务详情', { serviceName }));
263
+ }
264
+ catch (e) {
265
+ loading.stop();
266
+ log.error((0, i18n_1.t)('创建发布任务失败:{{message}}', { message: e.message }));
267
+ }
281
268
  }
282
269
  };
283
270
  __decorate([
@@ -328,53 +315,51 @@ let FunRunCommand = class FunRunCommand extends common_1.Command {
328
315
  desc: (0, i18n_1.t)('本地运行函数式托管代码')
329
316
  };
330
317
  }
331
- execute(logger) {
332
- return __awaiter(this, void 0, void 0, function* () {
333
- const args = process.argv.slice(2);
334
- const watchFlag = ['--watch', '-w'];
335
- const defaultIgnoreFiles = ['logs/*.*'];
336
- if (watchFlag.some((flag) => args.includes(flag))) {
337
- const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
338
- if (!nodemon) {
339
- throw new Error((0, i18n_1.t)('缺少开发依赖 nodemon,独立发行版已不内置。请在本地开发环境中安装再使用该命令。'));
340
- }
341
- nodemon({
342
- script: '',
343
- exec: `${process.argv[1]} ${cmd}`,
344
- watchOptions: {
345
- usePolling: true,
346
- ignorePermissionErrors: true,
347
- ignored: defaultIgnoreFiles.join(','),
348
- persistent: true,
349
- interval: 500
350
- }
351
- })
352
- .on('start', () => {
353
- logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
354
- })
355
- .on('quit', (e) => {
356
- logger.info(`Nodemon quit with code ${e}.`);
357
- process.exit(0);
358
- })
359
- .on('restart', (e) => {
360
- var _a, _b;
361
- logger.info(`Server restarted due to changed files: ${(_b = (_a = e === null || e === void 0 ? void 0 : e.matched) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.join(', ')}`);
362
- })
363
- .on('log', (e) => {
364
- logger.info(`[nodemon ${e.type}] ${e.message}`);
365
- })
366
- .on('crash', () => {
367
- logger.error(`Server crashed.`);
368
- process.exit(1);
369
- })
370
- .on('exit', (e) => {
371
- logger.info(`Server exited with code ${e}.`);
372
- });
318
+ async execute(logger) {
319
+ const args = process.argv.slice(2);
320
+ const watchFlag = ['--watch', '-w'];
321
+ const defaultIgnoreFiles = ['logs/*.*'];
322
+ if (watchFlag.some((flag) => args.includes(flag))) {
323
+ const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
324
+ if (!nodemon) {
325
+ throw new Error((0, i18n_1.t)('缺少开发依赖 nodemon,独立发行版已不内置。请在本地开发环境中安装再使用该命令。'));
373
326
  }
374
- else {
375
- (0, functions_framework_1.runCLI)();
376
- }
377
- });
327
+ nodemon({
328
+ script: '',
329
+ exec: `${process.argv[1]} ${cmd}`,
330
+ watchOptions: {
331
+ usePolling: true,
332
+ ignorePermissionErrors: true,
333
+ ignored: defaultIgnoreFiles.join(','),
334
+ persistent: true,
335
+ interval: 500
336
+ }
337
+ })
338
+ .on('start', () => {
339
+ logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
340
+ })
341
+ .on('quit', (e) => {
342
+ logger.info(`Nodemon quit with code ${e}.`);
343
+ process.exit(0);
344
+ })
345
+ .on('restart', (e) => {
346
+ var _a, _b;
347
+ logger.info(`Server restarted due to changed files: ${(_b = (_a = e === null || e === void 0 ? void 0 : e.matched) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.join(', ')}`);
348
+ })
349
+ .on('log', (e) => {
350
+ logger.info(`[nodemon ${e.type}] ${e.message}`);
351
+ })
352
+ .on('crash', () => {
353
+ logger.error(`Server crashed.`);
354
+ process.exit(1);
355
+ })
356
+ .on('exit', (e) => {
357
+ logger.info(`Server exited with code ${e}.`);
358
+ });
359
+ }
360
+ else {
361
+ (0, functions_framework_1.runCLI)();
362
+ }
378
363
  }
379
364
  };
380
365
  __decorate([
@@ -388,42 +373,36 @@ FunRunCommand = __decorate([
388
373
  (0, common_1.ICommand)()
389
374
  ], FunRunCommand);
390
375
  exports.FunRunCommand = FunRunCommand;
391
- function _selectEnv() {
392
- return __awaiter(this, void 0, void 0, function* () {
393
- return (0, utils_2.selectEnv)({ source: [constants_1.EnvSource.MINIAPP] });
394
- });
376
+ async function _selectEnv() {
377
+ return (0, utils_2.selectEnv)({ source: [constants_1.EnvSource.MINIAPP] });
395
378
  }
396
- function _inputServiceName(defaultVal = '') {
397
- return __awaiter(this, void 0, void 0, function* () {
398
- const questions = [
399
- {
400
- type: 'input',
401
- name: 'serviceName',
402
- message: (0, i18n_1.t)('请输入服务名称(只能包含数字、小写字母和-,只能以小写字母开头,最多 20字符)'),
403
- default: defaultVal,
404
- validate: (val) => {
405
- return /^[a-z][a-z0-9-]{0,19}$/.test(val) ? true : (0, i18n_1.t)('请输入正确的服务名称');
406
- }
379
+ async function _inputServiceName(defaultVal = '') {
380
+ const questions = [
381
+ {
382
+ type: 'input',
383
+ name: 'serviceName',
384
+ message: (0, i18n_1.t)('请输入服务名称(只能包含数字、小写字母和-,只能以小写字母开头,最多 20字符)'),
385
+ default: defaultVal,
386
+ validate: (val) => {
387
+ return /^[a-z][a-z0-9-]{0,19}$/.test(val) ? true : (0, i18n_1.t)('请输入正确的服务名称');
407
388
  }
408
- ];
409
- const answers = yield inquirer_1.default.prompt(questions);
410
- return answers['serviceName'];
411
- });
389
+ }
390
+ ];
391
+ const answers = await inquirer_1.default.prompt(questions);
392
+ return answers['serviceName'];
412
393
  }
413
- function _inputAppId(defaultVal = '') {
414
- return __awaiter(this, void 0, void 0, function* () {
415
- const questions = [
416
- {
417
- type: 'input',
418
- name: 'appId',
419
- message: (0, i18n_1.t)('请输入微信 AppID'),
420
- validate: (val) => (val ? true : (0, i18n_1.t)('请输入微信 AppID')),
421
- default: defaultVal
422
- }
423
- ];
424
- const answers = yield inquirer_1.default.prompt(questions);
425
- return answers['appId'];
426
- });
394
+ async function _inputAppId(defaultVal = '') {
395
+ const questions = [
396
+ {
397
+ type: 'input',
398
+ name: 'appId',
399
+ message: (0, i18n_1.t)('请输入微信 AppID'),
400
+ validate: (val) => (val ? true : (0, i18n_1.t)('请输入微信 AppID')),
401
+ default: defaultVal
402
+ }
403
+ ];
404
+ const answers = await inquirer_1.default.prompt(questions);
405
+ return answers['appId'];
427
406
  }
428
407
  function _isFunRunService(tagStr) {
429
408
  if (!tagStr)
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.getFunctionRoutingConfig = void 0;
25
16
  const common_1 = require("../../common");
@@ -46,43 +37,41 @@ let getFunctionRoutingConfig = class getFunctionRoutingConfig extends common_1.C
46
37
  desc: (0, i18n_1.t)('查看函数版本流量配置')
47
38
  };
48
39
  }
49
- execute(ctx, params) {
40
+ async execute(ctx, params) {
50
41
  var _a;
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const name = params === null || params === void 0 ? void 0 : params[0];
53
- const { envId } = ctx;
54
- const loading = (0, utils_1.loadingFactory)();
55
- loading.start((0, i18n_1.t)('查询函数 [{{name}}] 版本流量配置中...', { name }));
56
- const aliasRes = yield (0, function_1.getFunctionAliasConfig)({
57
- envId,
58
- functionName: name,
59
- name: '$DEFAULT'
60
- });
61
- const routingConfig = (_a = aliasRes === null || aliasRes === void 0 ? void 0 : aliasRes.RoutingConfig) === null || _a === void 0 ? void 0 : _a.AddtionVersionMatchs;
62
- let finalConfig = [];
63
- if (routingConfig.length === 1) {
64
- finalConfig.push({
65
- version: routingConfig[0].Version,
66
- value: parseRoutingConfigValue(routingConfig[0].Expression)
67
- });
68
- }
69
- else if (routingConfig.length === 2) {
70
- finalConfig.push({
71
- version: routingConfig[0].Version,
72
- value: parseRoutingConfigValue(routingConfig[0].Expression)
73
- }, {
74
- version: routingConfig[1].Version,
75
- value: 100 - Number(parseRoutingConfigValue(routingConfig[0].Expression))
76
- });
77
- }
78
- loading.stop();
79
- const head = [(0, i18n_1.t)('版本'), (0, i18n_1.t)('流量比例')];
80
- const tableData = finalConfig.map((item) => [
81
- item.version,
82
- item.value
83
- ]);
84
- (0, utils_1.printHorizontalTable)(head, tableData);
42
+ const name = params === null || params === void 0 ? void 0 : params[0];
43
+ const { envId } = ctx;
44
+ const loading = (0, utils_1.loadingFactory)();
45
+ loading.start((0, i18n_1.t)('查询函数 [{{name}}] 版本流量配置中...', { name }));
46
+ const aliasRes = await (0, function_1.getFunctionAliasConfig)({
47
+ envId,
48
+ functionName: name,
49
+ name: '$DEFAULT'
85
50
  });
51
+ const routingConfig = (_a = aliasRes === null || aliasRes === void 0 ? void 0 : aliasRes.RoutingConfig) === null || _a === void 0 ? void 0 : _a.AddtionVersionMatchs;
52
+ let finalConfig = [];
53
+ if (routingConfig.length === 1) {
54
+ finalConfig.push({
55
+ version: routingConfig[0].Version,
56
+ value: parseRoutingConfigValue(routingConfig[0].Expression)
57
+ });
58
+ }
59
+ else if (routingConfig.length === 2) {
60
+ finalConfig.push({
61
+ version: routingConfig[0].Version,
62
+ value: parseRoutingConfigValue(routingConfig[0].Expression)
63
+ }, {
64
+ version: routingConfig[1].Version,
65
+ value: 100 - Number(parseRoutingConfigValue(routingConfig[0].Expression))
66
+ });
67
+ }
68
+ loading.stop();
69
+ const head = [(0, i18n_1.t)('版本'), (0, i18n_1.t)('流量比例')];
70
+ const tableData = finalConfig.map((item) => [
71
+ item.version,
72
+ item.value
73
+ ]);
74
+ (0, utils_1.printHorizontalTable)(head, tableData);
86
75
  }
87
76
  };
88
77
  __decorate([