@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
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.PackageStandalonegateway = void 0;
25
16
  const common_1 = require("../../common");
@@ -32,7 +23,9 @@ const utils_1 = require("../../../utils");
32
23
  const i18n_1 = require("../../../i18n");
33
24
  let PackageStandalonegateway = class PackageStandalonegateway extends common_1.Command {
34
25
  get options() {
35
- return Object.assign(Object.assign({}, (0, common_2.standalonegatewayCommonOptions)('package <operation>')), { options: [
26
+ return {
27
+ ...(0, common_2.standalonegatewayCommonOptions)('package <operation>'),
28
+ options: [
36
29
  {
37
30
  flags: '-e, --envId <envId>',
38
31
  desc: (0, i18n_1.t)('环境 Id')
@@ -41,35 +34,35 @@ let PackageStandalonegateway = class PackageStandalonegateway extends common_1.C
41
34
  flags: '-p, --packageVersion <packageVersion>',
42
35
  desc: (0, i18n_1.t)('套餐版本')
43
36
  }
44
- ], desc: (0, i18n_1.t)('套餐操作') });
37
+ ],
38
+ desc: (0, i18n_1.t)('套餐操作')
39
+ };
45
40
  }
46
- execute(envId, params, options) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const operation = params === null || params === void 0 ? void 0 : params[0];
49
- if (!operation || ['list'].indexOf(operation) === -1) {
50
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入具体操作'));
51
- }
52
- switch (operation) {
53
- case 'list':
54
- {
55
- let { appId, packageVersion = '' } = options;
56
- appId = String(appId);
57
- packageVersion = String(packageVersion);
58
- const loading = (0, toolbox_1.loadingFactory)();
59
- loading.start((0, i18n_1.t)('数据加载中...'));
60
- const data = yield (0, run_1.listPackageStandalonegateway)({
61
- envId,
62
- packageVersion
63
- });
64
- loading.stop();
65
- const head = [(0, i18n_1.t)('CPU'), (0, i18n_1.t)('内存'), (0, i18n_1.t)('版本')];
66
- (0, utils_1.printHorizontalTable)(head, data);
67
- }
68
- break;
69
- default:
70
- break;
71
- }
72
- });
41
+ async execute(envId, params, options) {
42
+ const operation = params === null || params === void 0 ? void 0 : params[0];
43
+ if (!operation || ['list'].indexOf(operation) === -1) {
44
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入具体操作'));
45
+ }
46
+ switch (operation) {
47
+ case 'list':
48
+ {
49
+ let { appId, packageVersion = '' } = options;
50
+ appId = String(appId);
51
+ packageVersion = String(packageVersion);
52
+ const loading = (0, toolbox_1.loadingFactory)();
53
+ loading.start((0, i18n_1.t)('数据加载中...'));
54
+ const data = await (0, run_1.listPackageStandalonegateway)({
55
+ envId,
56
+ packageVersion
57
+ });
58
+ loading.stop();
59
+ const head = [(0, i18n_1.t)('CPU'), (0, i18n_1.t)('内存'), (0, i18n_1.t)('版本')];
60
+ (0, utils_1.printHorizontalTable)(head, data);
61
+ }
62
+ break;
63
+ default:
64
+ break;
65
+ }
73
66
  }
74
67
  };
75
68
  __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
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.TurnStandalonegateway = void 0;
25
16
  const common_1 = require("../../common");
@@ -31,7 +22,9 @@ const error_1 = require("../../../error");
31
22
  const i18n_1 = require("../../../i18n");
32
23
  let TurnStandalonegateway = class TurnStandalonegateway extends common_1.Command {
33
24
  get options() {
34
- return Object.assign(Object.assign({}, (0, common_2.standalonegatewayCommonOptions)('turn <status>')), { options: [
25
+ return {
26
+ ...(0, common_2.standalonegatewayCommonOptions)('turn <status>'),
27
+ options: [
35
28
  {
36
29
  flags: '-e, --envId <envId>',
37
30
  desc: (0, i18n_1.t)('环境 Id')
@@ -44,32 +37,32 @@ let TurnStandalonegateway = class TurnStandalonegateway extends common_1.Command
44
37
  flags: '-sL, --serviceList <serviceList...>',
45
38
  desc: (0, i18n_1.t)('云托管服务列表')
46
39
  }
47
- ], desc: (0, i18n_1.t)('启停小租户网关') });
40
+ ],
41
+ desc: (0, i18n_1.t)('启停小租户网关')
42
+ };
48
43
  }
49
- execute(envId, params, options) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const status = params === null || params === void 0 ? void 0 : params[0];
52
- if (!status || ['on', 'off'].indexOf(status) === -1) {
53
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入启停状态'));
54
- }
55
- let { gatewayName = '', serviceList = [] } = options;
56
- gatewayName = String(gatewayName);
57
- if (gatewayName === '') {
58
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入网关名'));
59
- }
60
- if (serviceList.length === 0) {
61
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入云托管服务列表'));
62
- }
63
- const loading = (0, toolbox_1.loadingFactory)();
64
- loading.start((0, i18n_1.t)('数据加载中...'));
65
- yield (status === 'on' ? run_1.turnOnStandalonegateway : run_1.turnOffStandalonegateway)({
66
- envId,
67
- gatewayName,
68
- serviceList
69
- });
70
- loading.stop();
71
- console.log((0, i18n_1.t)('操作执行成功'));
44
+ async execute(envId, params, options) {
45
+ const status = params === null || params === void 0 ? void 0 : params[0];
46
+ if (!status || ['on', 'off'].indexOf(status) === -1) {
47
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入启停状态'));
48
+ }
49
+ let { gatewayName = '', serviceList = [] } = options;
50
+ gatewayName = String(gatewayName);
51
+ if (gatewayName === '') {
52
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入网关名'));
53
+ }
54
+ if (serviceList.length === 0) {
55
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入云托管服务列表'));
56
+ }
57
+ const loading = (0, toolbox_1.loadingFactory)();
58
+ loading.start((0, i18n_1.t)('数据加载中...'));
59
+ await (status === 'on' ? run_1.turnOnStandalonegateway : run_1.turnOffStandalonegateway)({
60
+ envId,
61
+ gatewayName,
62
+ serviceList
72
63
  });
64
+ loading.stop();
65
+ console.log((0, i18n_1.t)('操作执行成功'));
73
66
  }
74
67
  };
75
68
  __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
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.CreateVersion = void 0;
25
16
  const fs_1 = require("fs");
@@ -47,7 +38,9 @@ const memMap = {
47
38
  };
48
39
  let CreateVersion = class CreateVersion extends common_1.Command {
49
40
  get options() {
50
- return Object.assign(Object.assign({}, (0, common_2.versionCommonOptions)('create')), { options: [
41
+ return {
42
+ ...(0, common_2.versionCommonOptions)('create'),
43
+ options: [
51
44
  {
52
45
  flags: '-e, --envId <envId>',
53
46
  desc: (0, i18n_1.t)('环境 Id')
@@ -112,207 +105,207 @@ let CreateVersion = class CreateVersion extends common_1.Command {
112
105
  flags: '--env <env>',
113
106
  desc: (0, i18n_1.t)('环境变量,格式为xx=a&yy=b,默认为空')
114
107
  }
115
- ], desc: (0, i18n_1.t)('创建云开发环境下云托管服务的版本') });
108
+ ],
109
+ desc: (0, i18n_1.t)('创建云开发环境下云托管服务的版本')
110
+ };
116
111
  }
117
- execute(envId, options) {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- let envCheckType = yield (0, utils_1.checkTcbrEnv)(options.envId, false);
120
- if (envCheckType !== 0) {
121
- (0, utils_1.logEnvCheck)(envId, envCheckType);
122
- return;
123
- }
124
- let { serviceName = '', path: _path = '', repo: _repo = '', image: _image = '', port: _port = '80', flow: _flow = '0', remark: _remark = '', cpu: _cpu = '0.5', mem: _mem = '1', copy: _copy = '0~50', policy: _policy = 'cpu|60', dockerfile: _dockerfile = 'Dockerfile', log: _log = 'stdout', delay: _delay = '2', env: _env = '' } = options;
125
- if (!serviceName) {
126
- throw new error_1.CloudBaseError((0, i18n_1.t)('必须输入 serviceName'));
127
- }
128
- let path;
129
- let repositoryType;
130
- let branch;
131
- let codeDetail;
132
- let imageInfo;
133
- let containerPort;
134
- let flowRatio;
135
- let versionRemark;
136
- let cpu;
137
- let mem;
138
- let minNum;
139
- let maxNum;
140
- let policyType;
141
- let policyThreshold;
142
- let customLogs = 'stdout';
143
- let dockerfilePath = 'Dockerfile';
144
- let initialDelaySeconds = 2;
145
- let envParams = '{}';
146
- const uid = (0, utils_1.random)(4);
147
- const loading = (0, utils_1.loadingFactory)();
148
- if (_path) {
149
- path = _path;
150
- if ((0, fs_1.statSync)(path).isDirectory()) {
151
- loading.start((0, i18n_1.t)('正在压缩中'));
152
- yield (0, toolbox_1.zipDir)(path, `./code${uid}.zip`);
153
- loading.succeed((0, i18n_1.t)('压缩完成'));
154
- path = `./code${uid}.zip`;
155
- }
156
- }
157
- else if (_repo) {
158
- const repo = _repo.split('|');
159
- repositoryType = repo[0];
160
- codeDetail.Name.FullName = repo[1];
161
- codeDetail.Name.Name = repo[1].split('/')[1];
162
- branch = repo[2];
163
- }
164
- else if (_image) {
165
- imageInfo = {
166
- ImageUrl: _image
167
- };
168
- }
169
- else {
170
- throw new error_1.CloudBaseError((0, i18n_1.t)('请至少选择一个上传方式'));
171
- }
172
- containerPort = Number(_port);
173
- if (isNaN(containerPort)) {
174
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的端口号'));
175
- }
176
- flowRatio = Number(_flow);
177
- if (![100, 0].includes(flowRatio)) {
178
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的流量策略'));
179
- }
180
- versionRemark = _remark;
181
- cpu = Number(_cpu);
182
- mem = Number(_mem);
183
- if (isNaN(cpu) || isNaN(mem)) {
184
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的cpu和内存规格'));
185
- }
186
- minNum = Number(_copy.split('~')[0]);
187
- maxNum = Number(_copy.split('~')[1]);
188
- if (isNaN(maxNum) || isNaN(minNum)) {
189
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的副本个数'));
190
- }
191
- policyType = _policy.split('|')[0];
192
- policyThreshold = Number(_policy.split('|')[1]);
193
- if (!['cpu', 'mem'].includes(policyType) || isNaN(policyThreshold)) {
194
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的扩缩容条件'));
112
+ async execute(envId, options) {
113
+ let envCheckType = await (0, utils_1.checkTcbrEnv)(options.envId, false);
114
+ if (envCheckType !== 0) {
115
+ (0, utils_1.logEnvCheck)(envId, envCheckType);
116
+ return;
117
+ }
118
+ let { serviceName = '', path: _path = '', repo: _repo = '', image: _image = '', port: _port = '80', flow: _flow = '0', remark: _remark = '', cpu: _cpu = '0.5', mem: _mem = '1', copy: _copy = '0~50', policy: _policy = 'cpu|60', dockerfile: _dockerfile = 'Dockerfile', log: _log = 'stdout', delay: _delay = '2', env: _env = '' } = options;
119
+ if (!serviceName) {
120
+ throw new error_1.CloudBaseError((0, i18n_1.t)('必须输入 serviceName'));
121
+ }
122
+ let path;
123
+ let repositoryType;
124
+ let branch;
125
+ let codeDetail;
126
+ let imageInfo;
127
+ let containerPort;
128
+ let flowRatio;
129
+ let versionRemark;
130
+ let cpu;
131
+ let mem;
132
+ let minNum;
133
+ let maxNum;
134
+ let policyType;
135
+ let policyThreshold;
136
+ let customLogs = 'stdout';
137
+ let dockerfilePath = 'Dockerfile';
138
+ let initialDelaySeconds = 2;
139
+ let envParams = '{}';
140
+ const uid = (0, utils_1.random)(4);
141
+ const loading = (0, utils_1.loadingFactory)();
142
+ if (_path) {
143
+ path = _path;
144
+ if ((0, fs_1.statSync)(path).isDirectory()) {
145
+ loading.start((0, i18n_1.t)('正在压缩中'));
146
+ await (0, toolbox_1.zipDir)(path, `./code${uid}.zip`);
147
+ loading.succeed((0, i18n_1.t)('压缩完成'));
148
+ path = `./code${uid}.zip`;
195
149
  }
196
- dockerfilePath = _dockerfile;
197
- customLogs = _log;
198
- initialDelaySeconds = Number(_delay);
199
- if (isNaN(initialDelaySeconds)) {
200
- throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的延迟时间'));
201
- }
202
- let _envParams = {};
203
- _env.split('&').forEach((item) => {
204
- _envParams[item.split('=')[0]] = item.split('=')[1];
150
+ }
151
+ else if (_repo) {
152
+ const repo = _repo.split('|');
153
+ repositoryType = repo[0];
154
+ codeDetail.Name.FullName = repo[1];
155
+ codeDetail.Name.Name = repo[1].split('/')[1];
156
+ branch = repo[2];
157
+ }
158
+ else if (_image) {
159
+ imageInfo = {
160
+ ImageUrl: _image
161
+ };
162
+ }
163
+ else {
164
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请至少选择一个上传方式'));
165
+ }
166
+ containerPort = Number(_port);
167
+ if (isNaN(containerPort)) {
168
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的端口号'));
169
+ }
170
+ flowRatio = Number(_flow);
171
+ if (![100, 0].includes(flowRatio)) {
172
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的流量策略'));
173
+ }
174
+ versionRemark = _remark;
175
+ cpu = Number(_cpu);
176
+ mem = Number(_mem);
177
+ if (isNaN(cpu) || isNaN(mem)) {
178
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的cpu和内存规格'));
179
+ }
180
+ minNum = Number(_copy.split('~')[0]);
181
+ maxNum = Number(_copy.split('~')[1]);
182
+ if (isNaN(maxNum) || isNaN(minNum)) {
183
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的副本个数'));
184
+ }
185
+ policyType = _policy.split('|')[0];
186
+ policyThreshold = Number(_policy.split('|')[1]);
187
+ if (!['cpu', 'mem'].includes(policyType) || isNaN(policyThreshold)) {
188
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的扩缩容条件'));
189
+ }
190
+ dockerfilePath = _dockerfile;
191
+ customLogs = _log;
192
+ initialDelaySeconds = Number(_delay);
193
+ if (isNaN(initialDelaySeconds)) {
194
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请输入合法的延迟时间'));
195
+ }
196
+ let _envParams = {};
197
+ _env.split('&').forEach((item) => {
198
+ _envParams[item.split('=')[0]] = item.split('=')[1];
199
+ });
200
+ envParams = JSON.stringify(_envParams);
201
+ loading.start((0, i18n_1.t)('加载中...'));
202
+ let res = '';
203
+ let runId = '';
204
+ if (_path) {
205
+ loading.start((0, i18n_1.t)('正在上传中'));
206
+ let { PackageName, PackageVersion, UploadHeaders, UploadUrl } = await (0, run_1.createBuild)({
207
+ envId,
208
+ serviceName
205
209
  });
206
- envParams = JSON.stringify(_envParams);
207
- loading.start((0, i18n_1.t)('加载中...'));
208
- let res = '';
209
- let runId = '';
210
- if (_path) {
211
- loading.start((0, i18n_1.t)('正在上传中'));
212
- let { PackageName, PackageVersion, UploadHeaders, UploadUrl } = yield (0, run_1.createBuild)({
213
- envId,
214
- serviceName
215
- });
216
- yield (0, run_1.uploadZip)(path, UploadUrl, UploadHeaders[0]);
217
- loading.succeed((0, i18n_1.t)('上传成功'));
218
- if (path === `./code${uid}.zip`) {
219
- loading.start((0, i18n_1.t)('删除本地压缩包'));
220
- (0, fs_1.unlinkSync)(path);
221
- loading.succeed((0, i18n_1.t)('成功删除本地压缩包'));
222
- }
223
- let response = yield (0, run_1.createVersion)({
224
- envId,
225
- serverName: serviceName,
226
- containerPort,
227
- uploadType: 'package',
228
- packageName: PackageName,
229
- packageVersion: PackageVersion,
230
- flowRatio,
231
- versionRemark,
232
- enableUnion: true,
233
- cpu,
234
- mem,
235
- minNum,
236
- maxNum,
237
- policyType,
238
- policyThreshold,
239
- customLogs,
240
- dockerfilePath,
241
- envParams,
242
- initialDelaySeconds
243
- });
244
- res = response.Result;
245
- runId = response.RunId;
210
+ await (0, run_1.uploadZip)(path, UploadUrl, UploadHeaders[0]);
211
+ loading.succeed((0, i18n_1.t)('上传成功'));
212
+ if (path === `./code${uid}.zip`) {
213
+ loading.start((0, i18n_1.t)('删除本地压缩包'));
214
+ (0, fs_1.unlinkSync)(path);
215
+ loading.succeed((0, i18n_1.t)('成功删除本地压缩包'));
246
216
  }
247
- else if (_image) {
248
- let response = yield (0, run_1.createVersion)({
249
- envId,
250
- serverName: serviceName,
251
- containerPort,
252
- uploadType: 'image',
253
- imageInfo,
254
- flowRatio,
255
- versionRemark,
256
- enableUnion: true,
257
- cpu,
258
- mem,
259
- minNum,
260
- maxNum,
261
- policyType,
262
- policyThreshold,
263
- customLogs,
264
- envParams,
265
- initialDelaySeconds
266
- });
267
- res = response.Result;
268
- runId = response.RunId;
269
- }
270
- else {
271
- let response = yield (0, run_1.createVersion)({
272
- envId,
273
- serverName: serviceName,
274
- containerPort,
275
- uploadType: 'repository',
276
- repositoryType,
277
- branch,
278
- codeDetail,
279
- flowRatio,
280
- versionRemark,
281
- enableUnion: true,
282
- cpu,
283
- mem,
284
- minNum,
285
- maxNum,
286
- policyType,
287
- policyThreshold,
288
- customLogs,
289
- dockerfilePath,
290
- envParams,
291
- initialDelaySeconds
292
- });
293
- res = response.Result;
294
- runId = response.RunId;
217
+ let response = await (0, run_1.createVersion)({
218
+ envId,
219
+ serverName: serviceName,
220
+ containerPort,
221
+ uploadType: 'package',
222
+ packageName: PackageName,
223
+ packageVersion: PackageVersion,
224
+ flowRatio,
225
+ versionRemark,
226
+ enableUnion: true,
227
+ cpu,
228
+ mem,
229
+ minNum,
230
+ maxNum,
231
+ policyType,
232
+ policyThreshold,
233
+ customLogs,
234
+ dockerfilePath,
235
+ envParams,
236
+ initialDelaySeconds
237
+ });
238
+ res = response.Result;
239
+ runId = response.RunId;
240
+ }
241
+ else if (_image) {
242
+ let response = await (0, run_1.createVersion)({
243
+ envId,
244
+ serverName: serviceName,
245
+ containerPort,
246
+ uploadType: 'image',
247
+ imageInfo,
248
+ flowRatio,
249
+ versionRemark,
250
+ enableUnion: true,
251
+ cpu,
252
+ mem,
253
+ minNum,
254
+ maxNum,
255
+ policyType,
256
+ policyThreshold,
257
+ customLogs,
258
+ envParams,
259
+ initialDelaySeconds
260
+ });
261
+ res = response.Result;
262
+ runId = response.RunId;
263
+ }
264
+ else {
265
+ let response = await (0, run_1.createVersion)({
266
+ envId,
267
+ serverName: serviceName,
268
+ containerPort,
269
+ uploadType: 'repository',
270
+ repositoryType,
271
+ branch,
272
+ codeDetail,
273
+ flowRatio,
274
+ versionRemark,
275
+ enableUnion: true,
276
+ cpu,
277
+ mem,
278
+ minNum,
279
+ maxNum,
280
+ policyType,
281
+ policyThreshold,
282
+ customLogs,
283
+ dockerfilePath,
284
+ envParams,
285
+ initialDelaySeconds
286
+ });
287
+ res = response.Result;
288
+ runId = response.RunId;
289
+ }
290
+ if (res !== 'succ')
291
+ throw new error_1.CloudBaseError((0, i18n_1.t)('提交构建任务失败'));
292
+ loading.start((0, i18n_1.t)('正在部署中'));
293
+ while (true) {
294
+ let { Percent, Status } = await (0, run_1.basicOperate)({ envId, runId });
295
+ if (Status === 'build_fail') {
296
+ let logs = await (0, run_1.logCreate)({ envId, runId });
297
+ (0, fs_1.writeFileSync)(`./log${runId}`, logs.reduce((res, item) => res + item + '\n', ''));
298
+ throw new error_1.CloudBaseError((0, i18n_1.t)('构建失败,日志写入{{file}}中', { file: `./log${runId}` }));
295
299
  }
296
- if (res !== 'succ')
297
- throw new error_1.CloudBaseError((0, i18n_1.t)('提交构建任务失败'));
298
- loading.start((0, i18n_1.t)('正在部署中'));
299
- while (true) {
300
- let { Percent, Status } = yield (0, run_1.basicOperate)({ envId, runId });
301
- if (Status === 'build_fail') {
302
- let logs = yield (0, run_1.logCreate)({ envId, runId });
303
- (0, fs_1.writeFileSync)(`./log${runId}`, logs.reduce((res, item) => res + item + '\n', ''));
304
- throw new error_1.CloudBaseError((0, i18n_1.t)('构建失败,日志写入{{file}}中', { file: `./log${runId}` }));
305
- }
306
- else if (Status !== 'creating') {
307
- break;
308
- }
309
- loading.start((0, i18n_1.t)('目前构建进度{{percent}}%', { percent: Percent }));
310
- yield new Promise((resolve) => {
311
- setTimeout((_) => resolve('again'), 2000);
312
- });
300
+ else if (Status !== 'creating') {
301
+ break;
313
302
  }
314
- loading.succeed((0, i18n_1.t)('构建成功'));
315
- });
303
+ loading.start((0, i18n_1.t)('目前构建进度{{percent}}%', { percent: Percent }));
304
+ await new Promise((resolve) => {
305
+ setTimeout((_) => resolve('again'), 2000);
306
+ });
307
+ }
308
+ loading.succeed((0, i18n_1.t)('构建成功'));
316
309
  }
317
310
  };
318
311
  __decorate([