@cloudbase/cli 2.6.0-alpha.8 → 2.7.0-alpha.2

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.
@@ -0,0 +1,786 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.IaCState = exports.IaCDestory = exports.IaCApply = exports.IaCDev = exports.IaCBuild = exports.IaCPull = exports.IaCInit = exports.IaCPullRepoConfig = exports.IaCInitRepo = void 0;
28
+ const cals_1 = require("@cloudbase/cals");
29
+ const iac_core_1 = require("@cloudbase/iac-core");
30
+ const type_1 = require("@cloudbase/iac-core/lib/src/type");
31
+ const inquirer_1 = __importDefault(require("inquirer"));
32
+ const lodash_1 = require("lodash");
33
+ const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
34
+ const path_1 = __importDefault(require("path"));
35
+ const decorators_1 = require("../../decorators");
36
+ const utils_1 = require("../../utils");
37
+ const common_1 = require("../common");
38
+ const fs_extra_1 = require("fs-extra");
39
+ inquirer_1.default.registerPrompt('autocomplete', inquirer_autocomplete_prompt_1.default);
40
+ let IaCInitRepo = class IaCInitRepo extends common_1.Command {
41
+ get options() {
42
+ return {
43
+ cmd: 'repo',
44
+ childCmd: 'init',
45
+ options: (0, lodash_1.compact)([
46
+ {
47
+ flags: '--name <name>',
48
+ desc: '仓库名称'
49
+ },
50
+ {
51
+ flags: '--cwd <cwd>',
52
+ desc: '仓库路径'
53
+ },
54
+ {
55
+ flags: '--envId <envId>',
56
+ desc: '环境 ID。如有提供,会自动同步环境配置(如 Git 模式的配置数据)'
57
+ }
58
+ ]),
59
+ desc: '初始化云开发资源仓库项目 - 大仓 Monorepo 模式',
60
+ requiredEnvId: false,
61
+ autoRunLogin: true
62
+ };
63
+ }
64
+ execute(ctx, options, log) {
65
+ return __awaiter(this, void 0, void 0, function* () {
66
+ let { envId, name, cwd = '.' } = options;
67
+ const targetDir = path_1.default.resolve(cwd);
68
+ const params = { name, cwd, envId };
69
+ yield iac_core_1.IAC.init({
70
+ cwd,
71
+ getCredential: () => {
72
+ return getCredential(ctx, options);
73
+ }
74
+ });
75
+ log.info(`【cwd】: ${targetDir}`);
76
+ if (!name) {
77
+ const nameRes = yield inquirer_1.default.prompt({
78
+ type: 'input',
79
+ name: 'name',
80
+ message: '仓库名称(如有提供,将在【cwd】路径创建文件夹;如没提供,则将【cwd】路径初始化为资源仓库)'
81
+ });
82
+ if (nameRes) {
83
+ params.name = nameRes.name;
84
+ }
85
+ }
86
+ if (!envId) {
87
+ params.envId = yield showEnvIdUI({
88
+ required: false,
89
+ message: '环境 ID(如有提供,将自动同步环境配置,不选择则跳过)'
90
+ });
91
+ }
92
+ yield iac_core_1.IAC.tools.initRepo(params, (message) => trackCallback(message, log));
93
+ });
94
+ }
95
+ };
96
+ __decorate([
97
+ (0, decorators_1.InjectParams)(),
98
+ __param(0, (0, decorators_1.CmdContext)()),
99
+ __param(1, (0, decorators_1.ArgsOptions)()),
100
+ __param(2, (0, decorators_1.Log)()),
101
+ __metadata("design:type", Function),
102
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
103
+ __metadata("design:returntype", Promise)
104
+ ], IaCInitRepo.prototype, "execute", null);
105
+ IaCInitRepo = __decorate([
106
+ (0, common_1.ICommand)({
107
+ supportPrivate: true
108
+ })
109
+ ], IaCInitRepo);
110
+ exports.IaCInitRepo = IaCInitRepo;
111
+ let IaCPullRepoConfig = class IaCPullRepoConfig extends common_1.Command {
112
+ get options() {
113
+ return {
114
+ cmd: 'repo',
115
+ childCmd: 'pull-config',
116
+ options: (0, lodash_1.compact)([
117
+ {
118
+ flags: '--cwd <cwd>',
119
+ desc: '仓库路径'
120
+ },
121
+ {
122
+ flags: '--envId <envId>',
123
+ desc: '环境 ID。如有提供,会自动同步环境配置(如 Git 模式的配置数据)'
124
+ }
125
+ ]),
126
+ desc: '拉取大仓在指定环境下的配置(当前只支持拉取 Git 模式的配置)',
127
+ requiredEnvId: false,
128
+ autoRunLogin: true
129
+ };
130
+ }
131
+ execute(ctx, options, log) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ let { envId, name, cwd = '.' } = options;
134
+ const targetDir = path_1.default.resolve(cwd);
135
+ const params = { name, cwd, envId };
136
+ yield iac_core_1.IAC.init({
137
+ cwd,
138
+ getCredential: () => {
139
+ return getCredential(ctx, options);
140
+ }
141
+ });
142
+ log.info(`[当前路径] ${targetDir}`);
143
+ if (!envId && !process.env.ENV_ID) {
144
+ params.envId = yield showEnvIdUI();
145
+ }
146
+ yield iac_core_1.IAC.tools.pullRepoConfig(params, (message) => trackCallback(message, log));
147
+ });
148
+ }
149
+ };
150
+ __decorate([
151
+ (0, decorators_1.InjectParams)(),
152
+ __param(0, (0, decorators_1.CmdContext)()),
153
+ __param(1, (0, decorators_1.ArgsOptions)()),
154
+ __param(2, (0, decorators_1.Log)()),
155
+ __metadata("design:type", Function),
156
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
157
+ __metadata("design:returntype", Promise)
158
+ ], IaCPullRepoConfig.prototype, "execute", null);
159
+ IaCPullRepoConfig = __decorate([
160
+ (0, common_1.ICommand)({
161
+ supportPrivate: true
162
+ })
163
+ ], IaCPullRepoConfig);
164
+ exports.IaCPullRepoConfig = IaCPullRepoConfig;
165
+ let IaCInit = class IaCInit extends common_1.Command {
166
+ get options() {
167
+ return getOptions({
168
+ childCmd: 'init',
169
+ options: [],
170
+ desc: '初始化资源代码项目',
171
+ needEnvIdOption: false,
172
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.init
173
+ });
174
+ }
175
+ execute(ctx, options, log) {
176
+ return __awaiter(this, void 0, void 0, function* () {
177
+ let { resource, name, cwd = '.' } = options;
178
+ yield iac_core_1.IAC.resource.init(getAPIParams({
179
+ cwd,
180
+ name,
181
+ resource,
182
+ action: type_1.ResourceAction.Init,
183
+ log,
184
+ needEnvId: false,
185
+ specResourceLogic: function (resource, config) {
186
+ return __awaiter(this, void 0, void 0, function* () {
187
+ switch (resource) {
188
+ case type_1.ResourceType.SCF:
189
+ {
190
+ const runtimeRes = yield inquirer_1.default.prompt({
191
+ type: 'autocomplete',
192
+ name: 'runtime',
193
+ message: '请选择运行环境',
194
+ default: type_1.IFunctionRuntime.Nodejs18_15,
195
+ source: function (answersSoFar, input = '') {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ const choices = Object.values(type_1.IFunctionRuntime);
198
+ const filtered = choices.filter((choice) => choice
199
+ .toLowerCase()
200
+ .includes((input === null || input === void 0 ? void 0 : input.toLowerCase()) || ''));
201
+ return filtered;
202
+ });
203
+ }
204
+ });
205
+ Object.assign(config, runtimeRes);
206
+ const memorySizeRes = yield inquirer_1.default.prompt({
207
+ type: 'number',
208
+ name: 'memorySize',
209
+ message: '函数内存(MB)',
210
+ default: 256
211
+ });
212
+ Object.assign(config, memorySizeRes);
213
+ const descriptionSizeRes = yield inquirer_1.default.prompt({
214
+ type: 'input',
215
+ name: 'description',
216
+ message: '描述'
217
+ });
218
+ Object.assign(config, descriptionSizeRes);
219
+ }
220
+ break;
221
+ case type_1.ResourceType.App:
222
+ {
223
+ const titleRes = yield inquirer_1.default.prompt({
224
+ type: 'input',
225
+ name: 'title',
226
+ message: '应用名称',
227
+ default: config.name
228
+ });
229
+ Object.assign(config, titleRes);
230
+ }
231
+ break;
232
+ case type_1.ResourceType.Model:
233
+ {
234
+ const titleRes = yield inquirer_1.default.prompt({
235
+ type: 'input',
236
+ name: 'title',
237
+ message: '数据模型名称',
238
+ default: config.name
239
+ });
240
+ Object.assign(config, titleRes);
241
+ const dbInstanceTypeRes = yield inquirer_1.default.prompt({
242
+ type: 'list',
243
+ name: 'dbInstanceType',
244
+ message: '数据库类型',
245
+ default: cals_1.IDatabaseDataSourceDbType.FLEXDB,
246
+ choices: Object.values(cals_1.IDatabaseDataSourceDbType)
247
+ });
248
+ Object.assign(config, dbInstanceTypeRes);
249
+ const descriptionSizeRes = yield inquirer_1.default.prompt({
250
+ type: 'input',
251
+ name: 'description',
252
+ message: '描述'
253
+ });
254
+ Object.assign(config, descriptionSizeRes);
255
+ }
256
+ break;
257
+ case type_1.ResourceType.WebApp: {
258
+ const templateRes = yield inquirer_1.default.prompt({
259
+ type: 'list',
260
+ name: 'template',
261
+ message: '请选择模版',
262
+ default: 'static',
263
+ choices: iac_core_1.IAC.WebApp.getAvailableTemplates()
264
+ });
265
+ Object.assign(config, templateRes);
266
+ }
267
+ }
268
+ });
269
+ }
270
+ }));
271
+ });
272
+ }
273
+ };
274
+ __decorate([
275
+ (0, decorators_1.InjectParams)(),
276
+ __param(0, (0, decorators_1.CmdContext)()),
277
+ __param(1, (0, decorators_1.ArgsOptions)()),
278
+ __param(2, (0, decorators_1.Log)()),
279
+ __metadata("design:type", Function),
280
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
281
+ __metadata("design:returntype", Promise)
282
+ ], IaCInit.prototype, "execute", null);
283
+ IaCInit = __decorate([
284
+ (0, common_1.ICommand)({
285
+ supportPrivate: true
286
+ })
287
+ ], IaCInit);
288
+ exports.IaCInit = IaCInit;
289
+ let IaCPull = class IaCPull extends common_1.Command {
290
+ get options() {
291
+ return getOptions({
292
+ childCmd: 'pull',
293
+ options: [],
294
+ desc: '拉取资源项目代码',
295
+ needEnvIdOption: true,
296
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.pull
297
+ });
298
+ }
299
+ execute(ctx, options, log) {
300
+ return __awaiter(this, void 0, void 0, function* () {
301
+ let { resource, name, envId, cwd = '.' } = options;
302
+ yield iac_core_1.IAC.init({
303
+ cwd,
304
+ getCredential: () => {
305
+ return getCredential(ctx, options);
306
+ }
307
+ });
308
+ yield iac_core_1.IAC.resource.pull(getAPIParams({
309
+ cwd,
310
+ name,
311
+ resource,
312
+ action: type_1.ResourceAction.Pull,
313
+ envId,
314
+ log,
315
+ needEnvId: true
316
+ }));
317
+ });
318
+ }
319
+ };
320
+ __decorate([
321
+ (0, decorators_1.InjectParams)(),
322
+ __param(0, (0, decorators_1.CmdContext)()),
323
+ __param(1, (0, decorators_1.ArgsOptions)()),
324
+ __param(2, (0, decorators_1.Log)()),
325
+ __metadata("design:type", Function),
326
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
327
+ __metadata("design:returntype", Promise)
328
+ ], IaCPull.prototype, "execute", null);
329
+ IaCPull = __decorate([
330
+ (0, common_1.ICommand)({
331
+ supportPrivate: true
332
+ })
333
+ ], IaCPull);
334
+ exports.IaCPull = IaCPull;
335
+ let IaCBuild = class IaCBuild extends common_1.Command {
336
+ get options() {
337
+ return getOptions({
338
+ childCmd: 'build',
339
+ options: [],
340
+ desc: '构建资源项目代码',
341
+ needEnvIdOption: false,
342
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.build
343
+ });
344
+ }
345
+ execute(ctx, options, log) {
346
+ return __awaiter(this, void 0, void 0, function* () {
347
+ let { resource, name, cwd = '.' } = options;
348
+ yield iac_core_1.IAC.resource.build(getAPIParams({
349
+ cwd,
350
+ name,
351
+ action: type_1.ResourceAction.Build,
352
+ resource,
353
+ log,
354
+ needEnvId: false
355
+ }));
356
+ });
357
+ }
358
+ };
359
+ __decorate([
360
+ (0, decorators_1.InjectParams)(),
361
+ __param(0, (0, decorators_1.CmdContext)()),
362
+ __param(1, (0, decorators_1.ArgsOptions)()),
363
+ __param(2, (0, decorators_1.Log)()),
364
+ __metadata("design:type", Function),
365
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
366
+ __metadata("design:returntype", Promise)
367
+ ], IaCBuild.prototype, "execute", null);
368
+ IaCBuild = __decorate([
369
+ (0, common_1.ICommand)({
370
+ supportPrivate: true
371
+ })
372
+ ], IaCBuild);
373
+ exports.IaCBuild = IaCBuild;
374
+ let IaCDev = class IaCDev extends common_1.Command {
375
+ get options() {
376
+ return getOptions({
377
+ childCmd: 'dev',
378
+ options: [
379
+ {
380
+ flags: '--data <data>',
381
+ desc: '要传递给调用函数的序列化 Event 数据(仅当 resource=SCF 时有效)'
382
+ },
383
+ {
384
+ flags: '--dataPath <dataPath>',
385
+ desc: '要传递给调用函数 Event 的 json 文件所在路径(仅当 resource=SCF 时有效)'
386
+ },
387
+ {
388
+ flags: '--context <context>',
389
+ desc: '要传递给调用函数的序列化 Context 数据(仅当 resource=SCF 时有效)'
390
+ },
391
+ {
392
+ flags: '--contextPath <contextPath>',
393
+ desc: '要传递给调用函数 Context 的 json 文件所在路径(仅当 resource=SCF 时有效)'
394
+ },
395
+ {
396
+ flags: '--platform <platform>',
397
+ desc: '运行平台,可选为 web | mp。默认为 web(仅当 resource=App 时有效)'
398
+ }
399
+ ],
400
+ desc: '本地开发资源项目代码',
401
+ needEnvIdOption: true,
402
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.dev
403
+ });
404
+ }
405
+ execute(ctx, options, log) {
406
+ return __awaiter(this, void 0, void 0, function* () {
407
+ let { resource, name, cwd = '.' } = options;
408
+ const { data, dataPath, context, contextPath, platform } = options;
409
+ yield iac_core_1.IAC.init({
410
+ cwd,
411
+ getCredential: () => {
412
+ return getCredential(ctx, options);
413
+ }
414
+ });
415
+ yield iac_core_1.IAC.resource.dev(getAPIParams({
416
+ cwd,
417
+ name,
418
+ resource,
419
+ action: type_1.ResourceAction.Dev,
420
+ log,
421
+ needEnvId: false,
422
+ extraData: { data, dataPath, context, contextPath, platform },
423
+ specResourceLogic(resource, config) {
424
+ return __awaiter(this, void 0, void 0, function* () {
425
+ if (resource === type_1.ResourceType.WebApp) {
426
+ if (!config.distPath) {
427
+ const distPathRes = yield inquirer_1.default.prompt({
428
+ type: 'input',
429
+ name: 'distPath',
430
+ message: '请输入 distPath',
431
+ default: 'dist'
432
+ });
433
+ Object.assign(config, distPathRes);
434
+ }
435
+ }
436
+ });
437
+ }
438
+ }));
439
+ });
440
+ }
441
+ };
442
+ __decorate([
443
+ (0, decorators_1.InjectParams)(),
444
+ __param(0, (0, decorators_1.CmdContext)()),
445
+ __param(1, (0, decorators_1.ArgsOptions)()),
446
+ __param(2, (0, decorators_1.Log)()),
447
+ __metadata("design:type", Function),
448
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
449
+ __metadata("design:returntype", Promise)
450
+ ], IaCDev.prototype, "execute", null);
451
+ IaCDev = __decorate([
452
+ (0, common_1.ICommand)({
453
+ supportPrivate: true
454
+ })
455
+ ], IaCDev);
456
+ exports.IaCDev = IaCDev;
457
+ let IaCApply = class IaCApply extends common_1.Command {
458
+ get options() {
459
+ return getOptions({
460
+ childCmd: 'apply',
461
+ options: [
462
+ {
463
+ flags: '--comment <comment>',
464
+ desc: '提交信息(仅当 resource=App 时有效)'
465
+ }
466
+ ],
467
+ desc: '本地开发资源项目代码',
468
+ needEnvIdOption: true,
469
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.apply
470
+ });
471
+ }
472
+ execute(ctx, options, log) {
473
+ return __awaiter(this, void 0, void 0, function* () {
474
+ let { resource, name, envId, cwd = '.' } = options;
475
+ const { comment } = options;
476
+ yield iac_core_1.IAC.init({
477
+ cwd,
478
+ getCredential: () => {
479
+ return getCredential(ctx, options);
480
+ }
481
+ });
482
+ yield iac_core_1.IAC.resource.apply(getAPIParams({
483
+ cwd,
484
+ name,
485
+ resource,
486
+ action: type_1.ResourceAction.Apply,
487
+ envId,
488
+ log,
489
+ needEnvId: true,
490
+ extraData: { comment },
491
+ specResourceLogic: function (resource, config) {
492
+ return __awaiter(this, void 0, void 0, function* () {
493
+ if (resource === type_1.ResourceType.WebApp) {
494
+ if (!config.distPath) {
495
+ const distPathRes = yield inquirer_1.default.prompt({
496
+ type: 'input',
497
+ name: 'distPath',
498
+ message: '请输入 distPath',
499
+ default: 'dist'
500
+ });
501
+ Object.assign(config, distPathRes);
502
+ }
503
+ }
504
+ });
505
+ }
506
+ }));
507
+ });
508
+ }
509
+ };
510
+ __decorate([
511
+ (0, decorators_1.InjectParams)(),
512
+ __param(0, (0, decorators_1.CmdContext)()),
513
+ __param(1, (0, decorators_1.ArgsOptions)()),
514
+ __param(2, (0, decorators_1.Log)()),
515
+ __metadata("design:type", Function),
516
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
517
+ __metadata("design:returntype", Promise)
518
+ ], IaCApply.prototype, "execute", null);
519
+ IaCApply = __decorate([
520
+ (0, common_1.ICommand)({
521
+ supportPrivate: true
522
+ })
523
+ ], IaCApply);
524
+ exports.IaCApply = IaCApply;
525
+ let IaCDestory = class IaCDestory extends common_1.Command {
526
+ get options() {
527
+ return getOptions({
528
+ childCmd: 'destory',
529
+ options: [],
530
+ desc: '删除资源',
531
+ needEnvIdOption: true,
532
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.destory
533
+ });
534
+ }
535
+ execute(ctx, options, log) {
536
+ return __awaiter(this, void 0, void 0, function* () {
537
+ let { resource, name, envId, cwd = '.' } = options;
538
+ yield iac_core_1.IAC.init({
539
+ cwd,
540
+ getCredential: () => {
541
+ return getCredential(ctx, options);
542
+ }
543
+ });
544
+ yield iac_core_1.IAC.resource.destory(getAPIParams({
545
+ cwd,
546
+ name,
547
+ resource,
548
+ action: type_1.ResourceAction.Destory,
549
+ envId,
550
+ log,
551
+ needEnvId: true
552
+ }));
553
+ });
554
+ }
555
+ };
556
+ __decorate([
557
+ (0, decorators_1.InjectParams)(),
558
+ __param(0, (0, decorators_1.CmdContext)()),
559
+ __param(1, (0, decorators_1.ArgsOptions)()),
560
+ __param(2, (0, decorators_1.Log)()),
561
+ __metadata("design:type", Function),
562
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
563
+ __metadata("design:returntype", Promise)
564
+ ], IaCDestory.prototype, "execute", null);
565
+ IaCDestory = __decorate([
566
+ (0, common_1.ICommand)({
567
+ supportPrivate: true
568
+ })
569
+ ], IaCDestory);
570
+ exports.IaCDestory = IaCDestory;
571
+ let IaCState = class IaCState extends common_1.Command {
572
+ get options() {
573
+ return getOptions({
574
+ childCmd: 'state',
575
+ options: [],
576
+ desc: '查询资源信息',
577
+ needEnvIdOption: true,
578
+ resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.state
579
+ });
580
+ }
581
+ execute(ctx, options, log) {
582
+ return __awaiter(this, void 0, void 0, function* () {
583
+ const { resource, name, cwd = '.', envId } = options;
584
+ yield iac_core_1.IAC.init({
585
+ cwd,
586
+ getCredential: () => {
587
+ return getCredential(ctx, options);
588
+ }
589
+ });
590
+ const data = yield iac_core_1.IAC.resource.state(getAPIParams({
591
+ cwd,
592
+ name,
593
+ resource,
594
+ action: type_1.ResourceAction.State,
595
+ envId,
596
+ log,
597
+ needEnvId: true
598
+ }));
599
+ if (data) {
600
+ log.info(JSON.stringify(data, null, 2));
601
+ }
602
+ });
603
+ }
604
+ };
605
+ __decorate([
606
+ (0, decorators_1.InjectParams)(),
607
+ __param(0, (0, decorators_1.CmdContext)()),
608
+ __param(1, (0, decorators_1.ArgsOptions)()),
609
+ __param(2, (0, decorators_1.Log)()),
610
+ __metadata("design:type", Function),
611
+ __metadata("design:paramtypes", [Object, Object, decorators_1.Logger]),
612
+ __metadata("design:returntype", Promise)
613
+ ], IaCState.prototype, "execute", null);
614
+ IaCState = __decorate([
615
+ (0, common_1.ICommand)({
616
+ supportPrivate: true
617
+ })
618
+ ], IaCState);
619
+ exports.IaCState = IaCState;
620
+ function getOptions({ childCmd, options, desc, resourceSupportList, needEnvIdOption = true }) {
621
+ return {
622
+ cmd: 'res',
623
+ childCmd,
624
+ options: (0, lodash_1.compact)([
625
+ {
626
+ flags: '--resource <resource>',
627
+ desc: '资源类型。当前支持 ' + resourceSupportList.join(' / ')
628
+ },
629
+ {
630
+ flags: '--name <name>',
631
+ desc: '资源标识'
632
+ },
633
+ {
634
+ flags: '--cwd <cwd>',
635
+ desc: '仓库路径'
636
+ },
637
+ needEnvIdOption
638
+ ? {
639
+ flags: '--envId <envId>',
640
+ desc: '环境 ID'
641
+ }
642
+ : null,
643
+ ...options
644
+ ]),
645
+ desc,
646
+ requiredEnvId: false,
647
+ autoRunLogin: true
648
+ };
649
+ }
650
+ function getResource(resource, action) {
651
+ return __awaiter(this, void 0, void 0, function* () {
652
+ let selectedResource = resource;
653
+ if (!selectedResource) {
654
+ const res = yield inquirer_1.default.prompt({
655
+ type: 'list',
656
+ name: 'resource',
657
+ message: '请选择资源类型',
658
+ choices: iac_core_1.IAC.tools.getResourceList(action).map((item) => ({
659
+ name: `${item.value} - ${item.name}`,
660
+ value: item.value
661
+ }))
662
+ });
663
+ selectedResource = res.resource;
664
+ }
665
+ return selectedResource;
666
+ });
667
+ }
668
+ function trackCallback(message, log) {
669
+ if (message.type === 'error') {
670
+ log.error(message.details);
671
+ }
672
+ else {
673
+ log.info(message.details);
674
+ }
675
+ }
676
+ function getCredential(ctx, options) {
677
+ return __awaiter(this, void 0, void 0, function* () {
678
+ let credential;
679
+ if (ctx.hasPrivateSettings) {
680
+ process.env.IS_PRIVATE = 'true';
681
+ const privateSettings = (0, utils_1.getPrivateSettings)(ctx.config, options.cmd);
682
+ credential = privateSettings === null || privateSettings === void 0 ? void 0 : privateSettings.credential;
683
+ }
684
+ else {
685
+ credential = yield utils_1.authSupevisor.getLoginState();
686
+ }
687
+ return credential;
688
+ });
689
+ }
690
+ function getAPIParams(config) {
691
+ const { cwd, resource, action, name, envId, log, needEnvId = true, extraData = {}, specResourceLogic } = config;
692
+ return {
693
+ cwd,
694
+ getResource: () => {
695
+ return getResource(resource, action);
696
+ },
697
+ getConfig: function (resource, envObj, otherInfo) {
698
+ return __awaiter(this, void 0, void 0, function* () {
699
+ const config = (0, lodash_1.assignWith)(envObj, { name, envId }, extraData, function customizer(objValue, srcValue) {
700
+ return (0, lodash_1.isUndefined)(objValue) ? srcValue : objValue;
701
+ });
702
+ const { resourceGroupDir } = otherInfo;
703
+ if (!config.name) {
704
+ const nameRes = yield showNameUI(resourceGroupDir);
705
+ Object.assign(config, { name: nameRes });
706
+ }
707
+ if (needEnvId) {
708
+ if (!config.envId) {
709
+ const envIdRes = yield showEnvIdUI();
710
+ Object.assign(config, { envId: envIdRes });
711
+ }
712
+ }
713
+ yield (specResourceLogic === null || specResourceLogic === void 0 ? void 0 : specResourceLogic(resource, config));
714
+ return config;
715
+ });
716
+ },
717
+ trackCallback: (message) => {
718
+ trackCallback(message, log);
719
+ }
720
+ };
721
+ }
722
+ function showNameUI(resourceGroupDir) {
723
+ return __awaiter(this, void 0, void 0, function* () {
724
+ let res;
725
+ if (!(yield (0, fs_extra_1.pathExists)(resourceGroupDir))) {
726
+ res = yield inquirer_1.default.prompt({
727
+ type: 'input',
728
+ name: 'name',
729
+ message: '请输入资源标识',
730
+ validate: function (input) {
731
+ if (input.trim() === '') {
732
+ return '资源标识不能为空';
733
+ }
734
+ return true;
735
+ }
736
+ });
737
+ }
738
+ else {
739
+ res = yield inquirer_1.default.prompt({
740
+ type: 'autocomplete',
741
+ name: 'name',
742
+ message: '请选择或直接输入资源标识',
743
+ source: function (answersSoFar, input = '') {
744
+ return __awaiter(this, void 0, void 0, function* () {
745
+ const choices = yield (0, fs_extra_1.readdir)(resourceGroupDir).then((files) => files.filter((file) => (0, fs_extra_1.statSync)(path_1.default.join(resourceGroupDir, file)).isDirectory()));
746
+ const filtered = choices.filter((choice) => choice.toLowerCase().includes(input.toLowerCase()));
747
+ return input ? [input, ...filtered] : filtered;
748
+ });
749
+ },
750
+ validate: function (input) {
751
+ if (input.value.trim() === '') {
752
+ return '资源标识不能为空';
753
+ }
754
+ return true;
755
+ }
756
+ });
757
+ }
758
+ return res.name;
759
+ });
760
+ }
761
+ function showEnvIdUI(options) {
762
+ return __awaiter(this, void 0, void 0, function* () {
763
+ const { required = true, message = '环境 ID' } = options || {};
764
+ const envList = yield iac_core_1.IAC.tools.getEnvList();
765
+ const res = yield inquirer_1.default.prompt({
766
+ type: 'autocomplete',
767
+ name: 'envId',
768
+ message,
769
+ source: function (answersSoFar, input = '') {
770
+ return __awaiter(this, void 0, void 0, function* () {
771
+ const filtered = envList.filter((envId) => envId.toLowerCase().includes((input === null || input === void 0 ? void 0 : input.toLowerCase()) || ''));
772
+ return required ? filtered : (0, lodash_1.compact)([input ? undefined : '不提供', ...filtered]);
773
+ });
774
+ },
775
+ validate: required
776
+ ? function (input) {
777
+ if (input.value.trim() === '') {
778
+ return '环境 ID 不能为空';
779
+ }
780
+ return true;
781
+ }
782
+ : undefined
783
+ });
784
+ return res.envId === '不提供' ? null : res.envId;
785
+ });
786
+ }