@cloudbase/cli 2.7.0-alpha.0 → 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.
- package/lib/commands/iac/index.js +283 -139
- package/package.json +5 -3
- package/types/commands/iac/index.d.ts +28 -0
|
@@ -24,17 +24,144 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.IaCState = exports.IaCDestory = exports.IaCApply = exports.IaCDev = exports.IaCBuild = exports.IaCPull = exports.IaCInit = void 0;
|
|
27
|
+
exports.IaCState = exports.IaCDestory = exports.IaCApply = exports.IaCDev = exports.IaCBuild = exports.IaCPull = exports.IaCInit = exports.IaCPullRepoConfig = exports.IaCInitRepo = void 0;
|
|
28
28
|
const cals_1 = require("@cloudbase/cals");
|
|
29
29
|
const iac_core_1 = require("@cloudbase/iac-core");
|
|
30
30
|
const type_1 = require("@cloudbase/iac-core/lib/src/type");
|
|
31
|
-
const toolbox_1 = require("@cloudbase/toolbox");
|
|
32
31
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
33
32
|
const lodash_1 = require("lodash");
|
|
33
|
+
const inquirer_autocomplete_prompt_1 = __importDefault(require("inquirer-autocomplete-prompt"));
|
|
34
|
+
const path_1 = __importDefault(require("path"));
|
|
34
35
|
const decorators_1 = require("../../decorators");
|
|
35
36
|
const utils_1 = require("../../utils");
|
|
36
37
|
const common_1 = require("../common");
|
|
37
|
-
const
|
|
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;
|
|
38
165
|
let IaCInit = class IaCInit extends common_1.Command {
|
|
39
166
|
get options() {
|
|
40
167
|
return getOptions({
|
|
@@ -52,6 +179,7 @@ let IaCInit = class IaCInit extends common_1.Command {
|
|
|
52
179
|
cwd,
|
|
53
180
|
name,
|
|
54
181
|
resource,
|
|
182
|
+
action: type_1.ResourceAction.Init,
|
|
55
183
|
log,
|
|
56
184
|
needEnvId: false,
|
|
57
185
|
specResourceLogic: function (resource, config) {
|
|
@@ -60,11 +188,19 @@ let IaCInit = class IaCInit extends common_1.Command {
|
|
|
60
188
|
case type_1.ResourceType.SCF:
|
|
61
189
|
{
|
|
62
190
|
const runtimeRes = yield inquirer_1.default.prompt({
|
|
63
|
-
type: '
|
|
191
|
+
type: 'autocomplete',
|
|
64
192
|
name: 'runtime',
|
|
65
193
|
message: '请选择运行环境',
|
|
66
194
|
default: type_1.IFunctionRuntime.Nodejs18_15,
|
|
67
|
-
|
|
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
|
+
}
|
|
68
204
|
});
|
|
69
205
|
Object.assign(config, runtimeRes);
|
|
70
206
|
const memorySizeRes = yield inquirer_1.default.prompt({
|
|
@@ -118,6 +254,16 @@ let IaCInit = class IaCInit extends common_1.Command {
|
|
|
118
254
|
Object.assign(config, descriptionSizeRes);
|
|
119
255
|
}
|
|
120
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
|
+
}
|
|
121
267
|
}
|
|
122
268
|
});
|
|
123
269
|
}
|
|
@@ -144,12 +290,7 @@ let IaCPull = class IaCPull extends common_1.Command {
|
|
|
144
290
|
get options() {
|
|
145
291
|
return getOptions({
|
|
146
292
|
childCmd: 'pull',
|
|
147
|
-
options: [
|
|
148
|
-
{
|
|
149
|
-
flags: '--appId <appId>',
|
|
150
|
-
desc: '应用 ID(仅当 resource=App 时有效)'
|
|
151
|
-
}
|
|
152
|
-
],
|
|
293
|
+
options: [],
|
|
153
294
|
desc: '拉取资源项目代码',
|
|
154
295
|
needEnvIdOption: true,
|
|
155
296
|
resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.pull
|
|
@@ -158,30 +299,20 @@ let IaCPull = class IaCPull extends common_1.Command {
|
|
|
158
299
|
execute(ctx, options, log) {
|
|
159
300
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
301
|
let { resource, name, envId, cwd = '.' } = options;
|
|
161
|
-
const { appId } = options;
|
|
162
302
|
yield iac_core_1.IAC.init({
|
|
303
|
+
cwd,
|
|
163
304
|
getCredential: () => {
|
|
164
|
-
return getCredential(ctx);
|
|
305
|
+
return getCredential(ctx, options);
|
|
165
306
|
}
|
|
166
307
|
});
|
|
167
308
|
yield iac_core_1.IAC.resource.pull(getAPIParams({
|
|
168
309
|
cwd,
|
|
169
310
|
name,
|
|
170
311
|
resource,
|
|
312
|
+
action: type_1.ResourceAction.Pull,
|
|
171
313
|
envId,
|
|
172
314
|
log,
|
|
173
|
-
needEnvId: true
|
|
174
|
-
extraData: { appId },
|
|
175
|
-
specResourceLogic: function (resource, config) {
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
if (resource === type_1.ResourceType.App) {
|
|
178
|
-
if (!config.appId) {
|
|
179
|
-
const appIdRes = yield showAppIdUI();
|
|
180
|
-
Object.assign(config, { appId: appIdRes });
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
315
|
+
needEnvId: true
|
|
185
316
|
}));
|
|
186
317
|
});
|
|
187
318
|
}
|
|
@@ -217,6 +348,7 @@ let IaCBuild = class IaCBuild extends common_1.Command {
|
|
|
217
348
|
yield iac_core_1.IAC.resource.build(getAPIParams({
|
|
218
349
|
cwd,
|
|
219
350
|
name,
|
|
351
|
+
action: type_1.ResourceAction.Build,
|
|
220
352
|
resource,
|
|
221
353
|
log,
|
|
222
354
|
needEnvId: false
|
|
@@ -266,7 +398,7 @@ let IaCDev = class IaCDev extends common_1.Command {
|
|
|
266
398
|
}
|
|
267
399
|
],
|
|
268
400
|
desc: '本地开发资源项目代码',
|
|
269
|
-
needEnvIdOption:
|
|
401
|
+
needEnvIdOption: true,
|
|
270
402
|
resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.dev
|
|
271
403
|
});
|
|
272
404
|
}
|
|
@@ -275,17 +407,34 @@ let IaCDev = class IaCDev extends common_1.Command {
|
|
|
275
407
|
let { resource, name, cwd = '.' } = options;
|
|
276
408
|
const { data, dataPath, context, contextPath, platform } = options;
|
|
277
409
|
yield iac_core_1.IAC.init({
|
|
410
|
+
cwd,
|
|
278
411
|
getCredential: () => {
|
|
279
|
-
return getCredential(ctx);
|
|
412
|
+
return getCredential(ctx, options);
|
|
280
413
|
}
|
|
281
414
|
});
|
|
282
415
|
yield iac_core_1.IAC.resource.dev(getAPIParams({
|
|
283
416
|
cwd,
|
|
284
417
|
name,
|
|
285
418
|
resource,
|
|
419
|
+
action: type_1.ResourceAction.Dev,
|
|
286
420
|
log,
|
|
287
421
|
needEnvId: false,
|
|
288
|
-
extraData: { data, dataPath, context, contextPath, platform }
|
|
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
|
+
}
|
|
289
438
|
}));
|
|
290
439
|
});
|
|
291
440
|
}
|
|
@@ -310,10 +459,6 @@ let IaCApply = class IaCApply extends common_1.Command {
|
|
|
310
459
|
return getOptions({
|
|
311
460
|
childCmd: 'apply',
|
|
312
461
|
options: [
|
|
313
|
-
{
|
|
314
|
-
flags: '--appId <appId>',
|
|
315
|
-
desc: '应用 ID(仅当 resource=App 时有效)'
|
|
316
|
-
},
|
|
317
462
|
{
|
|
318
463
|
flags: '--comment <comment>',
|
|
319
464
|
desc: '提交信息(仅当 resource=App 时有效)'
|
|
@@ -327,22 +472,35 @@ let IaCApply = class IaCApply extends common_1.Command {
|
|
|
327
472
|
execute(ctx, options, log) {
|
|
328
473
|
return __awaiter(this, void 0, void 0, function* () {
|
|
329
474
|
let { resource, name, envId, cwd = '.' } = options;
|
|
330
|
-
const {
|
|
475
|
+
const { comment } = options;
|
|
331
476
|
yield iac_core_1.IAC.init({
|
|
477
|
+
cwd,
|
|
332
478
|
getCredential: () => {
|
|
333
|
-
return getCredential(ctx);
|
|
479
|
+
return getCredential(ctx, options);
|
|
334
480
|
}
|
|
335
481
|
});
|
|
336
482
|
yield iac_core_1.IAC.resource.apply(getAPIParams({
|
|
337
483
|
cwd,
|
|
338
484
|
name,
|
|
339
485
|
resource,
|
|
486
|
+
action: type_1.ResourceAction.Apply,
|
|
340
487
|
envId,
|
|
341
488
|
log,
|
|
342
489
|
needEnvId: true,
|
|
343
|
-
extraData: {
|
|
490
|
+
extraData: { comment },
|
|
344
491
|
specResourceLogic: function (resource, config) {
|
|
345
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
|
+
}
|
|
346
504
|
});
|
|
347
505
|
}
|
|
348
506
|
}));
|
|
@@ -368,12 +526,7 @@ let IaCDestory = class IaCDestory extends common_1.Command {
|
|
|
368
526
|
get options() {
|
|
369
527
|
return getOptions({
|
|
370
528
|
childCmd: 'destory',
|
|
371
|
-
options: [
|
|
372
|
-
{
|
|
373
|
-
flags: '--appId <appId>',
|
|
374
|
-
desc: '应用 ID(仅当 resource=App 时有效)'
|
|
375
|
-
}
|
|
376
|
-
],
|
|
529
|
+
options: [],
|
|
377
530
|
desc: '删除资源',
|
|
378
531
|
needEnvIdOption: true,
|
|
379
532
|
resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.destory
|
|
@@ -382,30 +535,20 @@ let IaCDestory = class IaCDestory extends common_1.Command {
|
|
|
382
535
|
execute(ctx, options, log) {
|
|
383
536
|
return __awaiter(this, void 0, void 0, function* () {
|
|
384
537
|
let { resource, name, envId, cwd = '.' } = options;
|
|
385
|
-
const { appId } = options;
|
|
386
538
|
yield iac_core_1.IAC.init({
|
|
539
|
+
cwd,
|
|
387
540
|
getCredential: () => {
|
|
388
|
-
return getCredential(ctx);
|
|
541
|
+
return getCredential(ctx, options);
|
|
389
542
|
}
|
|
390
543
|
});
|
|
391
544
|
yield iac_core_1.IAC.resource.destory(getAPIParams({
|
|
392
545
|
cwd,
|
|
393
546
|
name,
|
|
394
547
|
resource,
|
|
548
|
+
action: type_1.ResourceAction.Destory,
|
|
395
549
|
envId,
|
|
396
550
|
log,
|
|
397
|
-
needEnvId: true
|
|
398
|
-
extraData: { appId },
|
|
399
|
-
specResourceLogic: function (resource, config) {
|
|
400
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
401
|
-
if (resource === type_1.ResourceType.App) {
|
|
402
|
-
if (!config.appId) {
|
|
403
|
-
const appIdRes = yield showAppIdUI();
|
|
404
|
-
Object.assign(config, { appId: appIdRes });
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
551
|
+
needEnvId: true
|
|
409
552
|
}));
|
|
410
553
|
});
|
|
411
554
|
}
|
|
@@ -429,12 +572,7 @@ let IaCState = class IaCState extends common_1.Command {
|
|
|
429
572
|
get options() {
|
|
430
573
|
return getOptions({
|
|
431
574
|
childCmd: 'state',
|
|
432
|
-
options: [
|
|
433
|
-
{
|
|
434
|
-
flags: '--appId <appId>',
|
|
435
|
-
desc: '应用 ID(仅当 resource=App 时有效)'
|
|
436
|
-
}
|
|
437
|
-
],
|
|
575
|
+
options: [],
|
|
438
576
|
desc: '查询资源信息',
|
|
439
577
|
needEnvIdOption: true,
|
|
440
578
|
resourceSupportList: iac_core_1.IAC.actionSupportedResourceTypes.state
|
|
@@ -443,32 +581,24 @@ let IaCState = class IaCState extends common_1.Command {
|
|
|
443
581
|
execute(ctx, options, log) {
|
|
444
582
|
return __awaiter(this, void 0, void 0, function* () {
|
|
445
583
|
const { resource, name, cwd = '.', envId } = options;
|
|
446
|
-
const { appId } = options;
|
|
447
584
|
yield iac_core_1.IAC.init({
|
|
585
|
+
cwd,
|
|
448
586
|
getCredential: () => {
|
|
449
|
-
return getCredential(ctx);
|
|
587
|
+
return getCredential(ctx, options);
|
|
450
588
|
}
|
|
451
589
|
});
|
|
452
590
|
const data = yield iac_core_1.IAC.resource.state(getAPIParams({
|
|
453
591
|
cwd,
|
|
454
592
|
name,
|
|
455
593
|
resource,
|
|
594
|
+
action: type_1.ResourceAction.State,
|
|
456
595
|
envId,
|
|
457
596
|
log,
|
|
458
|
-
needEnvId: true
|
|
459
|
-
extraData: { appId },
|
|
460
|
-
specResourceLogic: function (resource, config) {
|
|
461
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
462
|
-
if (resource === type_1.ResourceType.App) {
|
|
463
|
-
if (!config.appId) {
|
|
464
|
-
const appIdRes = yield showAppIdUI();
|
|
465
|
-
Object.assign(config, { appId: appIdRes });
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
});
|
|
469
|
-
}
|
|
597
|
+
needEnvId: true
|
|
470
598
|
}));
|
|
471
|
-
|
|
599
|
+
if (data) {
|
|
600
|
+
log.info(JSON.stringify(data, null, 2));
|
|
601
|
+
}
|
|
472
602
|
});
|
|
473
603
|
}
|
|
474
604
|
};
|
|
@@ -489,7 +619,7 @@ IaCState = __decorate([
|
|
|
489
619
|
exports.IaCState = IaCState;
|
|
490
620
|
function getOptions({ childCmd, options, desc, resourceSupportList, needEnvIdOption = true }) {
|
|
491
621
|
return {
|
|
492
|
-
cmd: '
|
|
622
|
+
cmd: 'res',
|
|
493
623
|
childCmd,
|
|
494
624
|
options: (0, lodash_1.compact)([
|
|
495
625
|
{
|
|
@@ -498,16 +628,16 @@ function getOptions({ childCmd, options, desc, resourceSupportList, needEnvIdOpt
|
|
|
498
628
|
},
|
|
499
629
|
{
|
|
500
630
|
flags: '--name <name>',
|
|
501
|
-
desc: '
|
|
631
|
+
desc: '资源标识'
|
|
502
632
|
},
|
|
503
633
|
{
|
|
504
634
|
flags: '--cwd <cwd>',
|
|
505
|
-
desc: '
|
|
635
|
+
desc: '仓库路径'
|
|
506
636
|
},
|
|
507
637
|
needEnvIdOption
|
|
508
638
|
? {
|
|
509
639
|
flags: '--envId <envId>',
|
|
510
|
-
desc: '环境
|
|
640
|
+
desc: '环境 ID'
|
|
511
641
|
}
|
|
512
642
|
: null,
|
|
513
643
|
...options
|
|
@@ -517,43 +647,39 @@ function getOptions({ childCmd, options, desc, resourceSupportList, needEnvIdOpt
|
|
|
517
647
|
autoRunLogin: true
|
|
518
648
|
};
|
|
519
649
|
}
|
|
520
|
-
function getResource(resource) {
|
|
650
|
+
function getResource(resource, action) {
|
|
521
651
|
return __awaiter(this, void 0, void 0, function* () {
|
|
522
|
-
|
|
652
|
+
let selectedResource = resource;
|
|
653
|
+
if (!selectedResource) {
|
|
523
654
|
const res = yield inquirer_1.default.prompt({
|
|
524
655
|
type: 'list',
|
|
525
656
|
name: 'resource',
|
|
526
657
|
message: '请选择资源类型',
|
|
527
|
-
choices: iac_core_1.IAC.
|
|
658
|
+
choices: iac_core_1.IAC.tools.getResourceList(action).map((item) => ({
|
|
659
|
+
name: `${item.value} - ${item.name}`,
|
|
660
|
+
value: item.value
|
|
661
|
+
}))
|
|
528
662
|
});
|
|
529
|
-
|
|
663
|
+
selectedResource = res.resource;
|
|
530
664
|
}
|
|
531
|
-
return
|
|
665
|
+
return selectedResource;
|
|
532
666
|
});
|
|
533
667
|
}
|
|
534
668
|
function trackCallback(message, log) {
|
|
535
|
-
if (message.
|
|
536
|
-
|
|
537
|
-
}
|
|
538
|
-
else if (message.status === 'done') {
|
|
539
|
-
loading.succeed(message.details);
|
|
669
|
+
if (message.type === 'error') {
|
|
670
|
+
log.error(message.details);
|
|
540
671
|
}
|
|
541
672
|
else {
|
|
542
|
-
|
|
543
|
-
loading.fail(message.details);
|
|
544
|
-
}
|
|
545
|
-
else {
|
|
546
|
-
log.info(message.details);
|
|
547
|
-
}
|
|
673
|
+
log.info(message.details);
|
|
548
674
|
}
|
|
549
675
|
}
|
|
550
|
-
function getCredential(ctx) {
|
|
676
|
+
function getCredential(ctx, options) {
|
|
551
677
|
return __awaiter(this, void 0, void 0, function* () {
|
|
552
678
|
let credential;
|
|
553
679
|
if (ctx.hasPrivateSettings) {
|
|
554
680
|
process.env.IS_PRIVATE = 'true';
|
|
555
|
-
const privateSettings = (0, utils_1.getPrivateSettings)(ctx.config,
|
|
556
|
-
credential = privateSettings.credential;
|
|
681
|
+
const privateSettings = (0, utils_1.getPrivateSettings)(ctx.config, options.cmd);
|
|
682
|
+
credential = privateSettings === null || privateSettings === void 0 ? void 0 : privateSettings.credential;
|
|
557
683
|
}
|
|
558
684
|
else {
|
|
559
685
|
credential = yield utils_1.authSupevisor.getLoginState();
|
|
@@ -562,19 +688,20 @@ function getCredential(ctx) {
|
|
|
562
688
|
});
|
|
563
689
|
}
|
|
564
690
|
function getAPIParams(config) {
|
|
565
|
-
const { cwd, resource, name, envId, log, needEnvId = true, extraData = {}, specResourceLogic } = config;
|
|
691
|
+
const { cwd, resource, action, name, envId, log, needEnvId = true, extraData = {}, specResourceLogic } = config;
|
|
566
692
|
return {
|
|
567
693
|
cwd,
|
|
568
694
|
getResource: () => {
|
|
569
|
-
return getResource(resource);
|
|
695
|
+
return getResource(resource, action);
|
|
570
696
|
},
|
|
571
|
-
getConfig: function (resource, envObj) {
|
|
697
|
+
getConfig: function (resource, envObj, otherInfo) {
|
|
572
698
|
return __awaiter(this, void 0, void 0, function* () {
|
|
573
699
|
const config = (0, lodash_1.assignWith)(envObj, { name, envId }, extraData, function customizer(objValue, srcValue) {
|
|
574
700
|
return (0, lodash_1.isUndefined)(objValue) ? srcValue : objValue;
|
|
575
701
|
});
|
|
702
|
+
const { resourceGroupDir } = otherInfo;
|
|
576
703
|
if (!config.name) {
|
|
577
|
-
const nameRes = yield showNameUI();
|
|
704
|
+
const nameRes = yield showNameUI(resourceGroupDir);
|
|
578
705
|
Object.assign(config, { name: nameRes });
|
|
579
706
|
}
|
|
580
707
|
if (needEnvId) {
|
|
@@ -592,51 +719,68 @@ function getAPIParams(config) {
|
|
|
592
719
|
}
|
|
593
720
|
};
|
|
594
721
|
}
|
|
595
|
-
function showNameUI() {
|
|
722
|
+
function showNameUI(resourceGroupDir) {
|
|
596
723
|
return __awaiter(this, void 0, void 0, function* () {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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;
|
|
604
735
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
+
}
|
|
608
758
|
return res.name;
|
|
609
759
|
});
|
|
610
760
|
}
|
|
611
|
-
function showEnvIdUI() {
|
|
761
|
+
function showEnvIdUI(options) {
|
|
612
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();
|
|
613
765
|
const res = yield inquirer_1.default.prompt({
|
|
614
|
-
type: '
|
|
766
|
+
type: 'autocomplete',
|
|
615
767
|
name: 'envId',
|
|
616
|
-
message
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const res = yield inquirer_1.default.prompt({
|
|
630
|
-
type: 'input',
|
|
631
|
-
name: 'appId',
|
|
632
|
-
message: '应用 ID',
|
|
633
|
-
validate: function (input) {
|
|
634
|
-
if (input.trim() === '') {
|
|
635
|
-
return '应用 ID不能为空';
|
|
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;
|
|
636
781
|
}
|
|
637
|
-
|
|
638
|
-
}
|
|
782
|
+
: undefined
|
|
639
783
|
});
|
|
640
|
-
return res.
|
|
784
|
+
return res.envId === '不提供' ? null : res.envId;
|
|
641
785
|
});
|
|
642
786
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cli",
|
|
3
|
-
"version": "2.7.0-alpha.
|
|
3
|
+
"version": "2.7.0-alpha.2",
|
|
4
4
|
"description": "cli tool for cloudbase",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@cloudbase/cloud-api": "^0.5.5",
|
|
35
35
|
"@cloudbase/framework-core": "^1.9.7",
|
|
36
|
+
"@cloudbase/iac-core": "^0.0.2-alpha.4",
|
|
36
37
|
"@cloudbase/lowcode-cli": "^0.21.1",
|
|
37
38
|
"@cloudbase/manager-node": "4.2.8",
|
|
38
39
|
"@cloudbase/toolbox": "^0.7.5",
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
"fs-extra": "^8.1.0",
|
|
49
50
|
"https-proxy-agent": "^5.0.1",
|
|
50
51
|
"inquirer": "^6.5.0",
|
|
52
|
+
"inquirer-autocomplete-prompt": "2.0.1",
|
|
51
53
|
"json-schema-to-typescript": "^14.0.5",
|
|
52
54
|
"lodash": "^4.17.21",
|
|
53
55
|
"log-symbols": "^3.0.0",
|
|
@@ -67,11 +69,11 @@
|
|
|
67
69
|
"update-notifier": "^4.0.0",
|
|
68
70
|
"xdg-basedir": "^4.0.0",
|
|
69
71
|
"yargs": "^16.2.0",
|
|
70
|
-
"yargs-parser": "^21.0.1"
|
|
71
|
-
"@cloudbase/iac-core": "^0.0.2-alpha.2"
|
|
72
|
+
"yargs-parser": "^21.0.1"
|
|
72
73
|
},
|
|
73
74
|
"devDependencies": {
|
|
74
75
|
"@types/fs-extra": "^11.0.4",
|
|
76
|
+
"@types/inquirer-autocomplete-prompt": "^3.0.3",
|
|
75
77
|
"@types/jest": "^27",
|
|
76
78
|
"@types/koa__router": "^8.0.11",
|
|
77
79
|
"@types/lodash": "^4.14.182",
|
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
import { Logger } from '../../decorators';
|
|
2
2
|
import { Command, ICommandOptions } from '../common';
|
|
3
|
+
export declare class IaCInitRepo extends Command {
|
|
4
|
+
get options(): {
|
|
5
|
+
cmd: string;
|
|
6
|
+
childCmd: string;
|
|
7
|
+
options: {
|
|
8
|
+
flags: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
}[];
|
|
11
|
+
desc: string;
|
|
12
|
+
requiredEnvId: boolean;
|
|
13
|
+
autoRunLogin: boolean;
|
|
14
|
+
};
|
|
15
|
+
execute(ctx: any, options: any, log: Logger): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class IaCPullRepoConfig extends Command {
|
|
18
|
+
get options(): {
|
|
19
|
+
cmd: string;
|
|
20
|
+
childCmd: string;
|
|
21
|
+
options: {
|
|
22
|
+
flags: string;
|
|
23
|
+
desc: string;
|
|
24
|
+
}[];
|
|
25
|
+
desc: string;
|
|
26
|
+
requiredEnvId: boolean;
|
|
27
|
+
autoRunLogin: boolean;
|
|
28
|
+
};
|
|
29
|
+
execute(ctx: any, options: any, log: Logger): Promise<void>;
|
|
30
|
+
}
|
|
3
31
|
export declare class IaCInit extends Command {
|
|
4
32
|
get options(): ICommandOptions;
|
|
5
33
|
execute(ctx: any, options: any, log: Logger): Promise<void>;
|