@cloudbase/cli 2.10.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.
- package/lib/auth/login.js +51 -65
- package/lib/auth/logout.js +3 -14
- package/lib/commands/account/login.js +136 -149
- package/lib/commands/account/logout.js +3 -14
- package/lib/commands/ag/base.js +203 -0
- package/lib/commands/ag/create.js +301 -0
- package/lib/commands/ag/debug/index.html +699 -0
- package/lib/commands/ag/delete.js +200 -0
- package/lib/commands/ag/deploy.js +185 -0
- package/lib/commands/ag/detail.js +113 -0
- package/lib/commands/ag/index.js +22 -0
- package/lib/commands/ag/list.js +155 -0
- package/lib/commands/ag/run.js +644 -0
- package/lib/commands/ai/index.js +76 -95
- package/lib/commands/cloudfunction/base.js +182 -203
- package/lib/commands/cloudrun/base.js +578 -603
- package/lib/commands/common.js +48 -63
- package/lib/commands/config/delete.js +16 -27
- package/lib/commands/config/get.js +13 -24
- package/lib/commands/config/list.js +16 -27
- package/lib/commands/config/set.js +33 -44
- package/lib/commands/db/base.js +221 -240
- package/lib/commands/env/base.js +36 -49
- package/lib/commands/env/domain.js +79 -94
- package/lib/commands/env/login.js +120 -135
- package/lib/commands/framework/index.js +32 -49
- package/lib/commands/fun/base.js +223 -244
- package/lib/commands/functions/alias/getRoute.js +33 -44
- package/lib/commands/functions/alias/setRoute.js +36 -47
- package/lib/commands/functions/code-download.js +43 -54
- package/lib/commands/functions/code-update.js +23 -34
- package/lib/commands/functions/concurrency/delete.js +11 -22
- package/lib/commands/functions/concurrency/list.js +20 -31
- package/lib/commands/functions/concurrency/set.js +13 -24
- package/lib/commands/functions/config-update.js +30 -41
- package/lib/commands/functions/copy.js +12 -23
- package/lib/commands/functions/delete.js +30 -41
- package/lib/commands/functions/deploy.js +184 -202
- package/lib/commands/functions/detail.js +23 -34
- package/lib/commands/functions/invoke.js +69 -75
- package/lib/commands/functions/layer/bind.js +102 -105
- package/lib/commands/functions/layer/create.js +29 -35
- package/lib/commands/functions/layer/delete.js +42 -48
- package/lib/commands/functions/layer/download.js +52 -58
- package/lib/commands/functions/layer/list.js +44 -50
- package/lib/commands/functions/layer/sort.js +39 -45
- package/lib/commands/functions/list.js +25 -36
- package/lib/commands/functions/log.js +65 -73
- package/lib/commands/functions/run.js +118 -116
- package/lib/commands/functions/trigger-create.js +32 -43
- package/lib/commands/functions/trigger-delete.js +50 -61
- package/lib/commands/functions/version/list.js +29 -40
- package/lib/commands/functions/version/publish.js +11 -22
- package/lib/commands/gateway/create.js +50 -61
- package/lib/commands/gateway/delete.js +38 -49
- package/lib/commands/gateway/domain.js +65 -80
- package/lib/commands/gateway/list.js +31 -42
- package/lib/commands/gateway/switch.js +48 -61
- package/lib/commands/helpers/init.js +226 -249
- package/lib/commands/helpers/new.js +35 -46
- package/lib/commands/helpers/open.js +22 -33
- package/lib/commands/hosting/hosting.js +157 -178
- package/lib/commands/index.js +1 -0
- package/lib/commands/lowcode/app.js +114 -144
- package/lib/commands/lowcode/comps.js +136 -127
- package/lib/commands/lowcode/utils.js +11 -22
- package/lib/commands/pull/pull.js +33 -46
- package/lib/commands/run/delete.js +35 -46
- package/lib/commands/run/image/delete.js +32 -39
- package/lib/commands/run/image/download.js +26 -33
- package/lib/commands/run/image/list.js +41 -48
- package/lib/commands/run/image/upload.js +26 -33
- package/lib/commands/run/list.js +32 -43
- package/lib/commands/run/service/config.js +17 -28
- package/lib/commands/run/service/deploy.js +15 -26
- package/lib/commands/run/service/list.js +48 -59
- package/lib/commands/run/service/update.js +7 -18
- package/lib/commands/run/standalonegateway/create.js +35 -42
- package/lib/commands/run/standalonegateway/destroy.js +23 -30
- package/lib/commands/run/standalonegateway/list.js +19 -26
- package/lib/commands/run/standalonegateway/package.js +31 -38
- package/lib/commands/run/standalonegateway/turn.js +27 -34
- package/lib/commands/run/version/create.js +198 -205
- package/lib/commands/run/version/delete.js +31 -38
- package/lib/commands/run/version/list.js +42 -49
- package/lib/commands/run/version/modify.js +27 -34
- package/lib/commands/run/version/update.js +201 -208
- package/lib/commands/runf/base.js +216 -237
- package/lib/commands/self-update.js +59 -72
- package/lib/commands/smart.js +66 -79
- package/lib/commands/storage/storage.js +192 -219
- package/lib/commands/third/thirdAttach.js +16 -27
- package/lib/commands/utils.js +119 -149
- package/lib/db/index.js +48 -67
- package/lib/decorators/captureError.js +10 -21
- package/lib/decorators/guard.js +11 -22
- package/lib/decorators/injectParams.js +29 -40
- package/lib/decorators/params/common.js +5 -2
- package/lib/decorators/params/index.js +3 -12
- package/lib/env/domain.js +13 -28
- package/lib/env/index.js +25 -44
- package/lib/env/login.js +30 -45
- package/lib/function/alias.js +31 -44
- package/lib/function/base.js +187 -215
- package/lib/function/code.js +8 -19
- package/lib/function/concurrency.js +43 -58
- package/lib/function/create.js +43 -53
- package/lib/function/delete.js +22 -35
- package/lib/function/layer/attach.js +33 -46
- package/lib/function/layer/create.js +34 -45
- package/lib/function/layer/delete.js +5 -16
- package/lib/function/layer/download.js +11 -22
- package/lib/function/layer/list.js +12 -25
- package/lib/function/layer/sort.js +6 -17
- package/lib/function/trigger.js +65 -82
- package/lib/function/update.js +24 -32
- package/lib/function/version.js +29 -42
- package/lib/function/vpc.js +12 -25
- package/lib/gateway/index.js +77 -104
- package/lib/hosting.js +157 -188
- package/lib/run/delete.js +3 -12
- package/lib/run/image/build.js +6 -15
- package/lib/run/image/delete.js +3 -12
- package/lib/run/image/info.js +3 -12
- package/lib/run/image/list.js +6 -15
- package/lib/run/list.js +19 -30
- package/lib/run/repo.js +6 -15
- package/lib/run/service/common.js +160 -173
- package/lib/run/service/config.js +44 -57
- package/lib/run/service/deployPackage.js +33 -44
- package/lib/run/service/list.js +8 -14
- package/lib/run/service/showLogs.js +69 -90
- package/lib/run/service/update.js +50 -63
- package/lib/run/standalonegateway/create.js +3 -12
- package/lib/run/standalonegateway/destroy.js +3 -12
- package/lib/run/standalonegateway/list.js +3 -12
- package/lib/run/standalonegateway/package/list.js +3 -12
- package/lib/run/standalonegateway/turn/off.js +3 -12
- package/lib/run/standalonegateway/turn/on.js +3 -12
- package/lib/run/version/create.js +41 -31
- package/lib/run/version/delete.js +3 -12
- package/lib/run/version/list.js +3 -12
- package/lib/run/version/modify.js +3 -12
- package/lib/run/version/repo.js +6 -15
- package/lib/run/version/update.js +37 -26
- package/lib/storage.js +62 -93
- package/lib/third/index.js +6 -17
- package/lib/utils/ai/banner.js +49 -60
- package/lib/utils/ai/claudeWindows.js +2 -2
- package/lib/utils/ai/config.js +169 -206
- package/lib/utils/ai/ensureFiles.js +6 -17
- package/lib/utils/ai/env.js +16 -27
- package/lib/utils/ai/envLocalManager.js +35 -52
- package/lib/utils/ai/router.js +927 -1005
- package/lib/utils/ai/setup.js +527 -563
- package/lib/utils/auth.js +3 -14
- package/lib/utils/checkTcbrEnv.js +20 -31
- package/lib/utils/cli-table.js +6 -1
- package/lib/utils/config.js +4 -13
- package/lib/utils/dts.js +98 -113
- package/lib/utils/env.js +154 -175
- package/lib/utils/function-packer.js +29 -42
- package/lib/utils/log.js +10 -21
- package/lib/utils/mcp-config-modifier.js +105 -120
- package/lib/utils/net/cloud-api-request.js +15 -23
- package/lib/utils/net/credential.js +26 -39
- package/lib/utils/net/http-request.js +63 -80
- package/lib/utils/net/manager-service.js +22 -35
- package/lib/utils/notice.js +16 -27
- package/lib/utils/output/loading.js +3 -12
- package/lib/utils/parallel.js +32 -43
- package/lib/utils/platform/mac.js +4 -15
- package/lib/utils/platform/port.js +4 -15
- package/lib/utils/prompt/select.js +6 -15
- package/lib/utils/report.js +28 -33
- package/lib/utils/reporter/agree.js +11 -22
- package/lib/utils/reporter/download.js +17 -28
- package/lib/utils/reporter/usage.js +12 -23
- package/lib/utils/store/auth.js +17 -30
- package/lib/utils/store/config.js +11 -25
- package/lib/utils/store/db.js +17 -36
- package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
- package/lib/utils/template-manager.js +215 -242
- package/lib/utils/template.js +81 -96
- package/lib/utils/tools/common.js +45 -56
- package/lib/utils/tools/time.js +5 -16
- package/lib/utils/url.js +10 -4
- package/package.json +2 -2
- package/specs/ag-command/design.md +421 -0
- package/specs/ag-command/doc.md +204 -0
- package/specs/ag-command/requirements.md +173 -0
- package/specs/ag-command/summary.md +174 -0
- package/specs/ag-command/tasks.md +197 -0
- package/specs/ag-command/usage-guide.md +420 -0
- package/tsconfig.json +1 -1
- package/types/commands/ag/base.d.ts +44 -0
- package/types/commands/ag/create.d.ts +25 -0
- package/types/commands/ag/delete.d.ts +32 -0
- package/types/commands/ag/deploy.d.ts +31 -0
- package/types/commands/ag/detail.d.ts +28 -0
- package/types/commands/ag/index.d.ts +6 -0
- package/types/commands/ag/list.d.ts +35 -0
- package/types/commands/ag/run.d.ts +52 -0
- package/types/commands/cloudrun/base.d.ts +10 -0
- package/types/commands/index.d.ts +1 -0
|
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
16
|
};
|
|
@@ -47,45 +38,43 @@ let DeleteFunction = class DeleteFunction extends common_1.Command {
|
|
|
47
38
|
desc: (0, i18n_1.t)('删除云函数')
|
|
48
39
|
};
|
|
49
40
|
}
|
|
50
|
-
execute(ctx, params) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
41
|
+
async execute(ctx, params) {
|
|
42
|
+
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
43
|
+
const { envId, config: { functions } } = ctx;
|
|
44
|
+
const functionService = await (0, function_1.getFunctionService)(envId);
|
|
45
|
+
let isBatchDelete = false;
|
|
46
|
+
if (!name) {
|
|
47
|
+
const answer = await inquirer_1.default.prompt({
|
|
48
|
+
type: 'confirm',
|
|
49
|
+
name: 'isBatch',
|
|
50
|
+
message: (0, i18n_1.t)('无云函数名称,是否需要删除配置文件中的全部云函数?'),
|
|
51
|
+
default: false
|
|
52
|
+
});
|
|
53
|
+
if (answer.isBatch) {
|
|
54
|
+
const { reConfirm } = await inquirer_1.default.prompt({
|
|
58
55
|
type: 'confirm',
|
|
59
|
-
name: '
|
|
60
|
-
message: (0, i18n_1.t)('
|
|
56
|
+
name: 'reConfirm',
|
|
57
|
+
message: (0, i18n_1.t)('确定要删除配置文件中的全部云函数?'),
|
|
61
58
|
default: false
|
|
62
59
|
});
|
|
63
|
-
|
|
64
|
-
const { reConfirm } = yield inquirer_1.default.prompt({
|
|
65
|
-
type: 'confirm',
|
|
66
|
-
name: 'reConfirm',
|
|
67
|
-
message: (0, i18n_1.t)('确定要删除配置文件中的全部云函数?'),
|
|
68
|
-
default: false
|
|
69
|
-
});
|
|
70
|
-
isBatchDelete = reConfirm;
|
|
71
|
-
}
|
|
72
|
-
if (!isBatchDelete) {
|
|
73
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要删除的云函数名称!'));
|
|
74
|
-
}
|
|
60
|
+
isBatchDelete = reConfirm;
|
|
75
61
|
}
|
|
76
|
-
if (isBatchDelete) {
|
|
77
|
-
|
|
78
|
-
return functionService.batchDeleteFunctions({
|
|
79
|
-
names
|
|
80
|
-
});
|
|
62
|
+
if (!isBatchDelete) {
|
|
63
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要删除的云函数名称!'));
|
|
81
64
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
65
|
+
}
|
|
66
|
+
if (isBatchDelete) {
|
|
67
|
+
const names = functions.map((item) => item.name);
|
|
68
|
+
return functionService.batchDeleteFunctions({
|
|
69
|
+
names
|
|
86
70
|
});
|
|
87
|
-
|
|
71
|
+
}
|
|
72
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
73
|
+
loading.start((0, i18n_1.t)('删除函数 [{{name}}] 中...', { name }));
|
|
74
|
+
await functionService.deleteFunction({
|
|
75
|
+
name
|
|
88
76
|
});
|
|
77
|
+
loading.succeed((0, i18n_1.t)('删除函数 [{{name}}] 成功!', { name }));
|
|
89
78
|
}
|
|
90
79
|
};
|
|
91
80
|
__decorate([
|
|
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
16
|
};
|
|
@@ -77,236 +68,227 @@ let FunctionDeploy = class FunctionDeploy extends common_1.Command {
|
|
|
77
68
|
desc: (0, i18n_1.t)('部署云函数')
|
|
78
69
|
};
|
|
79
70
|
}
|
|
80
|
-
execute(ctx, params, log) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('--dir 参数必须指定为云函数的文件夹路径'));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
let newFunction;
|
|
111
|
-
if (functions && functions.length > 0) {
|
|
112
|
-
newFunction = functions.find((item) => item.name === name);
|
|
71
|
+
async execute(ctx, params, log) {
|
|
72
|
+
const { envId, config, options } = ctx;
|
|
73
|
+
const { functions } = config;
|
|
74
|
+
const { force, codeSecret, path: access, all, dir } = options;
|
|
75
|
+
const functionRootPath = path_1.default.join(process.cwd(), config.functionRoot);
|
|
76
|
+
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
77
|
+
if (access && (0, utils_1.checkFullAccess)(access)) {
|
|
78
|
+
log.warn((0, i18n_1.t)('--path 参数已更换为HTTP 访问服务路径,请使用 --dir 指定部署函数的文件夹路径'));
|
|
79
|
+
}
|
|
80
|
+
if (access && access[0] !== '/') {
|
|
81
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('HTTP 访问服务路径必须以 / 开头'));
|
|
82
|
+
}
|
|
83
|
+
if ((!name && !dir) || all) {
|
|
84
|
+
return this.deployAllFunction({
|
|
85
|
+
all,
|
|
86
|
+
envId,
|
|
87
|
+
force,
|
|
88
|
+
access,
|
|
89
|
+
functions,
|
|
90
|
+
codeSecret,
|
|
91
|
+
functionRootPath
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (dir) {
|
|
95
|
+
(0, utils_1.checkFullAccess)(dir, true);
|
|
96
|
+
if (!(0, utils_1.isDirectory)(dir)) {
|
|
97
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('--dir 参数必须指定为云函数的文件夹路径'));
|
|
113
98
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
}
|
|
100
|
+
let newFunction;
|
|
101
|
+
if (functions && functions.length > 0) {
|
|
102
|
+
newFunction = functions.find((item) => item.name === name);
|
|
103
|
+
}
|
|
104
|
+
if (!newFunction || !newFunction.name) {
|
|
105
|
+
log.info((0, i18n_1.t)('未找到函数发布配置,使用默认配置 => 运行时:Nodejs10.15/在线安装依赖'));
|
|
106
|
+
newFunction = {
|
|
107
|
+
name,
|
|
108
|
+
...constant_1.DefaultFunctionDeployConfig
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
112
|
+
loading.start((0, i18n_1.t)('云函数部署中...'));
|
|
113
|
+
try {
|
|
114
|
+
await (0, function_1.createFunction)({
|
|
115
|
+
force,
|
|
116
|
+
envId,
|
|
117
|
+
codeSecret,
|
|
118
|
+
functionRootPath,
|
|
119
|
+
func: newFunction,
|
|
120
|
+
accessPath: access,
|
|
121
|
+
functionPath: dir
|
|
122
|
+
});
|
|
123
|
+
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功!', { name: newFunction.name }));
|
|
124
|
+
this.printSuccessTips(envId);
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
loading.stop();
|
|
128
|
+
await this.handleDeployFail(e, {
|
|
129
|
+
envId,
|
|
130
|
+
codeSecret,
|
|
131
|
+
functionRootPath,
|
|
132
|
+
func: newFunction,
|
|
133
|
+
accessPath: access,
|
|
134
|
+
functionPath: dir
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (access || newFunction.path) {
|
|
138
|
+
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access || newFunction.path}`);
|
|
139
|
+
console.log((0, i18n_1.t)('\n云函数HTTP 访问服务访问链接:{{link}}', { link }));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async deployAllFunction(options) {
|
|
143
|
+
const { functions = [], envId, force, codeSecret, functionRootPath, all, access } = options;
|
|
144
|
+
if (!all) {
|
|
145
|
+
const { isBatch } = await inquirer_1.default.prompt({
|
|
146
|
+
type: 'confirm',
|
|
147
|
+
name: 'isBatch',
|
|
148
|
+
message: (0, i18n_1.t)('没有指定需要部署的云函数,是否部署配置文件中的全部云函数?'),
|
|
149
|
+
default: false
|
|
150
|
+
});
|
|
151
|
+
if (!isBatch) {
|
|
152
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定需要部署的云函数的名称或通过 --path 参数指定需要部署的函数的路径!'));
|
|
117
153
|
}
|
|
118
|
-
|
|
119
|
-
|
|
154
|
+
}
|
|
155
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
156
|
+
const tasks = functions.map((func) => async () => {
|
|
157
|
+
loading.start((0, i18n_1.t)('云函数部署中'));
|
|
120
158
|
try {
|
|
121
|
-
|
|
122
|
-
|
|
159
|
+
await (0, function_1.createFunction)({
|
|
160
|
+
func,
|
|
123
161
|
envId,
|
|
162
|
+
force,
|
|
124
163
|
codeSecret,
|
|
125
164
|
functionRootPath,
|
|
126
|
-
|
|
127
|
-
accessPath: access,
|
|
128
|
-
functionPath: dir
|
|
165
|
+
accessPath: access
|
|
129
166
|
});
|
|
130
|
-
loading.succeed((0, i18n_1.t)('[{{name}}]
|
|
131
|
-
this.printSuccessTips(envId);
|
|
167
|
+
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数部署成功', { name: func.name }));
|
|
132
168
|
}
|
|
133
169
|
catch (e) {
|
|
134
170
|
loading.stop();
|
|
135
|
-
|
|
171
|
+
await this.handleDeployFail(e, {
|
|
172
|
+
func,
|
|
136
173
|
envId,
|
|
137
174
|
codeSecret,
|
|
138
175
|
functionRootPath,
|
|
139
|
-
|
|
140
|
-
accessPath: access,
|
|
141
|
-
functionPath: dir
|
|
176
|
+
accessPath: access
|
|
142
177
|
});
|
|
143
178
|
}
|
|
144
|
-
if (access || newFunction.path) {
|
|
145
|
-
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${access || newFunction.path}`);
|
|
146
|
-
console.log((0, i18n_1.t)('\n云函数HTTP 访问服务访问链接:{{link}}', { link }));
|
|
147
|
-
}
|
|
148
179
|
});
|
|
180
|
+
if (tasks.length > 5) {
|
|
181
|
+
utils_1.logger.info((0, i18n_1.t)('函数数量较多,将使用队列部署'));
|
|
182
|
+
}
|
|
183
|
+
const asyncTaskController = new utils_1.AsyncTaskParallelController(5, 50);
|
|
184
|
+
asyncTaskController.loadTasks(tasks);
|
|
185
|
+
const results = await asyncTaskController.run();
|
|
186
|
+
const success = results.filter((_) => !_);
|
|
187
|
+
utils_1.logger.success((0, i18n_1.t)('成功部署 {{count}} 个函数', { count: success === null || success === void 0 ? void 0 : success.length }));
|
|
188
|
+
const err = results.filter((_) => _);
|
|
189
|
+
(err === null || err === void 0 ? void 0 : err.length) && utils_1.logger.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: err === null || err === void 0 ? void 0 : err.length }));
|
|
149
190
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
const loading = (0, utils_1.loadingFactory)();
|
|
165
|
-
const tasks = functions.map((func) => () => __awaiter(this, void 0, void 0, function* () {
|
|
166
|
-
loading.start((0, i18n_1.t)('云函数部署中'));
|
|
191
|
+
async handleDeployFail(e, options) {
|
|
192
|
+
const { envId, codeSecret, functionRootPath, func, functionPath, accessPath } = options;
|
|
193
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
194
|
+
if (e.code === 'ResourceInUse.FunctionName' || e.code === 'ResourceInUse.Function') {
|
|
195
|
+
const { force } = await inquirer_1.default.prompt({
|
|
196
|
+
type: 'confirm',
|
|
197
|
+
name: 'force',
|
|
198
|
+
message: (0, i18n_1.t)('存在同名云函数:[{{name}}],是否覆盖原函数代码与配置', { name: func.name }),
|
|
199
|
+
default: false
|
|
200
|
+
});
|
|
201
|
+
const { triggers } = func;
|
|
202
|
+
if (force) {
|
|
203
|
+
loading.start((0, i18n_1.t)('云函数更新部署中...'));
|
|
167
204
|
try {
|
|
168
|
-
|
|
205
|
+
await (0, function_2.updateFunctionCode)({
|
|
169
206
|
func,
|
|
170
207
|
envId,
|
|
171
|
-
force,
|
|
172
208
|
codeSecret,
|
|
173
|
-
functionRootPath
|
|
174
|
-
|
|
209
|
+
functionRootPath
|
|
210
|
+
});
|
|
211
|
+
await this.waitForFunctionReady(envId, func.name, loading);
|
|
212
|
+
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
|
|
213
|
+
await (0, function_2.updateFunctionConfig)({
|
|
214
|
+
envId,
|
|
215
|
+
functionName: func.name,
|
|
216
|
+
config: func
|
|
175
217
|
});
|
|
176
|
-
loading.succeed((0, i18n_1.t)('[{{name}}]
|
|
218
|
+
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
|
|
219
|
+
await this.printSuccessTips(envId);
|
|
177
220
|
}
|
|
178
221
|
catch (e) {
|
|
179
222
|
loading.stop();
|
|
180
|
-
|
|
181
|
-
func,
|
|
182
|
-
envId,
|
|
183
|
-
codeSecret,
|
|
184
|
-
functionRootPath,
|
|
185
|
-
accessPath: access
|
|
186
|
-
});
|
|
223
|
+
throw e;
|
|
187
224
|
}
|
|
188
|
-
|
|
189
|
-
if (tasks.length > 5) {
|
|
190
|
-
utils_1.logger.info((0, i18n_1.t)('函数数量较多,将使用队列部署'));
|
|
225
|
+
return;
|
|
191
226
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const results = yield asyncTaskController.run();
|
|
195
|
-
const success = results.filter((_) => !_);
|
|
196
|
-
utils_1.logger.success((0, i18n_1.t)('成功部署 {{count}} 个函数', { count: success === null || success === void 0 ? void 0 : success.length }));
|
|
197
|
-
const err = results.filter((_) => _);
|
|
198
|
-
(err === null || err === void 0 ? void 0 : err.length) && utils_1.logger.error((0, i18n_1.t)('{{count}} 个云函数部署失败', { count: err === null || err === void 0 ? void 0 : err.length }));
|
|
199
|
-
});
|
|
227
|
+
}
|
|
228
|
+
throw e;
|
|
200
229
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
envId,
|
|
219
|
-
codeSecret,
|
|
220
|
-
functionRootPath
|
|
221
|
-
});
|
|
222
|
-
yield this.waitForFunctionReady(envId, func.name, loading);
|
|
223
|
-
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数配置更新中...', { name: func.name }));
|
|
224
|
-
yield (0, function_2.updateFunctionConfig)({
|
|
225
|
-
envId,
|
|
226
|
-
functionName: func.name,
|
|
227
|
-
config: func
|
|
228
|
-
});
|
|
229
|
-
loading.succeed((0, i18n_1.t)('[{{name}}] 云函数更新成功!', { name: func.name }));
|
|
230
|
-
yield this.printSuccessTips(envId);
|
|
230
|
+
async waitForFunctionReady(envId, functionName, loading, timeoutMinutes = 5) {
|
|
231
|
+
const scfService = await (0, function_2.getFunctionService)(envId);
|
|
232
|
+
const timeoutMs = timeoutMinutes * 60 * 1000;
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
let intervalId = null;
|
|
235
|
+
const timeoutId = setTimeout(() => {
|
|
236
|
+
clearInterval(intervalId);
|
|
237
|
+
reject(new error_1.CloudBaseError((0, i18n_1.t)('[{{functionName}}] 等待函数更新超时,已等待 {{timeoutMinutes}} 分钟', { functionName, timeoutMinutes })));
|
|
238
|
+
}, timeoutMs);
|
|
239
|
+
intervalId = setInterval(async () => {
|
|
240
|
+
try {
|
|
241
|
+
const functionInfo = await scfService.getFunctionDetail(functionName);
|
|
242
|
+
if ((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) === 'Active') {
|
|
243
|
+
clearTimeout(timeoutId);
|
|
244
|
+
clearInterval(intervalId);
|
|
245
|
+
loading.succeed((0, i18n_1.t)('[{{functionName}}] 云函数代码已更新!', { functionName }));
|
|
246
|
+
resolve();
|
|
231
247
|
}
|
|
232
|
-
|
|
233
|
-
loading.
|
|
234
|
-
throw e;
|
|
248
|
+
else {
|
|
249
|
+
loading.text = (0, i18n_1.t)('正在更新[{{functionName}}] 云函数代码... 当前状态: {{status}}', { functionName, status: (functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) || (0, i18n_1.t)('未知') });
|
|
235
250
|
}
|
|
236
|
-
return;
|
|
237
251
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
waitForFunctionReady(envId, functionName, loading, timeoutMinutes = 5) {
|
|
243
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
-
const scfService = yield (0, function_2.getFunctionService)(envId);
|
|
245
|
-
const timeoutMs = timeoutMinutes * 60 * 1000;
|
|
246
|
-
return new Promise((resolve, reject) => {
|
|
247
|
-
let intervalId = null;
|
|
248
|
-
const timeoutId = setTimeout(() => {
|
|
249
|
-
clearInterval(intervalId);
|
|
250
|
-
reject(new error_1.CloudBaseError((0, i18n_1.t)('[{{functionName}}] 等待函数更新超时,已等待 {{timeoutMinutes}} 分钟', { functionName, timeoutMinutes })));
|
|
251
|
-
}, timeoutMs);
|
|
252
|
-
intervalId = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
253
|
-
try {
|
|
254
|
-
const functionInfo = yield scfService.getFunctionDetail(functionName);
|
|
255
|
-
if ((functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) === 'Active') {
|
|
256
|
-
clearTimeout(timeoutId);
|
|
257
|
-
clearInterval(intervalId);
|
|
258
|
-
loading.succeed((0, i18n_1.t)('[{{functionName}}] 云函数代码已更新!', { functionName }));
|
|
259
|
-
resolve();
|
|
260
|
-
}
|
|
261
|
-
else {
|
|
262
|
-
loading.text = (0, i18n_1.t)('正在更新[{{functionName}}] 云函数代码... 当前状态: {{status}}', { functionName, status: (functionInfo === null || functionInfo === void 0 ? void 0 : functionInfo.Status) || (0, i18n_1.t)('未知') });
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
loading.text = (0, i18n_1.t)('获取[{{functionName}}] 云函数状态失败,重试中...', { functionName });
|
|
267
|
-
}
|
|
268
|
-
}), 2000);
|
|
269
|
-
});
|
|
252
|
+
catch (error) {
|
|
253
|
+
loading.text = (0, i18n_1.t)('获取[{{functionName}}] 云函数状态失败,重试中...', { functionName });
|
|
254
|
+
}
|
|
255
|
+
}, 2000);
|
|
270
256
|
});
|
|
271
257
|
}
|
|
272
|
-
printSuccessTips(envId, log) {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
log.info((0, i18n_1.t)('使用 {{command}} 命令查看已部署云函数', { command: (0, utils_1.highlightCommand)('cloudbase functions:list') }));
|
|
281
|
-
});
|
|
258
|
+
async printSuccessTips(envId, log) {
|
|
259
|
+
let url = `${utils_1.EUrl.TcbConsole}/scf?envId=${envId}`;
|
|
260
|
+
const region = await (0, toolbox_1.getRegion)();
|
|
261
|
+
url += `&rid=${regionIdMap[region]}`;
|
|
262
|
+
const link = (0, utils_1.genClickableLink)(url);
|
|
263
|
+
log.breakLine();
|
|
264
|
+
log.info((0, i18n_1.t)('控制台查看函数详情或创建HTTP 访问服务链接 🔗:{{link}}', { link }));
|
|
265
|
+
log.info((0, i18n_1.t)('使用 {{command}} 命令查看已部署云函数', { command: (0, utils_1.highlightCommand)('cloudbase functions:list') }));
|
|
282
266
|
}
|
|
283
|
-
genApiGateway(envId, name) {
|
|
267
|
+
async genApiGateway(envId, name) {
|
|
284
268
|
var _a, _b;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
269
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
270
|
+
const res = await (0, gateway_1.queryGateway)({
|
|
271
|
+
name,
|
|
272
|
+
envId
|
|
273
|
+
});
|
|
274
|
+
if ((res === null || res === void 0 ? void 0 : res.EnableService) === false)
|
|
275
|
+
return;
|
|
276
|
+
loading.start((0, i18n_1.t)('生成云函数HTTP 访问服务中...'));
|
|
277
|
+
let path;
|
|
278
|
+
if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
279
|
+
path = (_b = res.APISet[0]) === null || _b === void 0 ? void 0 : _b.Path;
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
path = `/${(0, utils_1.random)(12)}`;
|
|
283
|
+
await (0, gateway_1.createGateway)({
|
|
284
|
+
envId,
|
|
288
285
|
name,
|
|
289
|
-
|
|
286
|
+
path
|
|
290
287
|
});
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
296
|
-
path = (_b = res.APISet[0]) === null || _b === void 0 ? void 0 : _b.Path;
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
path = `/${(0, utils_1.random)(12)}`;
|
|
300
|
-
yield (0, gateway_1.createGateway)({
|
|
301
|
-
envId,
|
|
302
|
-
name,
|
|
303
|
-
path
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
loading.stop();
|
|
307
|
-
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${path}`);
|
|
308
|
-
console.log((0, i18n_1.t)('\n云函数HTTP 访问服务链接:{{link}}', { link }));
|
|
309
|
-
});
|
|
288
|
+
}
|
|
289
|
+
loading.stop();
|
|
290
|
+
const link = (0, utils_1.genClickableLink)(`https://${envId}.service.tcloudbase.com${path}`);
|
|
291
|
+
console.log((0, i18n_1.t)('\n云函数HTTP 访问服务链接:{{link}}', { link }));
|
|
310
292
|
}
|
|
311
293
|
};
|
|
312
294
|
__decorate([
|
|
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
11
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
13
|
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
16
|
};
|
|
@@ -58,32 +49,30 @@ let FunctionDetail = class FunctionDetail extends common_1.Command {
|
|
|
58
49
|
desc: (0, i18n_1.t)('获取云函数信息')
|
|
59
50
|
};
|
|
60
51
|
}
|
|
61
|
-
execute(ctx, params) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 函数不存在', { name }));
|
|
80
|
-
}
|
|
81
|
-
throw e;
|
|
82
|
-
}
|
|
83
|
-
finally {
|
|
84
|
-
loading.stop();
|
|
52
|
+
async execute(ctx, params) {
|
|
53
|
+
const { envId, options } = ctx;
|
|
54
|
+
const { codeSecret } = options;
|
|
55
|
+
const name = params === null || params === void 0 ? void 0 : params[0];
|
|
56
|
+
if (!name) {
|
|
57
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('请指定云函数名称!'));
|
|
58
|
+
}
|
|
59
|
+
const loading = (0, utils_1.loadingFactory)();
|
|
60
|
+
loading.start((0, i18n_1.t)('获取函数信息中...'));
|
|
61
|
+
const functionService = await (0, function_1.getFunctionService)(envId);
|
|
62
|
+
try {
|
|
63
|
+
const data = await functionService.getFunctionDetail(name, codeSecret);
|
|
64
|
+
loading.stop();
|
|
65
|
+
this.logDetail(data, name);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
if (e.code === 'ResourceNotFound.FunctionName') {
|
|
69
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('[{{name}}] 函数不存在', { name }));
|
|
85
70
|
}
|
|
86
|
-
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
loading.stop();
|
|
75
|
+
}
|
|
87
76
|
}
|
|
88
77
|
logDetail(info, name, log) {
|
|
89
78
|
const ResMap = {
|