@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
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -69,33 +60,31 @@ class TemplateManager {
69
60
  this.git = (0, simple_git_1.simpleGit)();
70
61
  this.mcpConfigModifier = new mcp_config_modifier_1.MCPConfigModifier();
71
62
  }
72
- pullTemplate(source, options = {}, log) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const targetPath = options.output || process.cwd();
75
- const { force = false } = options;
76
- yield fs_extra_1.default.ensureDir(targetPath);
77
- const tempDir = path_1.default.join(process.cwd(), '.temp-template-' + Date.now());
78
- try {
79
- if (this.isBuiltinTemplate(source)) {
80
- yield this.downloadBuiltinTemplateToTemp(source, tempDir, log);
81
- }
82
- else if (this.isZipUrl(source)) {
83
- yield this.downloadZipTemplateToTemp(source, tempDir, log);
84
- }
85
- else if (this.isGitUrl(source)) {
86
- const gitInfo = this.parseGitUrl(source);
87
- yield this.downloadGitTemplateToTemp(gitInfo, tempDir, log);
88
- }
89
- else {
90
- throw new error_1.CloudBaseError((0, i18n_1.t)('不支持的模板来源: {{source}}', { source: typeof source === 'string' ? source : JSON.stringify(source) }));
91
- }
92
- yield this.copyFromTempToTarget(tempDir, targetPath, force, log);
93
- log.info((0, i18n_1.t)('✅ 模板拉取完成: {{targetPath}}', { targetPath }));
63
+ async pullTemplate(source, options = {}, log) {
64
+ const targetPath = options.output || process.cwd();
65
+ const { force = false } = options;
66
+ await fs_extra_1.default.ensureDir(targetPath);
67
+ const tempDir = path_1.default.join(process.cwd(), '.temp-template-' + Date.now());
68
+ try {
69
+ if (this.isBuiltinTemplate(source)) {
70
+ await this.downloadBuiltinTemplateToTemp(source, tempDir, log);
94
71
  }
95
- finally {
96
- yield fs_extra_1.default.remove(tempDir);
72
+ else if (this.isZipUrl(source)) {
73
+ await this.downloadZipTemplateToTemp(source, tempDir, log);
97
74
  }
98
- });
75
+ else if (this.isGitUrl(source)) {
76
+ const gitInfo = this.parseGitUrl(source);
77
+ await this.downloadGitTemplateToTemp(gitInfo, tempDir, log);
78
+ }
79
+ else {
80
+ throw new error_1.CloudBaseError((0, i18n_1.t)('不支持的模板来源: {{source}}', { source: typeof source === 'string' ? source : JSON.stringify(source) }));
81
+ }
82
+ await this.copyFromTempToTarget(tempDir, targetPath, force, log);
83
+ log.info((0, i18n_1.t)('✅ 模板拉取完成: {{targetPath}}', { targetPath }));
84
+ }
85
+ finally {
86
+ await fs_extra_1.default.remove(tempDir);
87
+ }
99
88
  }
100
89
  isBuiltinTemplate(source) {
101
90
  return Object.keys(BUILTIN_TEMPLATES).includes(source);
@@ -194,251 +183,235 @@ class TemplateManager {
194
183
  }
195
184
  throw new error_1.CloudBaseError((0, i18n_1.t)('不支持的 Git 平台: {{platform}}', { platform: gitInfo.platform }));
196
185
  }
197
- cloneWithSubpathOptimized(gitUrl, tempDir, gitInfo, log) {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- try {
200
- yield this.git.clone(gitUrl, tempDir, [
201
- '--depth', '1',
202
- '--single-branch',
203
- '--branch', gitInfo.branch,
204
- '--filter=blob:none'
205
- ]);
206
- const subpathFull = path_1.default.join(tempDir, gitInfo.subpath);
207
- if (!(yield fs_extra_1.default.pathExists(subpathFull))) {
208
- throw new error_1.CloudBaseError((0, i18n_1.t)('子目录不存在: {{subpath}}', { subpath: gitInfo.subpath }));
209
- }
210
- const tempContentDir = path_1.default.join(tempDir, '.temp-content-' + Date.now());
211
- yield fs_extra_1.default.move(subpathFull, tempContentDir);
212
- const tempFiles = yield fs_extra_1.default.readdir(tempDir);
213
- for (const file of tempFiles) {
214
- if (file !== path_1.default.basename(tempContentDir)) {
215
- yield fs_extra_1.default.remove(path_1.default.join(tempDir, file));
216
- }
217
- }
218
- const contentFiles = yield fs_extra_1.default.readdir(tempContentDir);
219
- for (const file of contentFiles) {
220
- yield fs_extra_1.default.move(path_1.default.join(tempContentDir, file), path_1.default.join(tempDir, file));
221
- }
222
- yield fs_extra_1.default.remove(tempContentDir);
223
- }
224
- catch (error) {
225
- throw new error_1.CloudBaseError((0, i18n_1.t)('克隆子目录失败: {{error}}', { error: error.message }), { original: error });
186
+ async cloneWithSubpathOptimized(gitUrl, tempDir, gitInfo, log) {
187
+ try {
188
+ await this.git.clone(gitUrl, tempDir, [
189
+ '--depth', '1',
190
+ '--single-branch',
191
+ '--branch', gitInfo.branch,
192
+ '--filter=blob:none'
193
+ ]);
194
+ const subpathFull = path_1.default.join(tempDir, gitInfo.subpath);
195
+ if (!await fs_extra_1.default.pathExists(subpathFull)) {
196
+ throw new error_1.CloudBaseError((0, i18n_1.t)('子目录不存在: {{subpath}}', { subpath: gitInfo.subpath }));
226
197
  }
227
- });
228
- }
229
- cloneWithSubpath(gitUrl, tempDir, gitInfo, log) {
230
- return __awaiter(this, void 0, void 0, function* () {
231
- try {
232
- yield this.git.clone(gitUrl, tempDir);
233
- const tempGit = (0, simple_git_1.simpleGit)(tempDir);
234
- yield tempGit.checkout(gitInfo.branch);
235
- const subpathFull = path_1.default.join(tempDir, gitInfo.subpath);
236
- if (!(yield fs_extra_1.default.pathExists(subpathFull))) {
237
- throw new error_1.CloudBaseError((0, i18n_1.t)('子目录不存在: {{subpath}}', { subpath: gitInfo.subpath }));
238
- }
239
- const tempContentDir = path_1.default.join(tempDir, '.temp-content-' + Date.now());
240
- yield fs_extra_1.default.move(subpathFull, tempContentDir);
241
- const tempFiles = yield fs_extra_1.default.readdir(tempDir);
242
- for (const file of tempFiles) {
243
- if (file !== path_1.default.basename(tempContentDir)) {
244
- yield fs_extra_1.default.remove(path_1.default.join(tempDir, file));
245
- }
198
+ const tempContentDir = path_1.default.join(tempDir, '.temp-content-' + Date.now());
199
+ await fs_extra_1.default.move(subpathFull, tempContentDir);
200
+ const tempFiles = await fs_extra_1.default.readdir(tempDir);
201
+ for (const file of tempFiles) {
202
+ if (file !== path_1.default.basename(tempContentDir)) {
203
+ await fs_extra_1.default.remove(path_1.default.join(tempDir, file));
246
204
  }
247
- const contentFiles = yield fs_extra_1.default.readdir(tempContentDir);
248
- for (const file of contentFiles) {
249
- yield fs_extra_1.default.move(path_1.default.join(tempContentDir, file), path_1.default.join(tempDir, file));
250
- }
251
- yield fs_extra_1.default.remove(tempContentDir);
252
205
  }
253
- catch (error) {
254
- throw new error_1.CloudBaseError((0, i18n_1.t)('克隆子目录失败: {{error}}', { error: error.message }), { original: error });
206
+ const contentFiles = await fs_extra_1.default.readdir(tempContentDir);
207
+ for (const file of contentFiles) {
208
+ await fs_extra_1.default.move(path_1.default.join(tempContentDir, file), path_1.default.join(tempDir, file));
255
209
  }
256
- });
210
+ await fs_extra_1.default.remove(tempContentDir);
211
+ }
212
+ catch (error) {
213
+ throw new error_1.CloudBaseError((0, i18n_1.t)('克隆子目录失败: {{error}}', { error: error.message }), { original: error });
214
+ }
257
215
  }
258
- downloadBuiltinTemplateToTemp(templateId, tempDir, log) {
259
- return __awaiter(this, void 0, void 0, function* () {
260
- const template = BUILTIN_TEMPLATES[templateId];
261
- if (!template) {
262
- throw new error_1.CloudBaseError((0, i18n_1.t)('未知的内置模板: {{templateId}}', { templateId }));
216
+ async cloneWithSubpath(gitUrl, tempDir, gitInfo, log) {
217
+ try {
218
+ await this.git.clone(gitUrl, tempDir);
219
+ const tempGit = (0, simple_git_1.simpleGit)(tempDir);
220
+ await tempGit.checkout(gitInfo.branch);
221
+ const subpathFull = path_1.default.join(tempDir, gitInfo.subpath);
222
+ if (!await fs_extra_1.default.pathExists(subpathFull)) {
223
+ throw new error_1.CloudBaseError((0, i18n_1.t)('子目录不存在: {{subpath}}', { subpath: gitInfo.subpath }));
263
224
  }
264
- log.info((0, i18n_1.t)('📦 正在下载 {{templateName}} 模板到临时目录...', { templateName: template.name }));
265
- try {
266
- const { downloadAndExtractRemoteZip } = yield Promise.resolve().then(() => __importStar(require('./tools/common')));
267
- yield downloadAndExtractRemoteZip(template.url, tempDir);
268
- log.info((0, i18n_1.t)('✅ {{templateName}} 模板下载完成到临时目录', { templateName: template.name }));
225
+ const tempContentDir = path_1.default.join(tempDir, '.temp-content-' + Date.now());
226
+ await fs_extra_1.default.move(subpathFull, tempContentDir);
227
+ const tempFiles = await fs_extra_1.default.readdir(tempDir);
228
+ for (const file of tempFiles) {
229
+ if (file !== path_1.default.basename(tempContentDir)) {
230
+ await fs_extra_1.default.remove(path_1.default.join(tempDir, file));
231
+ }
269
232
  }
270
- catch (error) {
271
- throw new error_1.CloudBaseError((0, i18n_1.t)('下载内置模板失败: {{error}}', { error: error.message }), { original: error });
233
+ const contentFiles = await fs_extra_1.default.readdir(tempContentDir);
234
+ for (const file of contentFiles) {
235
+ await fs_extra_1.default.move(path_1.default.join(tempContentDir, file), path_1.default.join(tempDir, file));
272
236
  }
273
- });
237
+ await fs_extra_1.default.remove(tempContentDir);
238
+ }
239
+ catch (error) {
240
+ throw new error_1.CloudBaseError((0, i18n_1.t)('克隆子目录失败: {{error}}', { error: error.message }), { original: error });
241
+ }
274
242
  }
275
- downloadZipTemplateToTemp(zipUrl, tempDir, log) {
276
- return __awaiter(this, void 0, void 0, function* () {
277
- log.info((0, i18n_1.t)('📦 正在下载 zip 文件模板到临时目录: {{zipUrl}}', { zipUrl }));
278
- try {
279
- const { downloadAndExtractRemoteZip } = yield Promise.resolve().then(() => __importStar(require('./tools/common')));
280
- yield downloadAndExtractRemoteZip(zipUrl, tempDir);
281
- log.info((0, i18n_1.t)('✅ zip 文件模板下载完成到临时目录'));
243
+ async downloadBuiltinTemplateToTemp(templateId, tempDir, log) {
244
+ const template = BUILTIN_TEMPLATES[templateId];
245
+ if (!template) {
246
+ throw new error_1.CloudBaseError((0, i18n_1.t)('未知的内置模板: {{templateId}}', { templateId }));
247
+ }
248
+ log.info((0, i18n_1.t)('📦 正在下载 {{templateName}} 模板到临时目录...', { templateName: template.name }));
249
+ try {
250
+ const { downloadAndExtractRemoteZip } = await Promise.resolve().then(() => __importStar(require('./tools/common')));
251
+ await downloadAndExtractRemoteZip(template.url, tempDir);
252
+ log.info((0, i18n_1.t)('✅ {{templateName}} 模板下载完成到临时目录', { templateName: template.name }));
253
+ }
254
+ catch (error) {
255
+ throw new error_1.CloudBaseError((0, i18n_1.t)('下载内置模板失败: {{error}}', { error: error.message }), { original: error });
256
+ }
257
+ }
258
+ async downloadZipTemplateToTemp(zipUrl, tempDir, log) {
259
+ log.info((0, i18n_1.t)('📦 正在下载 zip 文件模板到临时目录: {{zipUrl}}', { zipUrl }));
260
+ try {
261
+ const { downloadAndExtractRemoteZip } = await Promise.resolve().then(() => __importStar(require('./tools/common')));
262
+ await downloadAndExtractRemoteZip(zipUrl, tempDir);
263
+ log.info((0, i18n_1.t)('✅ zip 文件模板下载完成到临时目录'));
264
+ }
265
+ catch (error) {
266
+ throw new error_1.CloudBaseError((0, i18n_1.t)('下载 zip 文件模板失败: {{error}}', { error: error.message }), { original: error });
267
+ }
268
+ }
269
+ async downloadGitTemplateToTemp(gitInfo, tempDir, log) {
270
+ const gitUrl = this.buildGitUrl(gitInfo);
271
+ log.info((0, i18n_1.t)('📦 正在从 {{platform}} 下载模板到临时目录...', { platform: gitInfo.platform }));
272
+ try {
273
+ if (gitInfo.subpath) {
274
+ await this.cloneWithSubpathOptimized(gitUrl, tempDir, gitInfo, log);
282
275
  }
283
- catch (error) {
284
- throw new error_1.CloudBaseError((0, i18n_1.t)('下载 zip 文件模板失败: {{error}}', { error: error.message }), { original: error });
276
+ else {
277
+ await this.git.clone(gitUrl, tempDir, ['--depth', '1', '--single-branch', '--branch', gitInfo.branch]);
285
278
  }
286
- });
279
+ log.info((0, i18n_1.t)('✅ Git 模板下载完成到临时目录'));
280
+ }
281
+ catch (error) {
282
+ throw new error_1.CloudBaseError((0, i18n_1.t)('Git 模板下载失败: {{error}}', { error: error.message }), { original: error });
283
+ }
287
284
  }
288
- downloadGitTemplateToTemp(gitInfo, tempDir, log) {
289
- return __awaiter(this, void 0, void 0, function* () {
290
- const gitUrl = this.buildGitUrl(gitInfo);
291
- log.info((0, i18n_1.t)('📦 正在从 {{platform}} 下载模板到临时目录...', { platform: gitInfo.platform }));
292
- try {
293
- if (gitInfo.subpath) {
294
- yield this.cloneWithSubpathOptimized(gitUrl, tempDir, gitInfo, log);
285
+ async copyFromTempToTarget(tempDir, targetPath, force, log) {
286
+ log.info((0, i18n_1.t)('📦 正在从临时目录复制到目标目录 {{targetPath}}...', { targetPath }));
287
+ try {
288
+ if (force) {
289
+ if (await fs_extra_1.default.pathExists(targetPath)) {
290
+ const files = await fs_extra_1.default.readdir(targetPath);
291
+ if (files.length > 0) {
292
+ log.info((0, i18n_1.t)('⚠️ 使用 --force 参数,将覆盖目标目录中的现有文件'));
293
+ }
295
294
  }
296
- else {
297
- yield this.git.clone(gitUrl, tempDir, ['--depth', '1', '--single-branch', '--branch', gitInfo.branch]);
295
+ await this.copyFilesWithOverwrite(tempDir, targetPath, log);
296
+ }
297
+ else {
298
+ if (await fs_extra_1.default.pathExists(targetPath)) {
299
+ const files = await fs_extra_1.default.readdir(targetPath);
300
+ if (files.length > 0) {
301
+ log.info((0, i18n_1.t)('ℹ️ 目标目录不为空,将跳过已存在的文件,只复制新文件'));
302
+ }
298
303
  }
299
- log.info((0, i18n_1.t)('✅ Git 模板下载完成到临时目录'));
304
+ await this.copyFilesSkipExisting(tempDir, targetPath, log);
305
+ }
306
+ log.info((0, i18n_1.t)('✅ 模板复制完成'));
307
+ try {
308
+ log.debug((0, i18n_1.t)('🔧 开始调用 MCP 配置修改器...'));
309
+ await this.mcpConfigModifier.modifyMCPConfigs(targetPath, log);
310
+ log.debug((0, i18n_1.t)('✅ MCP 配置修改器调用完成'));
300
311
  }
301
312
  catch (error) {
302
- throw new error_1.CloudBaseError((0, i18n_1.t)('Git 模板下载失败: {{error}}', { error: error.message }), { original: error });
313
+ log.warn((0, i18n_1.t)('⚠️ MCP 配置修改失败: {{error}}', { error: error.message }));
303
314
  }
304
- });
315
+ }
316
+ catch (error) {
317
+ throw new error_1.CloudBaseError((0, i18n_1.t)('复制模板失败: {{error}}', { error: error.message }), { original: error });
318
+ }
305
319
  }
306
- copyFromTempToTarget(tempDir, targetPath, force, log) {
307
- return __awaiter(this, void 0, void 0, function* () {
308
- log.info((0, i18n_1.t)('📦 正在从临时目录复制到目标目录 {{targetPath}}...', { targetPath }));
320
+ async copyFilesWithOverwrite(sourceDir, targetDir, log) {
321
+ let copiedCount = 0;
322
+ let overwrittenCount = 0;
323
+ const copyFile = async (srcPath, destPath) => {
309
324
  try {
310
- if (force) {
311
- if (yield fs_extra_1.default.pathExists(targetPath)) {
312
- const files = yield fs_extra_1.default.readdir(targetPath);
313
- if (files.length > 0) {
314
- log.info((0, i18n_1.t)('⚠️ 使用 --force 参数,将覆盖目标目录中的现有文件'));
315
- }
325
+ const stat = await fs_extra_1.default.stat(srcPath);
326
+ if (stat.isDirectory()) {
327
+ await fs_extra_1.default.ensureDir(destPath);
328
+ const entries = await fs_extra_1.default.readdir(srcPath, { withFileTypes: true });
329
+ const copyPromises = entries.map(entry => {
330
+ const entrySrcPath = path_1.default.join(srcPath, entry.name);
331
+ const entryDestPath = path_1.default.join(destPath, entry.name);
332
+ return copyFile(entrySrcPath, entryDestPath);
333
+ });
334
+ const chunks = this.chunkArray(copyPromises, 10);
335
+ for (const chunk of chunks) {
336
+ await Promise.all(chunk);
316
337
  }
317
- yield this.copyFilesWithOverwrite(tempDir, targetPath, log);
318
338
  }
319
339
  else {
320
- if (yield fs_extra_1.default.pathExists(targetPath)) {
321
- const files = yield fs_extra_1.default.readdir(targetPath);
322
- if (files.length > 0) {
323
- log.info((0, i18n_1.t)('ℹ️ 目标目录不为空,将跳过已存在的文件,只复制新文件'));
324
- }
340
+ const exists = await fs_extra_1.default.pathExists(destPath);
341
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(destPath));
342
+ await fs_extra_1.default.copy(srcPath, destPath);
343
+ const relativePath = path_1.default.relative(sourceDir, srcPath);
344
+ if (exists) {
345
+ overwrittenCount++;
346
+ }
347
+ else {
348
+ copiedCount++;
325
349
  }
326
- yield this.copyFilesSkipExisting(tempDir, targetPath, log);
327
- }
328
- log.info((0, i18n_1.t)('✅ 模板复制完成'));
329
- try {
330
- log.debug((0, i18n_1.t)('🔧 开始调用 MCP 配置修改器...'));
331
- yield this.mcpConfigModifier.modifyMCPConfigs(targetPath, log);
332
- log.debug((0, i18n_1.t)('✅ MCP 配置修改器调用完成'));
333
- }
334
- catch (error) {
335
- log.warn((0, i18n_1.t)('⚠️ MCP 配置修改失败: {{error}}', { error: error.message }));
336
350
  }
337
351
  }
338
352
  catch (error) {
339
- throw new error_1.CloudBaseError((0, i18n_1.t)('复制模板失败: {{error}}', { error: error.message }), { original: error });
353
+ log.warn((0, i18n_1.t)('⚠️ 复制失败: {{path}} - {{error}}', { path: path_1.default.relative(sourceDir, srcPath), error: error.message }));
340
354
  }
355
+ };
356
+ const entries = await fs_extra_1.default.readdir(sourceDir, { withFileTypes: true });
357
+ const copyPromises = entries.map(entry => {
358
+ const srcPath = path_1.default.join(sourceDir, entry.name);
359
+ const destPath = path_1.default.join(targetDir, entry.name);
360
+ return copyFile(srcPath, destPath);
341
361
  });
362
+ const chunks = this.chunkArray(copyPromises, 5);
363
+ for (const chunk of chunks) {
364
+ await Promise.all(chunk);
365
+ }
366
+ log.info((0, i18n_1.t)('📊 复制统计: {{copiedCount}} 个新文件复制, {{overwrittenCount}} 个文件覆盖', { copiedCount, overwrittenCount }));
342
367
  }
343
- copyFilesWithOverwrite(sourceDir, targetDir, log) {
344
- return __awaiter(this, void 0, void 0, function* () {
345
- let copiedCount = 0;
346
- let overwrittenCount = 0;
347
- const copyFile = (srcPath, destPath) => __awaiter(this, void 0, void 0, function* () {
348
- try {
349
- const stat = yield fs_extra_1.default.stat(srcPath);
350
- if (stat.isDirectory()) {
351
- yield fs_extra_1.default.ensureDir(destPath);
352
- const entries = yield fs_extra_1.default.readdir(srcPath, { withFileTypes: true });
353
- const copyPromises = entries.map(entry => {
354
- const entrySrcPath = path_1.default.join(srcPath, entry.name);
355
- const entryDestPath = path_1.default.join(destPath, entry.name);
356
- return copyFile(entrySrcPath, entryDestPath);
357
- });
358
- const chunks = this.chunkArray(copyPromises, 10);
359
- for (const chunk of chunks) {
360
- yield Promise.all(chunk);
361
- }
362
- }
363
- else {
364
- const exists = yield fs_extra_1.default.pathExists(destPath);
365
- yield fs_extra_1.default.ensureDir(path_1.default.dirname(destPath));
366
- yield fs_extra_1.default.copy(srcPath, destPath);
367
- const relativePath = path_1.default.relative(sourceDir, srcPath);
368
- if (exists) {
369
- overwrittenCount++;
370
- }
371
- else {
372
- copiedCount++;
373
- }
368
+ async copyFilesSkipExisting(sourceDir, targetDir, log) {
369
+ let copiedCount = 0;
370
+ let skippedCount = 0;
371
+ const copyFile = async (srcPath, destPath) => {
372
+ try {
373
+ const stat = await fs_extra_1.default.stat(srcPath);
374
+ if (stat.isDirectory()) {
375
+ await fs_extra_1.default.ensureDir(destPath);
376
+ const entries = await fs_extra_1.default.readdir(srcPath, { withFileTypes: true });
377
+ const copyPromises = entries.map(entry => {
378
+ const entrySrcPath = path_1.default.join(srcPath, entry.name);
379
+ const entryDestPath = path_1.default.join(destPath, entry.name);
380
+ return copyFile(entrySrcPath, entryDestPath);
381
+ });
382
+ const chunks = this.chunkArray(copyPromises, 10);
383
+ for (const chunk of chunks) {
384
+ await Promise.all(chunk);
374
385
  }
375
386
  }
376
- catch (error) {
377
- log.warn((0, i18n_1.t)('⚠️ 复制失败: {{path}} - {{error}}', { path: path_1.default.relative(sourceDir, srcPath), error: error.message }));
378
- }
379
- });
380
- const entries = yield fs_extra_1.default.readdir(sourceDir, { withFileTypes: true });
381
- const copyPromises = entries.map(entry => {
382
- const srcPath = path_1.default.join(sourceDir, entry.name);
383
- const destPath = path_1.default.join(targetDir, entry.name);
384
- return copyFile(srcPath, destPath);
385
- });
386
- const chunks = this.chunkArray(copyPromises, 5);
387
- for (const chunk of chunks) {
388
- yield Promise.all(chunk);
389
- }
390
- log.info((0, i18n_1.t)('📊 复制统计: {{copiedCount}} 个新文件复制, {{overwrittenCount}} 个文件覆盖', { copiedCount, overwrittenCount }));
391
- });
392
- }
393
- copyFilesSkipExisting(sourceDir, targetDir, log) {
394
- return __awaiter(this, void 0, void 0, function* () {
395
- let copiedCount = 0;
396
- let skippedCount = 0;
397
- const copyFile = (srcPath, destPath) => __awaiter(this, void 0, void 0, function* () {
398
- try {
399
- const stat = yield fs_extra_1.default.stat(srcPath);
400
- if (stat.isDirectory()) {
401
- yield fs_extra_1.default.ensureDir(destPath);
402
- const entries = yield fs_extra_1.default.readdir(srcPath, { withFileTypes: true });
403
- const copyPromises = entries.map(entry => {
404
- const entrySrcPath = path_1.default.join(srcPath, entry.name);
405
- const entryDestPath = path_1.default.join(destPath, entry.name);
406
- return copyFile(entrySrcPath, entryDestPath);
407
- });
408
- const chunks = this.chunkArray(copyPromises, 10);
409
- for (const chunk of chunks) {
410
- yield Promise.all(chunk);
411
- }
387
+ else {
388
+ if (!await fs_extra_1.default.pathExists(destPath)) {
389
+ await fs_extra_1.default.ensureDir(path_1.default.dirname(destPath));
390
+ await fs_extra_1.default.copy(srcPath, destPath);
391
+ const relativePath = path_1.default.relative(sourceDir, srcPath);
392
+ copiedCount++;
412
393
  }
413
394
  else {
414
- if (!(yield fs_extra_1.default.pathExists(destPath))) {
415
- yield fs_extra_1.default.ensureDir(path_1.default.dirname(destPath));
416
- yield fs_extra_1.default.copy(srcPath, destPath);
417
- const relativePath = path_1.default.relative(sourceDir, srcPath);
418
- copiedCount++;
419
- }
420
- else {
421
- const relativePath = path_1.default.relative(sourceDir, srcPath);
422
- skippedCount++;
423
- }
395
+ const relativePath = path_1.default.relative(sourceDir, srcPath);
396
+ skippedCount++;
424
397
  }
425
398
  }
426
- catch (error) {
427
- log.warn((0, i18n_1.t)('⚠️ 复制失败: {{path}} - {{error}}', { path: path_1.default.relative(sourceDir, srcPath), error: error.message }));
428
- }
429
- });
430
- const entries = yield fs_extra_1.default.readdir(sourceDir, { withFileTypes: true });
431
- const copyPromises = entries.map(entry => {
432
- const srcPath = path_1.default.join(sourceDir, entry.name);
433
- const destPath = path_1.default.join(targetDir, entry.name);
434
- return copyFile(srcPath, destPath);
435
- });
436
- const chunks = this.chunkArray(copyPromises, 5);
437
- for (const chunk of chunks) {
438
- yield Promise.all(chunk);
439
399
  }
440
- log.info((0, i18n_1.t)('📊 复制统计: {{copiedCount}} 个文件复制完成, {{skippedCount}} 个文件跳过', { copiedCount, skippedCount }));
400
+ catch (error) {
401
+ log.warn((0, i18n_1.t)('⚠️ 复制失败: {{path}} - {{error}}', { path: path_1.default.relative(sourceDir, srcPath), error: error.message }));
402
+ }
403
+ };
404
+ const entries = await fs_extra_1.default.readdir(sourceDir, { withFileTypes: true });
405
+ const copyPromises = entries.map(entry => {
406
+ const srcPath = path_1.default.join(sourceDir, entry.name);
407
+ const destPath = path_1.default.join(targetDir, entry.name);
408
+ return copyFile(srcPath, destPath);
441
409
  });
410
+ const chunks = this.chunkArray(copyPromises, 5);
411
+ for (const chunk of chunks) {
412
+ await Promise.all(chunk);
413
+ }
414
+ log.info((0, i18n_1.t)('📊 复制统计: {{copiedCount}} 个文件复制完成, {{skippedCount}} 个文件跳过', { copiedCount, skippedCount }));
442
415
  }
443
416
  chunkArray(array, chunkSize) {
444
417
  const chunks = [];