@vectorx/xhs-cloud-cli 0.6.1 → 1.0.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/bin/rcb.js +47 -157
- package/lib/commands/agent/dev.js +3 -0
- package/lib/commands/auth/login.js +13 -0
- package/lib/commands/env/create.js +156 -0
- package/lib/commands/env/index.js +20 -0
- package/lib/commands/env/info.js +106 -0
- package/lib/commands/env/list.js +93 -0
- package/lib/commands/env/set.js +129 -0
- package/lib/commands/fun/deploy.js +182 -0
- package/lib/commands/fun/dev.js +183 -0
- package/lib/commands/fun/index.js +20 -0
- package/lib/commands/fun/list.js +77 -0
- package/lib/commands/fun/new.js +125 -0
- package/lib/commands/index.js +2 -0
- package/lib/constants/cmd.js +9 -9
- package/lib/core/base.js +75 -1
- package/lib/decorators/auth.js +6 -0
- package/lib/decorators/captureError.js +1 -0
- package/lib/main.js +6 -0
- package/package.json +7 -6
- package/templates/ai-cloud-functions-example/.env.template +1 -0
- package/templates/ai-cloud-functions-example/README.md +277 -0
- package/templates/ai-cloud-functions-example/agent-cloudbase-functions.json +83 -0
- package/templates/ai-cloud-functions-example/package.json +10 -0
- package/templates/ai-cloud-functions-example/src/binary/index.js +207 -0
- package/templates/ai-cloud-functions-example/src/context/context-service.js +94 -0
- package/templates/ai-cloud-functions-example/src/context/index.js +57 -0
- package/templates/ai-cloud-functions-example/src/env/index.js +264 -0
- package/templates/ai-cloud-functions-example/src/form/index.js +138 -0
- package/templates/ai-cloud-functions-example/src/index.js +0 -0
- package/templates/ai-cloud-functions-example/src/json/index.js +194 -0
- package/templates/ai-cloud-functions-example/src/multipart/index.js +189 -0
- package/templates/ai-cloud-functions-example/src/text/index.js +319 -0
- package/templates/ai-cloud-functions-example/src/user/index.js +82 -0
- package/templates/chatbox-agent/project.config.json +2 -2
- package/templates/cloudfunction-template/.env.template +2 -0
- package/templates/cloudfunction-template/agent-cloudbase-functions.json +17 -0
- package/templates/cloudfunction-template/package.json +11 -0
- package/templates/cloudfunction-template/project.config.json +5 -0
- package/templates/cloudfunction-template/src/echo.js +27 -0
- package/templates/cloudfunction-template/src/index.js +34 -0
- package/types/commands/env/create.d.ts +19 -0
- package/types/commands/env/index.d.ts +4 -0
- package/types/commands/env/info.d.ts +14 -0
- package/types/commands/env/list.d.ts +11 -0
- package/types/commands/env/set.d.ts +14 -0
- package/types/commands/fun/deploy.d.ts +14 -0
- package/types/commands/fun/dev.d.ts +14 -0
- package/types/commands/fun/index.d.ts +4 -0
- package/types/commands/fun/list.d.ts +14 -0
- package/types/commands/fun/new.d.ts +16 -0
- package/types/commands/index.d.ts +2 -0
package/bin/rcb.js
CHANGED
|
@@ -5,8 +5,6 @@ const { program } = require("commander");
|
|
|
5
5
|
const logSymbols = require("log-symbols");
|
|
6
6
|
const didYouMean = require("didyoumean");
|
|
7
7
|
const updateNotifier = require("update-notifier");
|
|
8
|
-
const { Confirm } = require("enquirer");
|
|
9
|
-
const execa = require("execa");
|
|
10
8
|
const semver = require("semver");
|
|
11
9
|
const { registerCommands, ALL_COMMANDS } = require("../lib");
|
|
12
10
|
|
|
@@ -32,17 +30,55 @@ async function main() {
|
|
|
32
30
|
process.exit(1);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
// 输出版本信息
|
|
36
|
-
console.log(chalk.gray(`RedCloudBase CLI ${pkg.version}`));
|
|
37
|
-
console.log(`[API Config] Env: ${process.env.AGENT_BUILD_ENV || 'production'}`);
|
|
38
|
-
|
|
39
33
|
const yargsParsedResult = yargsParser(process.argv.slice(2));
|
|
40
34
|
|
|
35
|
+
// 检查是否是版本请求,如果是则自定义输出
|
|
36
|
+
if (process.argv.includes("-V") || process.argv.includes("--version")) {
|
|
37
|
+
const version = pkg.version;
|
|
38
|
+
const isBeta = version.indexOf("-") > -1;
|
|
39
|
+
const versionColor = isBeta ? chalk.yellow : chalk.green;
|
|
40
|
+
|
|
41
|
+
console.log();
|
|
42
|
+
console.log(
|
|
43
|
+
chalk.cyan.bold(" ╭─────────────────────────────────╮")
|
|
44
|
+
);
|
|
45
|
+
console.log(
|
|
46
|
+
chalk.cyan.bold(" │"),
|
|
47
|
+
chalk.white.bold(" rcb"),
|
|
48
|
+
chalk.gray("v"),
|
|
49
|
+
versionColor.bold(version),
|
|
50
|
+
isBeta ? chalk.yellow(" (beta)") : "",
|
|
51
|
+
chalk.cyan.bold(" │")
|
|
52
|
+
);
|
|
53
|
+
console.log(
|
|
54
|
+
chalk.cyan.bold(" │"),
|
|
55
|
+
chalk.gray(" 小红书云服务 CLI"),
|
|
56
|
+
chalk.cyan.bold(" │")
|
|
57
|
+
);
|
|
58
|
+
console.log(
|
|
59
|
+
chalk.cyan.bold(" ╰─────────────────────────────────╯")
|
|
60
|
+
);
|
|
61
|
+
console.log();
|
|
62
|
+
process.exit(0);
|
|
63
|
+
}
|
|
64
|
+
|
|
41
65
|
await registerCommands();
|
|
42
66
|
|
|
43
|
-
// 设置 options
|
|
67
|
+
// 设置 options 选项(必须在添加任何选项之前调用)
|
|
44
68
|
program.storeOptionsAsProperties(false);
|
|
45
|
-
|
|
69
|
+
|
|
70
|
+
// 配置 commander 帮助格式,对齐 nrm 格式
|
|
71
|
+
program
|
|
72
|
+
.name("rcb")
|
|
73
|
+
.description("小红书云服务 CLI,用于 agent 调试、发布和 cloud 云函数的调试、部署")
|
|
74
|
+
.usage("[options] [command]")
|
|
75
|
+
.version(pkg.version, "-V, --version", "output the version number");
|
|
76
|
+
|
|
77
|
+
// 配置帮助输出格式
|
|
78
|
+
program.configureHelp({
|
|
79
|
+
sortSubcommands: true,
|
|
80
|
+
subcommandTerm: (cmd) => cmd.name(),
|
|
81
|
+
});
|
|
46
82
|
|
|
47
83
|
const isCommandEmpty = yargsParsedResult._.length === 0;
|
|
48
84
|
|
|
@@ -63,9 +99,8 @@ async function main() {
|
|
|
63
99
|
console.log(`💡使用 ${chalk.bold("rcb -h")} 查看所有命令`);
|
|
64
100
|
});
|
|
65
101
|
|
|
66
|
-
//
|
|
102
|
+
// 没有使用命令时,直接输出帮助信息
|
|
67
103
|
if (isCommandEmpty) {
|
|
68
|
-
program.outputHelp();
|
|
69
104
|
// 需要隐藏的选项
|
|
70
105
|
const hideArgs = ["-h", "--help"];
|
|
71
106
|
hideArgs.forEach((arg) => {
|
|
@@ -74,8 +109,8 @@ async function main() {
|
|
|
74
109
|
processArgv.splice(index, 1);
|
|
75
110
|
}
|
|
76
111
|
});
|
|
77
|
-
|
|
78
|
-
|
|
112
|
+
// 使用 commander 内置的帮助输出
|
|
113
|
+
program.outputHelp();
|
|
79
114
|
}
|
|
80
115
|
|
|
81
116
|
try {
|
|
@@ -87,151 +122,6 @@ async function main() {
|
|
|
87
122
|
console.log(errMsg);
|
|
88
123
|
}
|
|
89
124
|
|
|
90
|
-
/**
|
|
91
|
-
* 处理异常
|
|
92
|
-
*/
|
|
93
|
-
async function errorHandler(err) {
|
|
94
|
-
process.emit("processExit");
|
|
95
|
-
|
|
96
|
-
// 3 空格,兼容中文字符编码长度问题
|
|
97
|
-
if (err && err.message) {
|
|
98
|
-
let errMsg = logSymbols.error + " " + err.message;
|
|
99
|
-
errMsg += err.requestId ? `\n${err.requestId}` : "";
|
|
100
|
-
console.log(errMsg);
|
|
101
|
-
|
|
102
|
-
// 多地域错误提示
|
|
103
|
-
if (errMsg.includes("Environment") && errMsg.includes("not found")) {
|
|
104
|
-
// 检查是否已经指定了 -r 或 --region 参数,如未指定则尝试获取地域信息
|
|
105
|
-
const regionSpecified =
|
|
106
|
-
processArgv.indexOf("-r") !== -1 ||
|
|
107
|
-
processArgv.indexOf("--region") !== -1;
|
|
108
|
-
const region = yargsParsedResult.r || yargsParsedResult.region;
|
|
109
|
-
const multiRegionErrMsg = `\n此环境可能不属于当前账号,或为非${
|
|
110
|
-
regionSupportedMap[region] || "上海"
|
|
111
|
-
}地域环境,如需切换地域请追加参数(例:-r gz),请检查环境归属,参考多地域使用方法:https://docs.cloudbase.net/cli-v1/region.html`;
|
|
112
|
-
if (!regionSpecified) {
|
|
113
|
-
// 从 -e 参数、--envId 参数和配置文件中获取环境 id
|
|
114
|
-
const envId =
|
|
115
|
-
yargsParsedResult.e || yargsParsedResult.envId || config.envId;
|
|
116
|
-
|
|
117
|
-
// 调用 API 接口尝试查询环境信息
|
|
118
|
-
const predictRegion = await tryTellEnvRegion(envId);
|
|
119
|
-
|
|
120
|
-
if (regionSupported.includes(predictRegion)) {
|
|
121
|
-
// 让用户选择是否切换地域
|
|
122
|
-
const prompt = new Confirm({
|
|
123
|
-
type: "confirm",
|
|
124
|
-
name: "confirm",
|
|
125
|
-
message: `该环境可能属于 ${regionSupportedMap[predictRegion]} 地域,是否切换地域并重新执行命令?`,
|
|
126
|
-
initial: "Y",
|
|
127
|
-
});
|
|
128
|
-
const confirm = await prompt.run();
|
|
129
|
-
if (confirm) {
|
|
130
|
-
// 检查原始命令是否已经追加了 -r 参数,如果有则替换,如果没有则追加
|
|
131
|
-
const regionArgIndex = processArgv.indexOf("-r");
|
|
132
|
-
if (regionArgIndex !== -1) {
|
|
133
|
-
processArgv[regionArgIndex + 1] = predictRegion;
|
|
134
|
-
} else {
|
|
135
|
-
processArgv.push("-r", predictRegion);
|
|
136
|
-
}
|
|
137
|
-
// 重新执行命令
|
|
138
|
-
const newArgvStr = processArgv.slice(2).join(" ");
|
|
139
|
-
console.log(
|
|
140
|
-
`\n${chalk.yellow.bold(
|
|
141
|
-
"正在重新执行命令:"
|
|
142
|
-
)} tcb ${newArgvStr}\n`
|
|
143
|
-
);
|
|
144
|
-
await execa("tcb", processArgv.slice(2), {
|
|
145
|
-
stdio: "inherit",
|
|
146
|
-
});
|
|
147
|
-
process.emit("tcbExit");
|
|
148
|
-
process.exit(0);
|
|
149
|
-
} else {
|
|
150
|
-
console.log(chalk.yellow.bold(multiRegionErrMsg));
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
} else {
|
|
154
|
-
console.log(chalk.yellow.bold(multiRegionErrMsg));
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 输出详细的错误信息
|
|
160
|
-
if (processArgv.includes("--verbose")) {
|
|
161
|
-
console.log(err);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
process.emit("processError");
|
|
165
|
-
setTimeout(() => {
|
|
166
|
-
process.exit(1);
|
|
167
|
-
}, 1000);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const isTokenExpired = (credential, gap = 120) =>
|
|
171
|
-
credential.accessTokenExpired &&
|
|
172
|
-
Number(credential.accessTokenExpired) < Date.now() + gap * 1000;
|
|
173
|
-
|
|
174
|
-
async function tryTellEnvRegion(envId) {
|
|
175
|
-
// 依次调用不同地域的 API 接口查询环境信息
|
|
176
|
-
const fetchedRegion = await Promise.all(
|
|
177
|
-
regionSupported.map(async (region) => {
|
|
178
|
-
const { EnvList = [] } = await fetchEnvInfoWithRegion(envId, region);
|
|
179
|
-
if (
|
|
180
|
-
EnvList.length !== 0 &&
|
|
181
|
-
EnvList.find((item) => item.EnvId === envId)
|
|
182
|
-
) {
|
|
183
|
-
return res.EnvList[0].Region;
|
|
184
|
-
}
|
|
185
|
-
return "";
|
|
186
|
-
})
|
|
187
|
-
);
|
|
188
|
-
|
|
189
|
-
let predictRegion = "";
|
|
190
|
-
fetchedRegion.forEach((region) => {
|
|
191
|
-
if (region) {
|
|
192
|
-
predictRegion = region;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
return predictRegion;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// 在指定地域调用 API 接口查询环境信息
|
|
199
|
-
async function fetchEnvInfoWithRegion(envId, region) {
|
|
200
|
-
let commonCredential = {};
|
|
201
|
-
const commonOpts = {
|
|
202
|
-
service: "tcb",
|
|
203
|
-
version: "2019-09-24",
|
|
204
|
-
proxy: getProxy(),
|
|
205
|
-
timeout: 15000,
|
|
206
|
-
getCredential: async () => {
|
|
207
|
-
if (commonCredential.secretId && !isTokenExpired(commonCredential)) {
|
|
208
|
-
return commonCredential;
|
|
209
|
-
}
|
|
210
|
-
const credential = await getCredentialWithoutCheck();
|
|
211
|
-
if (!credential) {
|
|
212
|
-
throw new Error("无有效身份信息,请使用 cloudbase login 登录");
|
|
213
|
-
}
|
|
214
|
-
commonCredential = credential;
|
|
215
|
-
return {
|
|
216
|
-
...credential,
|
|
217
|
-
tokenExpired: Number(credential.accessTokenExpired),
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
const apiName = "DescribeEnvs";
|
|
222
|
-
const tcbApi = new CloudApiService({
|
|
223
|
-
...commonOpts,
|
|
224
|
-
region,
|
|
225
|
-
});
|
|
226
|
-
const res = await tcbApi.request(apiName, {
|
|
227
|
-
EnvId: envId,
|
|
228
|
-
});
|
|
229
|
-
return res;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
process.on("uncaughtException", errorHandler);
|
|
233
|
-
process.on("unhandledRejection", errorHandler);
|
|
234
|
-
|
|
235
125
|
// 检查更新
|
|
236
126
|
const ONE_DAY = 86400000;
|
|
237
127
|
// Beta 版 1 个小时检查一次,稳定版 1 天检查一次
|
|
@@ -26,6 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.AgentDevCommand = void 0;
|
|
28
28
|
const fs_1 = __importDefault(require("fs"));
|
|
29
|
+
const agent_simulator_1 = require("@vectorx/agent-simulator");
|
|
29
30
|
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
30
31
|
const chalk_1 = __importDefault(require("chalk"));
|
|
31
32
|
const base_1 = require("../../core/base");
|
|
@@ -46,6 +47,8 @@ let AgentDevCommand = class AgentDevCommand extends base_1.Command {
|
|
|
46
47
|
watch: options.watch,
|
|
47
48
|
open: false,
|
|
48
49
|
enableRedLangfuse: Boolean(options.enableRedLangfuse),
|
|
50
|
+
mode: "agent",
|
|
51
|
+
deps: { AgentSimulator: agent_simulator_1.AgentSimulator },
|
|
49
52
|
});
|
|
50
53
|
if (options.open) {
|
|
51
54
|
log.info(`${prefix} 正在打开浏览器访问 localhost:${simulatorPort}`);
|
|
@@ -156,6 +156,7 @@ let GetLoginInfoCommand = class GetLoginInfoCommand extends base_1.Command {
|
|
|
156
156
|
}
|
|
157
157
|
execute(ctx) {
|
|
158
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
var _a;
|
|
159
160
|
try {
|
|
160
161
|
const loginInfo = yield this.authService.getLoginInfo();
|
|
161
162
|
if (!loginInfo) {
|
|
@@ -171,6 +172,18 @@ let GetLoginInfoCommand = class GetLoginInfoCommand extends base_1.Command {
|
|
|
171
172
|
console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + loginInfo.cli_token.slice(-8)));
|
|
172
173
|
console.log(chalk_1.default.bold("过期时间: ") +
|
|
173
174
|
chalk_1.default.yellow(new Date(loginInfo.create_at + loginInfo.expire_in_sec * 1000).toLocaleString("zh-CN")));
|
|
175
|
+
if ((_a = loginInfo.cloudEnvInfo) === null || _a === void 0 ? void 0 : _a.cloud_env_id) {
|
|
176
|
+
const env = loginInfo.cloudEnvInfo;
|
|
177
|
+
console.log(chalk_1.default.bold("云服务环境信息: ") +
|
|
178
|
+
chalk_1.default.cyan(env.cloud_env_name ? `${env.cloud_env_name} (${env.cloud_env_id})` : env.cloud_env_id));
|
|
179
|
+
console.log(chalk_1.default.gray(" 当前 env 已生效,后续命令将默认使用该云环境。") +
|
|
180
|
+
chalk_1.default.gray(" 如需修改,可执行: ") +
|
|
181
|
+
chalk_1.default.cyan("rcb env set -e <envId>"));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
console.log(chalk_1.default.bold("云服务环境信息: ") + chalk_1.default.gray("暂未指定 env Id"));
|
|
185
|
+
console.log(chalk_1.default.gray(" 可通过以下命令为 CLI 选择默认云环境: ") + chalk_1.default.cyan("rcb env set -e <envId>"));
|
|
186
|
+
}
|
|
174
187
|
console.log(chalk_1.default.gray("─".repeat(40)));
|
|
175
188
|
cloud_toolkit_1.logger.breakLine();
|
|
176
189
|
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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.EnvCreateCommand = void 0;
|
|
28
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
29
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
31
|
+
const base_1 = require("../../core/base");
|
|
32
|
+
const decorators_1 = require("../../decorators");
|
|
33
|
+
const auth_1 = require("../../decorators/auth");
|
|
34
|
+
const prefix = chalk_1.default.bgBlueBright(" 🌐 [rcb-env] ");
|
|
35
|
+
const CLOUD_ENV_NAME_REGEX = /^[A-Za-z0-9_]+$/;
|
|
36
|
+
let EnvCreateCommand = class EnvCreateCommand extends base_1.Command {
|
|
37
|
+
execute(rawOptions, log) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a;
|
|
40
|
+
let { name, description } = rawOptions;
|
|
41
|
+
const questions = [];
|
|
42
|
+
if (!name) {
|
|
43
|
+
questions.push({
|
|
44
|
+
type: "input",
|
|
45
|
+
name: "name",
|
|
46
|
+
message: "请输入云环境名称 (cloud_env_name):",
|
|
47
|
+
validate: (input) => {
|
|
48
|
+
const trimmed = (input || "").trim();
|
|
49
|
+
if (!trimmed) {
|
|
50
|
+
return "云环境名称不能为空";
|
|
51
|
+
}
|
|
52
|
+
if (trimmed.length > 64) {
|
|
53
|
+
return "云环境名称长度请不要超过 64 个字符";
|
|
54
|
+
}
|
|
55
|
+
if (!CLOUD_ENV_NAME_REGEX.test(trimmed)) {
|
|
56
|
+
return "云环境名称仅支持英文、数字、下划线";
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (typeof description === "undefined") {
|
|
63
|
+
questions.push({
|
|
64
|
+
type: "input",
|
|
65
|
+
name: "description",
|
|
66
|
+
message: "请输入云环境描述(可选,可留空):",
|
|
67
|
+
default: "",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
if (questions.length > 0) {
|
|
71
|
+
const answers = yield inquirer_1.default.prompt(questions);
|
|
72
|
+
if (!name) {
|
|
73
|
+
name = answers.name;
|
|
74
|
+
}
|
|
75
|
+
if (typeof description === "undefined") {
|
|
76
|
+
description = answers.description;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const cloudEnvName = (name || "").trim();
|
|
80
|
+
const cloudEnvDesc = (description || "").trim();
|
|
81
|
+
if (!cloudEnvName) {
|
|
82
|
+
log.error(`${prefix} 云环境名称不能为空,请重试`);
|
|
83
|
+
log.breakLine();
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
if (!CLOUD_ENV_NAME_REGEX.test(cloudEnvName)) {
|
|
87
|
+
log.error(`${prefix} 云环境名称仅支持英文、数字、下划线,请重试`);
|
|
88
|
+
log.breakLine();
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
const spinner = log.spinner(`${prefix} 正在创建云环境:${chalk_1.default.bold(cloudEnvName)} ...`);
|
|
92
|
+
try {
|
|
93
|
+
const env = yield (0, cloud_toolkit_1.createCloudEnvironment)({
|
|
94
|
+
cloud_env_name: cloudEnvName,
|
|
95
|
+
description: cloudEnvDesc,
|
|
96
|
+
});
|
|
97
|
+
spinner.succeed(`${prefix} 云环境创建成功`);
|
|
98
|
+
log.breakLine();
|
|
99
|
+
log.info(`${prefix} 新建云环境详情如下:`);
|
|
100
|
+
log.breakLine();
|
|
101
|
+
(0, cloud_toolkit_1.printHorizontalTable)([chalk_1.default.gray("字段"), chalk_1.default.gray("值")], [
|
|
102
|
+
[chalk_1.default.gray("名称"), chalk_1.default.bold(env.cloud_env_name)],
|
|
103
|
+
[chalk_1.default.gray("ID"), chalk_1.default.cyan(env.cloud_env_id)],
|
|
104
|
+
[
|
|
105
|
+
chalk_1.default.gray("状态"),
|
|
106
|
+
env.status === 1
|
|
107
|
+
? chalk_1.default.green("启用")
|
|
108
|
+
: env.status === 0
|
|
109
|
+
? chalk_1.default.blue("初始化")
|
|
110
|
+
: chalk_1.default.yellow(`停用/未知 (${(_a = env.status) !== null && _a !== void 0 ? _a : "N/A"})`),
|
|
111
|
+
],
|
|
112
|
+
[chalk_1.default.gray("描述"), env.description || "-"],
|
|
113
|
+
[chalk_1.default.gray("创建时间"), env.create_time || "-"],
|
|
114
|
+
[chalk_1.default.gray("更新时间"), env.update_time || "-"],
|
|
115
|
+
]);
|
|
116
|
+
log.breakLine();
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
spinner.fail(`${prefix} 云环境创建失败`);
|
|
120
|
+
log.error(`${prefix} 错误信息: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
|
|
121
|
+
log.breakLine();
|
|
122
|
+
process.exit(1);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
get options() {
|
|
127
|
+
return {
|
|
128
|
+
cmd: "env",
|
|
129
|
+
childCmd: "create",
|
|
130
|
+
desc: "创建一个新的云环境",
|
|
131
|
+
options: [
|
|
132
|
+
{
|
|
133
|
+
flags: "-n, --name <name>",
|
|
134
|
+
desc: "云环境名称 (cloud_env_name)",
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
flags: "-d, --description <description>",
|
|
138
|
+
desc: "云环境描述(可选)",
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
exports.EnvCreateCommand = EnvCreateCommand;
|
|
145
|
+
__decorate([
|
|
146
|
+
(0, decorators_1.InjectParams)(),
|
|
147
|
+
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
148
|
+
__param(1, (0, decorators_1.Log)()),
|
|
149
|
+
__metadata("design:type", Function),
|
|
150
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
151
|
+
__metadata("design:returntype", Promise)
|
|
152
|
+
], EnvCreateCommand.prototype, "execute", null);
|
|
153
|
+
exports.EnvCreateCommand = EnvCreateCommand = __decorate([
|
|
154
|
+
(0, auth_1.AuthGuard)(),
|
|
155
|
+
(0, base_1.ICommand)()
|
|
156
|
+
], EnvCreateCommand);
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./list"), exports);
|
|
18
|
+
__exportStar(require("./info"), exports);
|
|
19
|
+
__exportStar(require("./set"), exports);
|
|
20
|
+
__exportStar(require("./create"), exports);
|
|
@@ -0,0 +1,106 @@
|
|
|
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.EnvInfoCommand = void 0;
|
|
28
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
29
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const base_1 = require("../../core/base");
|
|
31
|
+
const decorators_1 = require("../../decorators");
|
|
32
|
+
const auth_1 = require("../../decorators/auth");
|
|
33
|
+
const prefix = chalk_1.default.bgBlueBright(" 🌐 [rcb-env] ");
|
|
34
|
+
let EnvInfoCommand = class EnvInfoCommand extends base_1.Command {
|
|
35
|
+
execute(options, log) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
var _a;
|
|
38
|
+
const envId = options.envId;
|
|
39
|
+
if (!envId) {
|
|
40
|
+
log.error(`${prefix} 请通过 -e, --envId 指定要查询的云环境 Id`);
|
|
41
|
+
log.breakLine();
|
|
42
|
+
console.log(chalk_1.default.gray("示例: "));
|
|
43
|
+
console.log(chalk_1.default.cyan(" rcb env info -e env-7k2m9n4p"));
|
|
44
|
+
log.breakLine();
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
const spinner = log.spinner(`${prefix} 正在查询云环境详情(envId=${envId})...`);
|
|
48
|
+
try {
|
|
49
|
+
const env = yield (0, cloud_toolkit_1.getCloudEnvironment)(envId);
|
|
50
|
+
spinner.succeed(`${prefix} 云环境详情查询完成`);
|
|
51
|
+
log.breakLine();
|
|
52
|
+
if (!env) {
|
|
53
|
+
log.warn(`${prefix} 未找到 Id 为 ${envId} 的云环境`);
|
|
54
|
+
log.breakLine();
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
log.info(`${prefix} 云环境详情:`);
|
|
58
|
+
log.breakLine();
|
|
59
|
+
(0, cloud_toolkit_1.printHorizontalTable)([chalk_1.default.gray("字段"), chalk_1.default.gray("值")], [
|
|
60
|
+
[chalk_1.default.gray("名称"), chalk_1.default.bold(env.cloud_env_name)],
|
|
61
|
+
[chalk_1.default.gray("ID"), chalk_1.default.cyan(env.cloud_env_id)],
|
|
62
|
+
[
|
|
63
|
+
chalk_1.default.gray("状态"),
|
|
64
|
+
env.status === 1 ? chalk_1.default.green("启用") : chalk_1.default.yellow(`停用/未知 (${(_a = env.status) !== null && _a !== void 0 ? _a : "N/A"})`),
|
|
65
|
+
],
|
|
66
|
+
[chalk_1.default.gray("描述"), env.description || "-"],
|
|
67
|
+
[chalk_1.default.gray("创建时间"), env.create_time || "-"],
|
|
68
|
+
[chalk_1.default.gray("更新时间"), env.update_time || "-"],
|
|
69
|
+
]);
|
|
70
|
+
log.breakLine();
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
spinner.fail(`${prefix} 云环境详情查询失败`);
|
|
74
|
+
log.error(`${prefix} 错误信息: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
|
|
75
|
+
log.breakLine();
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
get options() {
|
|
81
|
+
return {
|
|
82
|
+
cmd: "env",
|
|
83
|
+
childCmd: "info",
|
|
84
|
+
desc: "查看指定云环境的详情信息",
|
|
85
|
+
options: [
|
|
86
|
+
{
|
|
87
|
+
flags: "-e, --envId <envId>",
|
|
88
|
+
desc: "云环境 Id(cloud_env_id)",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.EnvInfoCommand = EnvInfoCommand;
|
|
95
|
+
__decorate([
|
|
96
|
+
(0, decorators_1.InjectParams)(),
|
|
97
|
+
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
98
|
+
__param(1, (0, decorators_1.Log)()),
|
|
99
|
+
__metadata("design:type", Function),
|
|
100
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
101
|
+
__metadata("design:returntype", Promise)
|
|
102
|
+
], EnvInfoCommand.prototype, "execute", null);
|
|
103
|
+
exports.EnvInfoCommand = EnvInfoCommand = __decorate([
|
|
104
|
+
(0, auth_1.AuthGuard)(),
|
|
105
|
+
(0, base_1.ICommand)()
|
|
106
|
+
], EnvInfoCommand);
|
|
@@ -0,0 +1,93 @@
|
|
|
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.EnvListCommand = void 0;
|
|
28
|
+
const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
|
|
29
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const base_1 = require("../../core/base");
|
|
31
|
+
const decorators_1 = require("../../decorators");
|
|
32
|
+
const auth_1 = require("../../decorators/auth");
|
|
33
|
+
const prefix = chalk_1.default.bgBlueBright(" 🌐 [rcb-env] ");
|
|
34
|
+
let EnvListCommand = class EnvListCommand extends base_1.Command {
|
|
35
|
+
execute(_options, log) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const spinner = log.spinner(`${prefix} 正在查询云环境列表...`);
|
|
38
|
+
try {
|
|
39
|
+
const envs = yield (0, cloud_toolkit_1.getCloudEnvironments)();
|
|
40
|
+
spinner.succeed(`${prefix} 云环境列表查询完成`);
|
|
41
|
+
log.breakLine();
|
|
42
|
+
if (!envs || envs.length === 0) {
|
|
43
|
+
log.info(`${prefix} 当前账号下暂未配置任何云环境`);
|
|
44
|
+
log.breakLine();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
log.info(`${prefix} 共查询到 ${envs.length} 个云环境:`);
|
|
48
|
+
log.breakLine();
|
|
49
|
+
(0, cloud_toolkit_1.printHorizontalTable)(["云环境 ID", "名称", "状态", "创建时间", "更新时间"], envs.map((env) => {
|
|
50
|
+
var _a;
|
|
51
|
+
return [
|
|
52
|
+
env.cloud_env_id,
|
|
53
|
+
chalk_1.default.bold(env.cloud_env_name),
|
|
54
|
+
env.status === 1
|
|
55
|
+
? chalk_1.default.green("启用")
|
|
56
|
+
: env.status === 0
|
|
57
|
+
? chalk_1.default.blue("初始化")
|
|
58
|
+
: chalk_1.default.yellow(`停用/未知 (${(_a = env.status) !== null && _a !== void 0 ? _a : "N/A"})`),
|
|
59
|
+
env.create_time || "-",
|
|
60
|
+
env.update_time || "-",
|
|
61
|
+
];
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
spinner.fail(`${prefix} 云环境列表查询失败`);
|
|
66
|
+
log.error(`${prefix} 错误信息: ${(error === null || error === void 0 ? void 0 : error.message) || error}`);
|
|
67
|
+
log.breakLine();
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
get options() {
|
|
73
|
+
return {
|
|
74
|
+
cmd: "env",
|
|
75
|
+
childCmd: "list",
|
|
76
|
+
desc: "查看当前账号下的云环境列表",
|
|
77
|
+
options: [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.EnvListCommand = EnvListCommand;
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, decorators_1.InjectParams)(),
|
|
84
|
+
__param(0, (0, decorators_1.ArgsOptions)()),
|
|
85
|
+
__param(1, (0, decorators_1.Log)()),
|
|
86
|
+
__metadata("design:type", Function),
|
|
87
|
+
__metadata("design:paramtypes", [Object, Function]),
|
|
88
|
+
__metadata("design:returntype", Promise)
|
|
89
|
+
], EnvListCommand.prototype, "execute", null);
|
|
90
|
+
exports.EnvListCommand = EnvListCommand = __decorate([
|
|
91
|
+
(0, auth_1.AuthGuard)(),
|
|
92
|
+
(0, base_1.ICommand)()
|
|
93
|
+
], EnvListCommand);
|