@cloudbase/cli 2.6.8 → 2.6.10
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/cloudfunction/base.js +464 -0
- package/lib/commands/cloudfunction/index.js +17 -0
- package/lib/commands/fun/base.js +1 -9
- package/lib/commands/index.js +1 -0
- package/lib/commands/runf/base.js +10 -26
- package/lib/commands/utils.js +15 -1
- package/package.json +2 -2
- package/types/commands/cloudfunction/base.d.ts +57 -0
- package/types/commands/cloudfunction/index.d.ts +1 -0
- package/types/commands/index.d.ts +1 -0
- package/types/commands/utils.d.ts +4 -0
|
@@ -0,0 +1,464 @@
|
|
|
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.CloudFunctionRunCommand = exports.CloudFunctionDownloadCommand = exports.CloudFunctionDeployCommand = exports.CloudFunctionListCommand = void 0;
|
|
28
|
+
const functions_framework_1 = require("@cloudbase/functions-framework");
|
|
29
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
30
|
+
const camelcase_keys_1 = __importDefault(require("camelcase-keys"));
|
|
31
|
+
const iac_core_1 = require("@cloudbase/iac-core");
|
|
32
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
33
|
+
const path_1 = __importDefault(require("path"));
|
|
34
|
+
const decorators_1 = require("../../decorators");
|
|
35
|
+
const utils_1 = require("../../utils");
|
|
36
|
+
const common_1 = require("../common");
|
|
37
|
+
const constants_1 = require("../constants");
|
|
38
|
+
const utils_2 = require("../utils");
|
|
39
|
+
const nodemon_1 = __importDefault(require("nodemon"));
|
|
40
|
+
const { CloudAPI } = iac_core_1.CloudAPI;
|
|
41
|
+
const scfService = utils_1.CloudApiService.getInstance('tcb');
|
|
42
|
+
class CloudFunctionListCommand extends common_1.Command {
|
|
43
|
+
get options() {
|
|
44
|
+
return {
|
|
45
|
+
cmd: 'cloudfunction',
|
|
46
|
+
childCmd: 'list',
|
|
47
|
+
options: [
|
|
48
|
+
{
|
|
49
|
+
flags: '-e, --envId <envId>',
|
|
50
|
+
desc: '环境 Id'
|
|
51
|
+
}
|
|
52
|
+
],
|
|
53
|
+
requiredEnvId: false,
|
|
54
|
+
autoRunLogin: true,
|
|
55
|
+
desc: '查看函数式托管服务列表'
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
execute(envId, log) {
|
|
59
|
+
var _a;
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
62
|
+
if (!envId) {
|
|
63
|
+
envId = yield _selectEnv();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
log.info(`当前环境 Id:${envId}`);
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
loading.start('获取函数式托管服务列表中…');
|
|
70
|
+
let serverListRes = yield scfService
|
|
71
|
+
.request('DescribeCloudBaseRunServers', {
|
|
72
|
+
EnvId: envId,
|
|
73
|
+
Limit: 100,
|
|
74
|
+
Offset: 0
|
|
75
|
+
})
|
|
76
|
+
.finally(() => loading.stop());
|
|
77
|
+
const serverList = (_a = serverListRes.CloudBaseRunServerSet) === null || _a === void 0 ? void 0 : _a.filter((item) => item.Tag === 'function');
|
|
78
|
+
const head = ['服务名称', '状态', '创建时间', '更新时间'];
|
|
79
|
+
const tableData = serverList.map((serverItem) => [
|
|
80
|
+
serverItem.ServerName,
|
|
81
|
+
serverItem.Status,
|
|
82
|
+
serverItem.CreatedTime,
|
|
83
|
+
serverItem.UpdatedTime
|
|
84
|
+
]);
|
|
85
|
+
(0, utils_1.printHorizontalTable)(head, tableData);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
log.error('获取函数式托管服务列表失败:' + e.message);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
__decorate([
|
|
94
|
+
(0, decorators_1.InjectParams)(),
|
|
95
|
+
__param(0, (0, decorators_1.EnvId)()),
|
|
96
|
+
__param(1, (0, decorators_1.Log)()),
|
|
97
|
+
__metadata("design:type", Function),
|
|
98
|
+
__metadata("design:paramtypes", [Object, decorators_1.Logger]),
|
|
99
|
+
__metadata("design:returntype", Promise)
|
|
100
|
+
], CloudFunctionListCommand.prototype, "execute", null);
|
|
101
|
+
exports.CloudFunctionListCommand = CloudFunctionListCommand;
|
|
102
|
+
let CloudFunctionDeployCommand = class CloudFunctionDeployCommand extends common_1.Command {
|
|
103
|
+
get options() {
|
|
104
|
+
return {
|
|
105
|
+
cmd: 'cloudfunction',
|
|
106
|
+
childCmd: 'deploy',
|
|
107
|
+
options: [
|
|
108
|
+
{
|
|
109
|
+
flags: '-e, --envId <envId>',
|
|
110
|
+
desc: '环境 Id'
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
flags: '-s, --serviceName <serviceName>',
|
|
114
|
+
desc: '服务名称'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
flags: '--source <source>',
|
|
118
|
+
desc: '目标函数文件所在目录路径。默认为当前路径'
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
requiredEnvId: false,
|
|
122
|
+
autoRunLogin: true,
|
|
123
|
+
desc: '部署云函数服务'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
execute(ctx, envId, log, options) {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
let { serviceName, source } = options;
|
|
129
|
+
const targetDir = path_1.default.resolve(source || process.cwd());
|
|
130
|
+
if (!envId) {
|
|
131
|
+
const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(targetDir));
|
|
132
|
+
if (envConfig.envId) {
|
|
133
|
+
envId = envConfig.envId;
|
|
134
|
+
log.info(`当前环境 Id:${envId}`);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
envId = yield _selectEnv();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
log.info(`当前环境 Id:${envId}`);
|
|
142
|
+
}
|
|
143
|
+
if (!serviceName) {
|
|
144
|
+
const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
|
|
145
|
+
serviceName = yield _inputServiceName(shortName);
|
|
146
|
+
}
|
|
147
|
+
const answers = yield inquirer_1.default.prompt([
|
|
148
|
+
{
|
|
149
|
+
type: 'confirm',
|
|
150
|
+
name: 'confirm',
|
|
151
|
+
message: `即将开始部署,是否确认继续?`,
|
|
152
|
+
default: true
|
|
153
|
+
}
|
|
154
|
+
]);
|
|
155
|
+
if (!answers.confirm) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
yield iac_core_1.IAC.init({
|
|
159
|
+
cwd: targetDir,
|
|
160
|
+
getCredential: () => {
|
|
161
|
+
return getCredential(ctx, options);
|
|
162
|
+
},
|
|
163
|
+
polyRepoMode: true
|
|
164
|
+
});
|
|
165
|
+
yield _runDeploy();
|
|
166
|
+
function _runDeploy() {
|
|
167
|
+
var _a;
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
try {
|
|
170
|
+
const res = yield iac_core_1.IAC.Function.apply({
|
|
171
|
+
cwd: targetDir,
|
|
172
|
+
envId: envId,
|
|
173
|
+
name: serviceName
|
|
174
|
+
}, function (message) {
|
|
175
|
+
trackCallback(message, log);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
if ((e === null || e === void 0 ? void 0 : e.action) === 'UpdateFunctionConfiguration' &&
|
|
180
|
+
((_a = e === null || e === void 0 ? void 0 : e.message) === null || _a === void 0 ? void 0 : _a.includes('当前函数处于Updating状态,无法进行此操作,请稍后重试'))) {
|
|
181
|
+
trackCallback({
|
|
182
|
+
type: 'error',
|
|
183
|
+
details: '当前函数处于更新状态,无法进行此操作,请稍后重试',
|
|
184
|
+
originalError: e
|
|
185
|
+
}, log);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
trackCallback({
|
|
189
|
+
type: 'error',
|
|
190
|
+
details: `${e.message}`,
|
|
191
|
+
originalError: e
|
|
192
|
+
}, log);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
__decorate([
|
|
201
|
+
(0, decorators_1.InjectParams)(),
|
|
202
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
203
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
204
|
+
__param(2, (0, decorators_1.Log)()),
|
|
205
|
+
__param(3, (0, decorators_1.ArgsOptions)()),
|
|
206
|
+
__metadata("design:type", Function),
|
|
207
|
+
__metadata("design:paramtypes", [Object, Object, decorators_1.Logger, Object]),
|
|
208
|
+
__metadata("design:returntype", Promise)
|
|
209
|
+
], CloudFunctionDeployCommand.prototype, "execute", null);
|
|
210
|
+
CloudFunctionDeployCommand = __decorate([
|
|
211
|
+
(0, common_1.ICommand)()
|
|
212
|
+
], CloudFunctionDeployCommand);
|
|
213
|
+
exports.CloudFunctionDeployCommand = CloudFunctionDeployCommand;
|
|
214
|
+
let CloudFunctionDownloadCommand = class CloudFunctionDownloadCommand extends common_1.Command {
|
|
215
|
+
get options() {
|
|
216
|
+
return {
|
|
217
|
+
cmd: 'cloudfunction',
|
|
218
|
+
childCmd: 'download',
|
|
219
|
+
options: [
|
|
220
|
+
{
|
|
221
|
+
flags: '-e, --envId <envId>',
|
|
222
|
+
desc: '环境 Id'
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
flags: '-s, --serviceName <serviceName>',
|
|
226
|
+
desc: '服务名称'
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
flags: '--source <source>',
|
|
230
|
+
desc: '目标函数文件所在目录路径。默认为当前路径'
|
|
231
|
+
}
|
|
232
|
+
],
|
|
233
|
+
requiredEnvId: false,
|
|
234
|
+
autoRunLogin: true,
|
|
235
|
+
desc: '下载云函数服务代码'
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
execute(ctx, envId, log, options) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
let { serviceName, source } = options;
|
|
241
|
+
let targetDir = path_1.default.resolve(source || process.cwd());
|
|
242
|
+
if (!envId) {
|
|
243
|
+
const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(targetDir));
|
|
244
|
+
envId = envConfig.envId || (yield _selectEnv());
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
log.info(`当前环境 Id:${envId}`);
|
|
248
|
+
}
|
|
249
|
+
if (!serviceName) {
|
|
250
|
+
const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
|
|
251
|
+
serviceName = yield _inputServiceName(shortName);
|
|
252
|
+
if (serviceName !== shortName) {
|
|
253
|
+
targetDir = path_1.default.join(targetDir, serviceName);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const needTips = !(yield isDirectoryEmptyOrNotExists(targetDir));
|
|
257
|
+
if (needTips) {
|
|
258
|
+
const answers = yield inquirer_1.default.prompt([
|
|
259
|
+
{
|
|
260
|
+
type: 'confirm',
|
|
261
|
+
name: 'confirm',
|
|
262
|
+
message: `下载将覆盖 ${targetDir} 目录下的代码,是否继续?`,
|
|
263
|
+
default: true
|
|
264
|
+
}
|
|
265
|
+
]);
|
|
266
|
+
if (!answers.confirm) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
yield iac_core_1.IAC.init({
|
|
271
|
+
cwd: targetDir,
|
|
272
|
+
getCredential: () => {
|
|
273
|
+
return getCredential(ctx, options);
|
|
274
|
+
},
|
|
275
|
+
polyRepoMode: true
|
|
276
|
+
});
|
|
277
|
+
try {
|
|
278
|
+
yield iac_core_1.IAC.Function.pull({
|
|
279
|
+
cwd: targetDir,
|
|
280
|
+
envId: envId,
|
|
281
|
+
name: serviceName
|
|
282
|
+
}, function (message) {
|
|
283
|
+
trackCallback(message, log);
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (e) {
|
|
287
|
+
trackCallback({
|
|
288
|
+
type: 'error',
|
|
289
|
+
details: `${e.message}`,
|
|
290
|
+
originalError: e
|
|
291
|
+
}, log);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
__decorate([
|
|
297
|
+
(0, decorators_1.InjectParams)(),
|
|
298
|
+
__param(0, (0, decorators_1.CmdContext)()),
|
|
299
|
+
__param(1, (0, decorators_1.EnvId)()),
|
|
300
|
+
__param(2, (0, decorators_1.Log)()),
|
|
301
|
+
__param(3, (0, decorators_1.ArgsOptions)()),
|
|
302
|
+
__metadata("design:type", Function),
|
|
303
|
+
__metadata("design:paramtypes", [Object, Object, decorators_1.Logger, Object]),
|
|
304
|
+
__metadata("design:returntype", Promise)
|
|
305
|
+
], CloudFunctionDownloadCommand.prototype, "execute", null);
|
|
306
|
+
CloudFunctionDownloadCommand = __decorate([
|
|
307
|
+
(0, common_1.ICommand)()
|
|
308
|
+
], CloudFunctionDownloadCommand);
|
|
309
|
+
exports.CloudFunctionDownloadCommand = CloudFunctionDownloadCommand;
|
|
310
|
+
let CloudFunctionRunCommand = class CloudFunctionRunCommand extends common_1.Command {
|
|
311
|
+
get options() {
|
|
312
|
+
return {
|
|
313
|
+
cmd: 'cloudfunction',
|
|
314
|
+
childCmd: 'run',
|
|
315
|
+
options: [
|
|
316
|
+
{
|
|
317
|
+
flags: '--source <source>',
|
|
318
|
+
desc: `目标函数文件所在目录路径,默认为当前路径
|
|
319
|
+
`
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
flags: '--port <port>',
|
|
323
|
+
desc: `监听的端口,默认为 3000
|
|
324
|
+
`
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
flags: '-w, --watch',
|
|
328
|
+
desc: `是否启用热重启模式,如启用,将会在文件变更时自动重启服务,默认为 false
|
|
329
|
+
`
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
requiredEnvId: false,
|
|
333
|
+
desc: '本地运行云函数代码'
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
execute(logger, ctx, options) {
|
|
337
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
338
|
+
const args = process.argv.slice(2);
|
|
339
|
+
const watchFlag = ['--watch', '-w'];
|
|
340
|
+
const defaultIgnoreFiles = ['logs/*.*'];
|
|
341
|
+
const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(process.cwd()));
|
|
342
|
+
const credential = yield getCredential(ctx, options);
|
|
343
|
+
process.env.TCB_ENV = envConfig.envId;
|
|
344
|
+
process.env.TENCENTCLOUD_SECRETID = credential.secretId;
|
|
345
|
+
process.env.TENCENTCLOUD_SECRETKEY = credential.secretKey;
|
|
346
|
+
process.env.TENCENTCLOUD_SESSIONTOKEN = credential.token;
|
|
347
|
+
if (watchFlag.some((flag) => args.includes(flag))) {
|
|
348
|
+
const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
|
|
349
|
+
(0, nodemon_1.default)({
|
|
350
|
+
script: '',
|
|
351
|
+
exec: `${process.argv[1]} ${cmd}`,
|
|
352
|
+
watchOptions: {
|
|
353
|
+
usePolling: true,
|
|
354
|
+
ignorePermissionErrors: true,
|
|
355
|
+
ignored: defaultIgnoreFiles.join(','),
|
|
356
|
+
persistent: true,
|
|
357
|
+
interval: 500
|
|
358
|
+
}
|
|
359
|
+
})
|
|
360
|
+
.on('start', () => {
|
|
361
|
+
logger.info('Initializing server in watch mode. Changes in source files will trigger a restart.');
|
|
362
|
+
})
|
|
363
|
+
.on('quit', (e) => {
|
|
364
|
+
logger.info(`Nodemon quit with code ${e}.`);
|
|
365
|
+
process.exit(0);
|
|
366
|
+
})
|
|
367
|
+
.on('restart', (e) => {
|
|
368
|
+
var _a, _b;
|
|
369
|
+
logger.info(`Server restarted due to changed files: ${(_b = (_a = e === null || e === void 0 ? void 0 : e.matched) === null || _a === void 0 ? void 0 : _a.result) === null || _b === void 0 ? void 0 : _b.join(', ')}`);
|
|
370
|
+
})
|
|
371
|
+
.on('log', (e) => {
|
|
372
|
+
logger.info(`[nodemon ${e.type}] ${e.message}`);
|
|
373
|
+
})
|
|
374
|
+
.on('crash', () => {
|
|
375
|
+
logger.error(`Server crashed.`);
|
|
376
|
+
process.exit(1);
|
|
377
|
+
})
|
|
378
|
+
.on('exit', (e) => {
|
|
379
|
+
logger.info(`Server exited with code ${e}.`);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
(0, functions_framework_1.runCLI)();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
__decorate([
|
|
389
|
+
(0, decorators_1.InjectParams)(),
|
|
390
|
+
__param(0, (0, decorators_1.Log)()),
|
|
391
|
+
__param(1, (0, decorators_1.CmdContext)()),
|
|
392
|
+
__param(2, (0, decorators_1.ArgsOptions)()),
|
|
393
|
+
__metadata("design:type", Function),
|
|
394
|
+
__metadata("design:paramtypes", [decorators_1.Logger, Object, Object]),
|
|
395
|
+
__metadata("design:returntype", Promise)
|
|
396
|
+
], CloudFunctionRunCommand.prototype, "execute", null);
|
|
397
|
+
CloudFunctionRunCommand = __decorate([
|
|
398
|
+
(0, common_1.ICommand)()
|
|
399
|
+
], CloudFunctionRunCommand);
|
|
400
|
+
exports.CloudFunctionRunCommand = CloudFunctionRunCommand;
|
|
401
|
+
function _selectEnv() {
|
|
402
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
403
|
+
return (0, utils_2.selectEnv)({ source: [constants_1.EnvSource.MINIAPP, constants_1.EnvSource.QCLOUD] });
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function _inputServiceName(defaultVal = '') {
|
|
407
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
408
|
+
const questions = [
|
|
409
|
+
{
|
|
410
|
+
type: 'input',
|
|
411
|
+
name: 'serviceName',
|
|
412
|
+
message: '请输入服务名称',
|
|
413
|
+
default: defaultVal,
|
|
414
|
+
validate: (val) => {
|
|
415
|
+
const isValid = !val.startsWith('lcap') &&
|
|
416
|
+
!val.startsWith('lowcode') &&
|
|
417
|
+
/^[A-Za-z][\w-_]{0,43}[A-Za-z0-9]$/.test(val);
|
|
418
|
+
return isValid
|
|
419
|
+
? true
|
|
420
|
+
: '支持大小写字母、数字、-和_,但必须以字母开头、以字母和数字结尾,不支持以lcap、lowcode开头,最长45个字符';
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
];
|
|
424
|
+
const answers = yield inquirer_1.default.prompt(questions);
|
|
425
|
+
return answers['serviceName'];
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
function getCredential(ctx, options) {
|
|
429
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
430
|
+
let credential;
|
|
431
|
+
if (ctx.hasPrivateSettings) {
|
|
432
|
+
process.env.IS_PRIVATE = 'true';
|
|
433
|
+
const privateSettings = (0, utils_1.getPrivateSettings)(ctx.config, options.cmd);
|
|
434
|
+
credential = privateSettings === null || privateSettings === void 0 ? void 0 : privateSettings.credential;
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
credential = yield utils_1.authSupevisor.getLoginState();
|
|
438
|
+
}
|
|
439
|
+
return credential;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
function isDirectoryEmptyOrNotExists(dirPath) {
|
|
443
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
444
|
+
try {
|
|
445
|
+
const exists = yield fs_extra_1.default.pathExists(dirPath);
|
|
446
|
+
if (!exists) {
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
const files = yield fs_extra_1.default.readdir(dirPath);
|
|
450
|
+
return files.length === 0;
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
return true;
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
function trackCallback(message, log) {
|
|
458
|
+
if (message.type === 'error') {
|
|
459
|
+
log.error(message.details);
|
|
460
|
+
}
|
|
461
|
+
else {
|
|
462
|
+
log.info(message.details);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./base"), exports);
|
package/lib/commands/fun/base.js
CHANGED
|
@@ -168,15 +168,7 @@ let FunDeployCommand = class FunDeployCommand extends common_1.Command {
|
|
|
168
168
|
}
|
|
169
169
|
else {
|
|
170
170
|
if (!(loadResult === null || loadResult === void 0 ? void 0 : loadResult.userFunction)) {
|
|
171
|
-
|
|
172
|
-
log.error(`${source} 不是一个有效的函数式托管代码目录,可以通过 --source <source> 指定代码目录路径`);
|
|
173
|
-
}
|
|
174
|
-
else if (loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason.includes('is not defined in the provided module')) {
|
|
175
|
-
log.error(`主文件并未导出目标函数 ${target},请导出 ${target} 目标函数`);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
log.error(loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason);
|
|
179
|
-
}
|
|
171
|
+
log.error(`验证加载云函数失败: ${loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason}`);
|
|
180
172
|
return;
|
|
181
173
|
}
|
|
182
174
|
}
|
package/lib/commands/index.js
CHANGED
|
@@ -148,22 +148,14 @@ let RunfDeployCommand = class RunfDeployCommand extends common_1.Command {
|
|
|
148
148
|
if (Array.isArray(loadResult)) {
|
|
149
149
|
for (const loadItem of loadResult) {
|
|
150
150
|
if (!(loadItem === null || loadItem === void 0 ? void 0 : loadItem.userFunction)) {
|
|
151
|
-
log.error(
|
|
151
|
+
log.error(`验证加载函数 ${loadItem === null || loadItem === void 0 ? void 0 : loadItem.name} 失败: "${loadItem === null || loadItem === void 0 ? void 0 : loadItem.reason}"`);
|
|
152
152
|
return;
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
if (!(loadResult === null || loadResult === void 0 ? void 0 : loadResult.userFunction)) {
|
|
158
|
-
|
|
159
|
-
log.error(`${targetDir} 不是一个有效的函数式托管代码目录,可以通过 --source <source> 指定代码目录路径`);
|
|
160
|
-
}
|
|
161
|
-
else if (loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason.includes('is not defined in the provided module')) {
|
|
162
|
-
log.error(`主文件并未导出目标函数 ${target},请导出 ${target} 目标函数`);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
log.error(loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason);
|
|
166
|
-
}
|
|
158
|
+
log.error(`验证加载云函数失败: ${loadResult === null || loadResult === void 0 ? void 0 : loadResult.reason}`);
|
|
167
159
|
return;
|
|
168
160
|
}
|
|
169
161
|
}
|
|
@@ -181,13 +173,8 @@ let RunfDeployCommand = class RunfDeployCommand extends common_1.Command {
|
|
|
181
173
|
log.info(`当前环境 Id:${envId}`);
|
|
182
174
|
}
|
|
183
175
|
if (!serviceName) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const pkg = yield fs_extra_1.default.readJSON(path_1.default.join(targetDir, 'package.json'));
|
|
187
|
-
pkgName = pkg.name;
|
|
188
|
-
}
|
|
189
|
-
catch (e) { }
|
|
190
|
-
serviceName = yield _inputServiceName(pkgName);
|
|
176
|
+
const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
|
|
177
|
+
serviceName = yield _inputServiceName(shortName);
|
|
191
178
|
}
|
|
192
179
|
const answers = yield inquirer_1.default.prompt([
|
|
193
180
|
{
|
|
@@ -323,14 +310,9 @@ let RunfDownloadCommand = class RunfDownloadCommand extends common_1.Command {
|
|
|
323
310
|
log.info(`当前环境 Id:${envId}`);
|
|
324
311
|
}
|
|
325
312
|
if (!serviceName) {
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
pkgName = pkg.name;
|
|
330
|
-
}
|
|
331
|
-
catch (e) { }
|
|
332
|
-
serviceName = yield _inputServiceName(pkgName);
|
|
333
|
-
if (serviceName !== pkgName) {
|
|
313
|
+
const { shortName } = yield (0, utils_2.getPackageJsonName)(path_1.default.join(targetDir, 'package.json'));
|
|
314
|
+
serviceName = yield _inputServiceName(shortName);
|
|
315
|
+
if (serviceName !== shortName) {
|
|
334
316
|
targetDir = path_1.default.join(targetDir, serviceName);
|
|
335
317
|
}
|
|
336
318
|
}
|
|
@@ -462,13 +444,15 @@ let RunfRunCommand = class RunfRunCommand extends common_1.Command {
|
|
|
462
444
|
const args = process.argv.slice(2);
|
|
463
445
|
const watchFlag = ['--watch', '-w'];
|
|
464
446
|
const defaultIgnoreFiles = ['logs/*.*'];
|
|
447
|
+
const envConfig = (0, camelcase_keys_1.default)(yield iac_core_1.utils.loadEnv(process.cwd()));
|
|
465
448
|
const credential = yield getCredential(ctx, options);
|
|
466
449
|
process.env.EXTENDED_CONTEXT = JSON.stringify({
|
|
467
450
|
tmpSecret: {
|
|
468
451
|
secretId: credential.secretId,
|
|
469
452
|
secretKey: credential.secretKey,
|
|
470
453
|
token: credential.token
|
|
471
|
-
}
|
|
454
|
+
},
|
|
455
|
+
envId: envConfig.envId
|
|
472
456
|
});
|
|
473
457
|
if (watchFlag.some((flag) => args.includes(flag))) {
|
|
474
458
|
const cmd = args.filter((arg) => !watchFlag.includes(arg)).join(' ');
|
package/lib/commands/utils.js
CHANGED
|
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.selectEnv = void 0;
|
|
15
|
+
exports.getPackageJsonName = exports.selectEnv = void 0;
|
|
16
16
|
const lodash_1 = require("lodash");
|
|
17
17
|
const env_1 = require("../env");
|
|
18
18
|
const constants_1 = require("./constants");
|
|
19
19
|
const inquirer_1 = __importDefault(require("inquirer"));
|
|
20
20
|
const utils_1 = require("../utils");
|
|
21
|
+
const fs_1 = require("@cloudbase/iac-core/lib/src/fs");
|
|
21
22
|
function selectEnv(options = {}) {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
24
|
const loading = (0, utils_1.loadingFactory)();
|
|
@@ -45,3 +46,16 @@ function selectEnv(options = {}) {
|
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
exports.selectEnv = selectEnv;
|
|
49
|
+
function getPackageJsonName(pkgPath) {
|
|
50
|
+
var _a;
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const pkg = yield (0, fs_1.safeReadJSON)(pkgPath);
|
|
53
|
+
const parts = ((_a = pkg.name) === null || _a === void 0 ? void 0 : _a.split('/')) || [];
|
|
54
|
+
const pkgName = parts.length > 1 ? parts[parts.length - 1] : parts[0];
|
|
55
|
+
return {
|
|
56
|
+
fullName: pkg.name,
|
|
57
|
+
shortName: pkgName
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
exports.getPackageJsonName = getPackageJsonName;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/cli",
|
|
3
|
-
"version": "2.6.
|
|
3
|
+
"version": "2.6.10",
|
|
4
4
|
"description": "cli tool for cloudbase",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@cloudbase/cloud-api": "^0.5.5",
|
|
35
35
|
"@cloudbase/framework-core": "^1.9.7",
|
|
36
36
|
"@cloudbase/functions-framework": "^1.5.0",
|
|
37
|
-
"@cloudbase/iac-core": "^0.0.3-alpha.
|
|
37
|
+
"@cloudbase/iac-core": "^0.0.3-alpha.6",
|
|
38
38
|
"@cloudbase/lowcode-cli": "^0.22.0",
|
|
39
39
|
"@cloudbase/manager-node": "4.2.8",
|
|
40
40
|
"@cloudbase/toolbox": "^0.7.5",
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Logger } from '../../decorators';
|
|
2
|
+
import { Command } from '../common';
|
|
3
|
+
export declare class CloudFunctionListCommand extends Command {
|
|
4
|
+
get options(): {
|
|
5
|
+
cmd: string;
|
|
6
|
+
childCmd: string;
|
|
7
|
+
options: {
|
|
8
|
+
flags: string;
|
|
9
|
+
desc: string;
|
|
10
|
+
}[];
|
|
11
|
+
requiredEnvId: boolean;
|
|
12
|
+
autoRunLogin: boolean;
|
|
13
|
+
desc: string;
|
|
14
|
+
};
|
|
15
|
+
execute(envId: any, log: Logger): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class CloudFunctionDeployCommand extends Command {
|
|
18
|
+
get options(): {
|
|
19
|
+
cmd: string;
|
|
20
|
+
childCmd: string;
|
|
21
|
+
options: {
|
|
22
|
+
flags: string;
|
|
23
|
+
desc: string;
|
|
24
|
+
}[];
|
|
25
|
+
requiredEnvId: boolean;
|
|
26
|
+
autoRunLogin: boolean;
|
|
27
|
+
desc: string;
|
|
28
|
+
};
|
|
29
|
+
execute(ctx: any, envId: any, log: Logger, options: any): Promise<void>;
|
|
30
|
+
}
|
|
31
|
+
export declare class CloudFunctionDownloadCommand extends Command {
|
|
32
|
+
get options(): {
|
|
33
|
+
cmd: string;
|
|
34
|
+
childCmd: string;
|
|
35
|
+
options: {
|
|
36
|
+
flags: string;
|
|
37
|
+
desc: string;
|
|
38
|
+
}[];
|
|
39
|
+
requiredEnvId: boolean;
|
|
40
|
+
autoRunLogin: boolean;
|
|
41
|
+
desc: string;
|
|
42
|
+
};
|
|
43
|
+
execute(ctx: any, envId: any, log: Logger, options: any): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
export declare class CloudFunctionRunCommand extends Command {
|
|
46
|
+
get options(): {
|
|
47
|
+
cmd: string;
|
|
48
|
+
childCmd: string;
|
|
49
|
+
options: {
|
|
50
|
+
flags: string;
|
|
51
|
+
desc: string;
|
|
52
|
+
}[];
|
|
53
|
+
requiredEnvId: boolean;
|
|
54
|
+
desc: string;
|
|
55
|
+
};
|
|
56
|
+
execute(logger: Logger, ctx: any, options: any): Promise<void>;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base';
|