@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
  };
@@ -69,274 +60,260 @@ let InitCommand = class InitCommand extends common_1.Command {
69
60
  withoutAuth: true
70
61
  };
71
62
  }
72
- execute(options, log) {
63
+ async execute(options, log) {
73
64
  var _a;
74
- return __awaiter(this, void 0, void 0, function* () {
75
- console.log(chalk_1.default.bold.yellowBright('\n', (0, i18n_1.t)('⚠️ 此命令将被废弃,请使用新的命令 => tcb new <appName> [template]')), '\n');
76
- yield this.checkLogin();
77
- const isInitNow = yield this.checkTcbService();
78
- let envData = [];
79
- if (isInitNow) {
80
- envData = yield (0, utils_1.execWithLoading)(() => {
81
- return new Promise((resolve) => {
82
- const timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
83
- const envs = yield (0, env_1.listEnvs)();
84
- if (envs.length) {
85
- clearInterval(timer);
86
- resolve(envs);
87
- }
88
- }), 2000);
89
- });
90
- }, {
91
- startTip: (0, i18n_1.t)('获取环境列表中')
65
+ console.log(chalk_1.default.bold.yellowBright('\n', (0, i18n_1.t)('⚠️ 此命令将被废弃,请使用新的命令 => tcb new <appName> [template]')), '\n');
66
+ await this.checkLogin();
67
+ const isInitNow = await this.checkTcbService();
68
+ let envData = [];
69
+ if (isInitNow) {
70
+ envData = await (0, utils_1.execWithLoading)(() => {
71
+ return new Promise((resolve) => {
72
+ const timer = setInterval(async () => {
73
+ const envs = await (0, env_1.listEnvs)();
74
+ if (envs.length) {
75
+ clearInterval(timer);
76
+ resolve(envs);
77
+ }
78
+ }, 2000);
92
79
  });
80
+ }, {
81
+ startTip: (0, i18n_1.t)('获取环境列表中')
82
+ });
83
+ }
84
+ else {
85
+ envData = await (0, utils_1.execWithLoading)(() => (0, env_1.listEnvs)(), {
86
+ startTip: (0, i18n_1.t)('获取环境列表中')
87
+ });
88
+ }
89
+ envData = envData || [];
90
+ const envs = envData
91
+ .map((item) => {
92
+ let name = `${item.Alias} - [${item.EnvId}:${item.PackageName || (0, i18n_1.t)('按量计费')}]`;
93
+ if (item.Status !== "NORMAL") {
94
+ name += `(${constant_1.STATUS_TEXT[item.Status]})`;
93
95
  }
94
- else {
95
- envData = yield (0, utils_1.execWithLoading)(() => (0, env_1.listEnvs)(), {
96
- startTip: (0, i18n_1.t)('获取环境列表中')
97
- });
96
+ return {
97
+ name,
98
+ value: item.EnvId
99
+ };
100
+ })
101
+ .sort((prev, next) => prev.value.charCodeAt(0) - next.value.charCodeAt(0));
102
+ const choices = [
103
+ ...envs,
104
+ {
105
+ name: envData.length ? (0, i18n_1.t)('创建新环境') : (0, i18n_1.t)('无可用环境,创建新环境'),
106
+ value: CREATE_ENV
98
107
  }
99
- envData = envData || [];
100
- const envs = envData
101
- .map((item) => {
102
- let name = `${item.Alias} - [${item.EnvId}:${item.PackageName || (0, i18n_1.t)('按量计费')}]`;
103
- if (item.Status !== "NORMAL") {
104
- name += `(${constant_1.STATUS_TEXT[item.Status]})`;
105
- }
106
- return {
107
- name,
108
- value: item.EnvId
109
- };
110
- })
111
- .sort((prev, next) => prev.value.charCodeAt(0) - next.value.charCodeAt(0));
112
- const choices = [
113
- ...envs,
114
- {
115
- name: envData.length ? (0, i18n_1.t)('创建新环境') : (0, i18n_1.t)('无可用环境,创建新环境'),
116
- value: CREATE_ENV
117
- }
118
- ];
119
- let { env } = yield (0, enquirer_1.prompt)({
120
- choices,
121
- type: 'select',
122
- name: 'env',
123
- message: (0, i18n_1.t)('选择关联环境'),
124
- result(choice) {
125
- return this.map(choice)[choice];
126
- }
108
+ ];
109
+ let { env } = await (0, enquirer_1.prompt)({
110
+ choices,
111
+ type: 'select',
112
+ name: 'env',
113
+ message: (0, i18n_1.t)('选择关联环境'),
114
+ result(choice) {
115
+ return this.map(choice)[choice];
116
+ }
117
+ });
118
+ if (env === CREATE_ENV) {
119
+ log.success((0, i18n_1.t)('已打开控制台,请前往控制台创建环境'));
120
+ const { envId } = await (0, toolbox_1.getDataFromWeb)((port) => `${consoleUrl}&port=${port}`, 'getData');
121
+ if (!envId) {
122
+ throw new error_1.CloudBaseError((0, i18n_1.t)('接收环境 Id 信息失败,请重新运行 init 命令!'));
123
+ }
124
+ log.success((0, i18n_1.t)('创建环境成功,环境 Id: {{envId}}', { envId }));
125
+ env = envId;
126
+ }
127
+ await this.checkEnvStatus(env);
128
+ let projectName;
129
+ let projectPath;
130
+ if (!options.withoutTemplate) {
131
+ const templates = await (0, utils_1.execWithLoading)(() => (0, utils_1.fetch)(listUrl), {
132
+ startTip: (0, i18n_1.t)('拉取云开发模板列表中')
127
133
  });
128
- if (env === CREATE_ENV) {
129
- log.success((0, i18n_1.t)('已打开控制台,请前往控制台创建环境'));
130
- const { envId } = yield (0, toolbox_1.getDataFromWeb)((port) => `${consoleUrl}&port=${port}`, 'getData');
131
- if (!envId) {
132
- throw new error_1.CloudBaseError((0, i18n_1.t)('接收环境 Id 信息失败,请重新运行 init 命令!'));
133
- }
134
- log.success((0, i18n_1.t)('创建环境成功,环境 Id: {{envId}}', { envId }));
135
- env = envId;
134
+ let templateName;
135
+ let tempateId;
136
+ if (options.template) {
137
+ tempateId = options.template;
136
138
  }
137
- yield this.checkEnvStatus(env);
138
- let projectName;
139
- let projectPath;
140
- if (!options.withoutTemplate) {
141
- const templates = yield (0, utils_1.execWithLoading)(() => (0, utils_1.fetch)(listUrl), {
142
- startTip: (0, i18n_1.t)('拉取云开发模板列表中')
143
- });
144
- let templateName;
145
- let tempateId;
146
- if (options.template) {
147
- tempateId = options.template;
148
- }
149
- else {
150
- let { selectTemplateName } = yield (0, enquirer_1.prompt)({
151
- type: 'select',
152
- name: 'selectTemplateName',
153
- message: (0, i18n_1.t)('选择云开发模板'),
154
- choices: templates.map((item) => item.name)
155
- });
156
- templateName = selectTemplateName;
157
- }
158
- const selectedTemplate = templateName
159
- ? templates.find((item) => item.name === templateName)
160
- : templates.find((item) => item.path === tempateId);
161
- if (!selectedTemplate) {
162
- log.info((0, i18n_1.t)('模板 `{{templateName}}` 不存在', { templateName: templateName || tempateId }));
163
- return;
164
- }
165
- if (options.project) {
166
- projectName = options.project;
167
- }
168
- else {
169
- const { projectName: promptProjectName } = yield (0, enquirer_1.prompt)({
170
- type: 'input',
171
- name: 'projectName',
172
- message: (0, i18n_1.t)('请输入项目名称'),
173
- initial: selectedTemplate.path
174
- });
175
- projectName = promptProjectName;
176
- }
177
- projectPath = path_1.default.join(process.cwd(), projectName);
178
- if ((0, utils_1.checkFullAccess)(projectPath)) {
179
- const { cover } = yield (0, enquirer_1.prompt)({
180
- type: 'confirm',
181
- name: 'cover',
182
- message: (0, i18n_1.t)('已存在同名文件夹:{{projectName}},是否覆盖?', { projectName }),
183
- initial: false
184
- });
185
- if (!cover) {
186
- throw new error_1.CloudBaseError((0, i18n_1.t)('操作终止!'));
187
- }
188
- else {
189
- fs_extra_1.default.removeSync(projectPath);
190
- }
191
- }
192
- yield (0, utils_1.execWithLoading)(() => __awaiter(this, void 0, void 0, function* () {
193
- yield (0, utils_1.templateDownloadReport)(selectedTemplate.path, selectedTemplate.name);
194
- yield this.extractTemplate(projectPath, selectedTemplate.path, selectedTemplate.url);
195
- }), {
196
- startTip: (0, i18n_1.t)('下载文件中')
139
+ else {
140
+ let { selectTemplateName } = await (0, enquirer_1.prompt)({
141
+ type: 'select',
142
+ name: 'selectTemplateName',
143
+ message: (0, i18n_1.t)('选择云开发模板'),
144
+ choices: templates.map((item) => item.name)
197
145
  });
146
+ templateName = selectTemplateName;
198
147
  }
199
- else {
200
- projectName = '';
201
- projectPath = path_1.default.join(process.cwd(), projectName);
148
+ const selectedTemplate = templateName
149
+ ? templates.find((item) => item.name === templateName)
150
+ : templates.find((item) => item.path === tempateId);
151
+ if (!selectedTemplate) {
152
+ log.info((0, i18n_1.t)('模板 `{{templateName}}` 不存在', { templateName: templateName || tempateId }));
153
+ return;
202
154
  }
203
- let filepath = (_a = (yield (0, toolbox_1.searchConfig)(projectPath))) === null || _a === void 0 ? void 0 : _a.filepath;
204
- if (!filepath) {
205
- fs_1.default.writeFileSync(path_1.default.join(projectPath, 'cloudbaserc.json'), JSON.stringify({
206
- envId: env,
207
- version: '2.0',
208
- $schema: 'https://framework-1258016615.tcloudbaseapp.com/schema/latest.json'
209
- }));
155
+ if (options.project) {
156
+ projectName = options.project;
210
157
  }
211
158
  else {
212
- const configContent = fs_1.default.readFileSync(filepath).toString();
213
- fs_1.default.writeFileSync(filepath, configContent.replace('{{envId}}', env));
159
+ const { projectName: promptProjectName } = await (0, enquirer_1.prompt)({
160
+ type: 'input',
161
+ name: 'projectName',
162
+ message: (0, i18n_1.t)('请输入项目名称'),
163
+ initial: selectedTemplate.path
164
+ });
165
+ projectName = promptProjectName;
214
166
  }
215
- this.initSuccessOutput(projectName);
216
- });
217
- }
218
- checkLogin(log) {
219
- var _a;
220
- return __awaiter(this, void 0, void 0, function* () {
221
- const credential = yield (0, utils_1.checkAndGetCredential)();
222
- if (lodash_1.default.isEmpty(credential)) {
223
- log.info((0, i18n_1.t)('你还没有登录,请在控制台中授权登录'));
224
- const res = yield (0, utils_1.execWithLoading)(() => (0, auth_1.login)(), {
225
- startTip: (0, i18n_1.t)('在浏览器中打开的授权页面进行授权...'),
226
- successTip: (0, i18n_1.t)('授权登录成功!')
167
+ projectPath = path_1.default.join(process.cwd(), projectName);
168
+ if ((0, utils_1.checkFullAccess)(projectPath)) {
169
+ const { cover } = await (0, enquirer_1.prompt)({
170
+ type: 'confirm',
171
+ name: 'cover',
172
+ message: (0, i18n_1.t)('已存在同名文件夹:{{projectName}},是否覆盖?', { projectName }),
173
+ initial: false
227
174
  });
228
- const envId = (_a = res === null || res === void 0 ? void 0 : res.credential) === null || _a === void 0 ? void 0 : _a.envId;
229
- if (envId) {
230
- const env = yield (0, env_1.getEnvInfo)(envId);
231
- if (env.Status === "UNAVAILABLE") {
232
- yield this.checkEnvAvaliable(envId);
233
- }
175
+ if (!cover) {
176
+ throw new error_1.CloudBaseError((0, i18n_1.t)('操作终止!'));
177
+ }
178
+ else {
179
+ fs_extra_1.default.removeSync(projectPath);
234
180
  }
235
181
  }
236
- });
237
- }
238
- checkEnvStatus(envId) {
239
- return __awaiter(this, void 0, void 0, function* () {
240
- const env = yield (0, env_1.getEnvInfo)(envId);
241
- if (env.Status === "UNAVAILABLE") {
242
- yield this.checkEnvAvaliable(envId);
243
- }
244
- else if (env.Status !== "NORMAL") {
245
- throw new error_1.CloudBaseError((0, i18n_1.t)('所有环境状态异常'));
246
- }
247
- });
248
- }
249
- checkEnvAvaliable(envId) {
250
- return __awaiter(this, void 0, void 0, function* () {
251
- let count = 0;
252
- yield (0, utils_1.execWithLoading)((flush) => {
253
- const increase = setInterval(() => {
254
- flush(`${ENV_INIT_TIP} ${++count}S`);
255
- }, 1000);
256
- return new Promise((resolve) => {
257
- const timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
258
- const env = yield (0, env_1.getEnvInfo)(envId);
259
- if (env.Status === "NORMAL") {
260
- clearInterval(timer);
261
- clearInterval(increase);
262
- resolve();
263
- }
264
- }), 3000);
265
- });
182
+ await (0, utils_1.execWithLoading)(async () => {
183
+ await (0, utils_1.templateDownloadReport)(selectedTemplate.path, selectedTemplate.name);
184
+ await this.extractTemplate(projectPath, selectedTemplate.path, selectedTemplate.url);
266
185
  }, {
267
- startTip: ENV_INIT_TIP,
268
- successTip: (0, i18n_1.t)('环境 {{envId}} 初始化成功', { envId })
186
+ startTip: (0, i18n_1.t)('下载文件中')
269
187
  });
270
- });
188
+ }
189
+ else {
190
+ projectName = '';
191
+ projectPath = path_1.default.join(process.cwd(), projectName);
192
+ }
193
+ let filepath = (_a = (await (0, toolbox_1.searchConfig)(projectPath))) === null || _a === void 0 ? void 0 : _a.filepath;
194
+ if (!filepath) {
195
+ fs_1.default.writeFileSync(path_1.default.join(projectPath, 'cloudbaserc.json'), JSON.stringify({
196
+ envId: env,
197
+ version: '2.0',
198
+ $schema: 'https://framework-1258016615.tcloudbaseapp.com/schema/latest.json'
199
+ }));
200
+ }
201
+ else {
202
+ const configContent = fs_1.default.readFileSync(filepath).toString();
203
+ fs_1.default.writeFileSync(filepath, configContent.replace('{{envId}}', env));
204
+ }
205
+ this.initSuccessOutput(projectName);
271
206
  }
272
- checkTcbService(log) {
273
- return __awaiter(this, void 0, void 0, function* () {
274
- const app = yield (0, utils_1.getMangerService)();
275
- let Initialized;
276
- try {
277
- Initialized = (yield app.env.checkTcbService()).Initialized;
278
- }
279
- catch (e) {
280
- if (!(0, toolbox_1.isCamRefused)(e)) {
281
- throw e;
282
- }
283
- }
284
- if (!Initialized) {
285
- const { jump } = yield (0, enquirer_1.prompt)({
286
- type: 'confirm',
287
- name: 'jump',
288
- message: (0, i18n_1.t)('你还没有开通云开发服务,是否跳转到控制台开通云开发服务?(取消将无法继续操作)'),
289
- initial: true
290
- });
291
- if (!jump) {
292
- throw new error_1.CloudBaseError((0, i18n_1.t)('init 操作终止,请开通云开发服务后再进行操作!'));
207
+ async checkLogin(log) {
208
+ var _a;
209
+ const credential = await (0, utils_1.checkAndGetCredential)();
210
+ if (lodash_1.default.isEmpty(credential)) {
211
+ log.info((0, i18n_1.t)('你还没有登录,请在控制台中授权登录'));
212
+ const res = await (0, utils_1.execWithLoading)(() => (0, auth_1.login)(), {
213
+ startTip: (0, i18n_1.t)('在浏览器中打开的授权页面进行授权...'),
214
+ successTip: (0, i18n_1.t)('授权登录成功!')
215
+ });
216
+ const envId = (_a = res === null || res === void 0 ? void 0 : res.credential) === null || _a === void 0 ? void 0 : _a.envId;
217
+ if (envId) {
218
+ const env = await (0, env_1.getEnvInfo)(envId);
219
+ if (env.Status === "UNAVAILABLE") {
220
+ await this.checkEnvAvaliable(envId);
293
221
  }
294
- (0, open_1.default)(consoleUrl);
295
- log.success((0, i18n_1.t)('已打开云开发控制台,请登录并在云开发控制台中开通服务!'));
296
- yield (0, utils_1.execWithLoading)(() => this.waitForServiceEnable(), {
297
- startTip: (0, i18n_1.t)('等待云开发服务开通中'),
298
- successTip: (0, i18n_1.t)('云开发服务开通成功!')
299
- });
300
- return true;
301
222
  }
302
- return false;
303
- });
223
+ }
304
224
  }
305
- waitForServiceEnable() {
306
- return __awaiter(this, void 0, void 0, function* () {
225
+ async checkEnvStatus(envId) {
226
+ const env = await (0, env_1.getEnvInfo)(envId);
227
+ if (env.Status === "UNAVAILABLE") {
228
+ await this.checkEnvAvaliable(envId);
229
+ }
230
+ else if (env.Status !== "NORMAL") {
231
+ throw new error_1.CloudBaseError((0, i18n_1.t)('所有环境状态异常'));
232
+ }
233
+ }
234
+ async checkEnvAvaliable(envId) {
235
+ let count = 0;
236
+ await (0, utils_1.execWithLoading)((flush) => {
237
+ const increase = setInterval(() => {
238
+ flush(`${ENV_INIT_TIP} ${++count}S`);
239
+ }, 1000);
307
240
  return new Promise((resolve) => {
308
- const timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
309
- const app = yield (0, utils_1.getMangerService)();
310
- try {
311
- const { Initialized } = yield app.env.checkTcbService();
312
- if (Initialized) {
313
- clearInterval(timer);
314
- setTimeout(() => {
315
- resolve();
316
- }, 5000);
317
- }
318
- }
319
- catch (e) {
320
- if (!(0, toolbox_1.isCamRefused)(e)) {
321
- throw e;
322
- }
241
+ const timer = setInterval(async () => {
242
+ const env = await (0, env_1.getEnvInfo)(envId);
243
+ if (env.Status === "NORMAL") {
244
+ clearInterval(timer);
245
+ clearInterval(increase);
246
+ resolve();
323
247
  }
324
- }), 3000);
248
+ }, 3000);
325
249
  });
250
+ }, {
251
+ startTip: ENV_INIT_TIP,
252
+ successTip: (0, i18n_1.t)('环境 {{envId}} 初始化成功', { envId })
326
253
  });
327
254
  }
328
- extractTemplate(projectPath, templatePath, remoteUrl) {
329
- return __awaiter(this, void 0, void 0, function* () {
330
- const url = remoteUrl || getTemplateAddress(templatePath);
331
- return (0, utils_1.fetchStream)(url).then((res) => __awaiter(this, void 0, void 0, function* () {
332
- if (!res) {
333
- throw new error_1.CloudBaseError((0, i18n_1.t)('请求异常'));
255
+ async checkTcbService(log) {
256
+ const app = await (0, utils_1.getMangerService)();
257
+ let Initialized;
258
+ try {
259
+ Initialized = (await app.env.checkTcbService()).Initialized;
260
+ }
261
+ catch (e) {
262
+ if (!(0, toolbox_1.isCamRefused)(e)) {
263
+ throw e;
264
+ }
265
+ }
266
+ if (!Initialized) {
267
+ const { jump } = await (0, enquirer_1.prompt)({
268
+ type: 'confirm',
269
+ name: 'jump',
270
+ message: (0, i18n_1.t)('你还没有开通云开发服务,是否跳转到控制台开通云开发服务?(取消将无法继续操作)'),
271
+ initial: true
272
+ });
273
+ if (!jump) {
274
+ throw new error_1.CloudBaseError((0, i18n_1.t)('init 操作终止,请开通云开发服务后再进行操作!'));
275
+ }
276
+ (0, open_1.default)(consoleUrl);
277
+ log.success((0, i18n_1.t)('已打开云开发控制台,请登录并在云开发控制台中开通服务!'));
278
+ await (0, utils_1.execWithLoading)(() => this.waitForServiceEnable(), {
279
+ startTip: (0, i18n_1.t)('等待云开发服务开通中'),
280
+ successTip: (0, i18n_1.t)('云开发服务开通成功!')
281
+ });
282
+ return true;
283
+ }
284
+ return false;
285
+ }
286
+ async waitForServiceEnable() {
287
+ return new Promise((resolve) => {
288
+ const timer = setInterval(async () => {
289
+ const app = await (0, utils_1.getMangerService)();
290
+ try {
291
+ const { Initialized } = await app.env.checkTcbService();
292
+ if (Initialized) {
293
+ clearInterval(timer);
294
+ setTimeout(() => {
295
+ resolve();
296
+ }, 5000);
297
+ }
334
298
  }
335
- if (res.status !== 200) {
336
- throw new error_1.CloudBaseError((0, i18n_1.t)('未找到文件'));
299
+ catch (e) {
300
+ if (!(0, toolbox_1.isCamRefused)(e)) {
301
+ throw e;
302
+ }
337
303
  }
338
- yield (0, toolbox_1.unzipStream)(res.body, projectPath);
339
- }));
304
+ }, 3000);
305
+ });
306
+ }
307
+ async extractTemplate(projectPath, templatePath, remoteUrl) {
308
+ const url = remoteUrl || getTemplateAddress(templatePath);
309
+ return (0, utils_1.fetchStream)(url).then(async (res) => {
310
+ if (!res) {
311
+ throw new error_1.CloudBaseError((0, i18n_1.t)('请求异常'));
312
+ }
313
+ if (res.status !== 200) {
314
+ throw new error_1.CloudBaseError((0, i18n_1.t)('未找到文件'));
315
+ }
316
+ await (0, toolbox_1.unzipStream)(res.body, projectPath);
340
317
  });
341
318
  }
342
319
  initSuccessOutput(projectName, log) {
@@ -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
  };
@@ -53,47 +44,45 @@ let NewCommand = class NewCommand extends common_1.Command {
53
44
  withoutAuth: true
54
45
  };
55
46
  }
56
- execute(ctx, log) {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- const { params, options, envId } = ctx;
59
- const { clone } = options;
60
- let appName = params === null || params === void 0 ? void 0 : params[0];
61
- const templateUri = params === null || params === void 0 ? void 0 : params[1];
62
- yield (0, auth_1.checkLogin)();
63
- let region = yield (0, toolbox_1.getRegion)(true);
64
- if (!region) {
65
- region = yield (0, utils_1.getSelectRegion)();
66
- }
67
- let env = envId;
68
- if (!env) {
69
- env = yield (0, utils_1.getSelectedEnv)(envId);
70
- }
71
- let projectPath;
72
- if (templateUri && isGitUrl(templateUri)) {
73
- if (clone) {
74
- yield (0, execa_1.default)('git', ['clone', templateUri, appName], {
75
- stdio: 'inherit'
76
- });
77
- }
78
- else {
79
- yield (0, execa_1.default)('git', ['clone', '--depth', 1, templateUri, appName], {
80
- stdio: 'inherit'
81
- });
82
- yield (0, utils_1.delSync)([path_1.default.join(process.cwd(), appName, '.git')]);
83
- }
84
- projectPath = path_1.default.join(process.cwd(), appName);
47
+ async execute(ctx, log) {
48
+ const { params, options, envId } = ctx;
49
+ const { clone } = options;
50
+ let appName = params === null || params === void 0 ? void 0 : params[0];
51
+ const templateUri = params === null || params === void 0 ? void 0 : params[1];
52
+ await (0, auth_1.checkLogin)();
53
+ let region = await (0, toolbox_1.getRegion)(true);
54
+ if (!region) {
55
+ region = await (0, utils_1.getSelectRegion)();
56
+ }
57
+ let env = envId;
58
+ if (!env) {
59
+ env = await (0, utils_1.getSelectedEnv)(envId);
60
+ }
61
+ let projectPath;
62
+ if (templateUri && isGitUrl(templateUri)) {
63
+ if (clone) {
64
+ await (0, execa_1.default)('git', ['clone', templateUri, appName], {
65
+ stdio: 'inherit'
66
+ });
85
67
  }
86
68
  else {
87
- projectPath = yield (0, utils_1.downloadTemplate)({
88
- appName,
89
- projectPath,
90
- templateUri,
91
- newProject: true
69
+ await (0, execa_1.default)('git', ['clone', '--depth', 1, templateUri, appName], {
70
+ stdio: 'inherit'
92
71
  });
72
+ await (0, utils_1.delSync)([path_1.default.join(process.cwd(), appName, '.git')]);
93
73
  }
94
- yield (0, utils_1.initProjectConfig)(env, region, projectPath);
95
- this.initSuccessOutput(appName);
96
- });
74
+ projectPath = path_1.default.join(process.cwd(), appName);
75
+ }
76
+ else {
77
+ projectPath = await (0, utils_1.downloadTemplate)({
78
+ appName,
79
+ projectPath,
80
+ templateUri,
81
+ newProject: true
82
+ });
83
+ }
84
+ await (0, utils_1.initProjectConfig)(env, region, projectPath);
85
+ this.initSuccessOutput(appName);
97
86
  }
98
87
  initSuccessOutput(appName, log) {
99
88
  log.success(appName ? (0, i18n_1.t)('创建应用 {{appName}} 成功!\n', { appName }) : (0, i18n_1.t)('创建应用成功!'));