@cloudbase/cli 2.10.0-beta.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
|
};
|
|
@@ -69,274 +60,260 @@ let InitCommand = class InitCommand extends common_1.Command {
|
|
|
69
60
|
withoutAuth: true
|
|
70
61
|
};
|
|
71
62
|
}
|
|
72
|
-
execute(options, log) {
|
|
63
|
+
async execute(options, log) {
|
|
73
64
|
var _a;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}), 2000);
|
|
89
|
-
});
|
|
90
|
-
}, {
|
|
91
|
-
startTip: (0, i18n_1.t)('获取环境列表中')
|
|
65
|
+
console.log(chalk_1.default.bold.yellowBright('\n', (0, i18n_1.t)('⚠️ 此命令将被废弃,请使用新的命令 => tcb new <appName> [template]')), '\n');
|
|
66
|
+
await this.checkLogin();
|
|
67
|
+
const isInitNow = await this.checkTcbService();
|
|
68
|
+
let envData = [];
|
|
69
|
+
if (isInitNow) {
|
|
70
|
+
envData = await (0, utils_1.execWithLoading)(() => {
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
const timer = setInterval(async () => {
|
|
73
|
+
const envs = await (0, env_1.listEnvs)();
|
|
74
|
+
if (envs.length) {
|
|
75
|
+
clearInterval(timer);
|
|
76
|
+
resolve(envs);
|
|
77
|
+
}
|
|
78
|
+
}, 2000);
|
|
92
79
|
});
|
|
80
|
+
}, {
|
|
81
|
+
startTip: (0, i18n_1.t)('获取环境列表中')
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
envData = await (0, utils_1.execWithLoading)(() => (0, env_1.listEnvs)(), {
|
|
86
|
+
startTip: (0, i18n_1.t)('获取环境列表中')
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
envData = envData || [];
|
|
90
|
+
const envs = envData
|
|
91
|
+
.map((item) => {
|
|
92
|
+
let name = `${item.Alias} - [${item.EnvId}:${item.PackageName || (0, i18n_1.t)('按量计费')}]`;
|
|
93
|
+
if (item.Status !== "NORMAL") {
|
|
94
|
+
name += `(${constant_1.STATUS_TEXT[item.Status]})`;
|
|
93
95
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
return {
|
|
97
|
+
name,
|
|
98
|
+
value: item.EnvId
|
|
99
|
+
};
|
|
100
|
+
})
|
|
101
|
+
.sort((prev, next) => prev.value.charCodeAt(0) - next.value.charCodeAt(0));
|
|
102
|
+
const choices = [
|
|
103
|
+
...envs,
|
|
104
|
+
{
|
|
105
|
+
name: envData.length ? (0, i18n_1.t)('创建新环境') : (0, i18n_1.t)('无可用环境,创建新环境'),
|
|
106
|
+
value: CREATE_ENV
|
|
98
107
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
result(choice) {
|
|
125
|
-
return this.map(choice)[choice];
|
|
126
|
-
}
|
|
108
|
+
];
|
|
109
|
+
let { env } = await (0, enquirer_1.prompt)({
|
|
110
|
+
choices,
|
|
111
|
+
type: 'select',
|
|
112
|
+
name: 'env',
|
|
113
|
+
message: (0, i18n_1.t)('选择关联环境'),
|
|
114
|
+
result(choice) {
|
|
115
|
+
return this.map(choice)[choice];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
if (env === CREATE_ENV) {
|
|
119
|
+
log.success((0, i18n_1.t)('已打开控制台,请前往控制台创建环境'));
|
|
120
|
+
const { envId } = await (0, toolbox_1.getDataFromWeb)((port) => `${consoleUrl}&port=${port}`, 'getData');
|
|
121
|
+
if (!envId) {
|
|
122
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('接收环境 Id 信息失败,请重新运行 init 命令!'));
|
|
123
|
+
}
|
|
124
|
+
log.success((0, i18n_1.t)('创建环境成功,环境 Id: {{envId}}', { envId }));
|
|
125
|
+
env = envId;
|
|
126
|
+
}
|
|
127
|
+
await this.checkEnvStatus(env);
|
|
128
|
+
let projectName;
|
|
129
|
+
let projectPath;
|
|
130
|
+
if (!options.withoutTemplate) {
|
|
131
|
+
const templates = await (0, utils_1.execWithLoading)(() => (0, utils_1.fetch)(listUrl), {
|
|
132
|
+
startTip: (0, i18n_1.t)('拉取云开发模板列表中')
|
|
127
133
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('接收环境 Id 信息失败,请重新运行 init 命令!'));
|
|
133
|
-
}
|
|
134
|
-
log.success((0, i18n_1.t)('创建环境成功,环境 Id: {{envId}}', { envId }));
|
|
135
|
-
env = envId;
|
|
134
|
+
let templateName;
|
|
135
|
+
let tempateId;
|
|
136
|
+
if (options.template) {
|
|
137
|
+
tempateId = options.template;
|
|
136
138
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
});
|
|
144
|
-
let templateName;
|
|
145
|
-
let tempateId;
|
|
146
|
-
if (options.template) {
|
|
147
|
-
tempateId = options.template;
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
let { selectTemplateName } = yield (0, enquirer_1.prompt)({
|
|
151
|
-
type: 'select',
|
|
152
|
-
name: 'selectTemplateName',
|
|
153
|
-
message: (0, i18n_1.t)('选择云开发模板'),
|
|
154
|
-
choices: templates.map((item) => item.name)
|
|
155
|
-
});
|
|
156
|
-
templateName = selectTemplateName;
|
|
157
|
-
}
|
|
158
|
-
const selectedTemplate = templateName
|
|
159
|
-
? templates.find((item) => item.name === templateName)
|
|
160
|
-
: templates.find((item) => item.path === tempateId);
|
|
161
|
-
if (!selectedTemplate) {
|
|
162
|
-
log.info((0, i18n_1.t)('模板 `{{templateName}}` 不存在', { templateName: templateName || tempateId }));
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (options.project) {
|
|
166
|
-
projectName = options.project;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
const { projectName: promptProjectName } = yield (0, enquirer_1.prompt)({
|
|
170
|
-
type: 'input',
|
|
171
|
-
name: 'projectName',
|
|
172
|
-
message: (0, i18n_1.t)('请输入项目名称'),
|
|
173
|
-
initial: selectedTemplate.path
|
|
174
|
-
});
|
|
175
|
-
projectName = promptProjectName;
|
|
176
|
-
}
|
|
177
|
-
projectPath = path_1.default.join(process.cwd(), projectName);
|
|
178
|
-
if ((0, utils_1.checkFullAccess)(projectPath)) {
|
|
179
|
-
const { cover } = yield (0, enquirer_1.prompt)({
|
|
180
|
-
type: 'confirm',
|
|
181
|
-
name: 'cover',
|
|
182
|
-
message: (0, i18n_1.t)('已存在同名文件夹:{{projectName}},是否覆盖?', { projectName }),
|
|
183
|
-
initial: false
|
|
184
|
-
});
|
|
185
|
-
if (!cover) {
|
|
186
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('操作终止!'));
|
|
187
|
-
}
|
|
188
|
-
else {
|
|
189
|
-
fs_extra_1.default.removeSync(projectPath);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
yield (0, utils_1.execWithLoading)(() => __awaiter(this, void 0, void 0, function* () {
|
|
193
|
-
yield (0, utils_1.templateDownloadReport)(selectedTemplate.path, selectedTemplate.name);
|
|
194
|
-
yield this.extractTemplate(projectPath, selectedTemplate.path, selectedTemplate.url);
|
|
195
|
-
}), {
|
|
196
|
-
startTip: (0, i18n_1.t)('下载文件中')
|
|
139
|
+
else {
|
|
140
|
+
let { selectTemplateName } = await (0, enquirer_1.prompt)({
|
|
141
|
+
type: 'select',
|
|
142
|
+
name: 'selectTemplateName',
|
|
143
|
+
message: (0, i18n_1.t)('选择云开发模板'),
|
|
144
|
+
choices: templates.map((item) => item.name)
|
|
197
145
|
});
|
|
146
|
+
templateName = selectTemplateName;
|
|
198
147
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
148
|
+
const selectedTemplate = templateName
|
|
149
|
+
? templates.find((item) => item.name === templateName)
|
|
150
|
+
: templates.find((item) => item.path === tempateId);
|
|
151
|
+
if (!selectedTemplate) {
|
|
152
|
+
log.info((0, i18n_1.t)('模板 `{{templateName}}` 不存在', { templateName: templateName || tempateId }));
|
|
153
|
+
return;
|
|
202
154
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
fs_1.default.writeFileSync(path_1.default.join(projectPath, 'cloudbaserc.json'), JSON.stringify({
|
|
206
|
-
envId: env,
|
|
207
|
-
version: '2.0',
|
|
208
|
-
$schema: 'https://framework-1258016615.tcloudbaseapp.com/schema/latest.json'
|
|
209
|
-
}));
|
|
155
|
+
if (options.project) {
|
|
156
|
+
projectName = options.project;
|
|
210
157
|
}
|
|
211
158
|
else {
|
|
212
|
-
const
|
|
213
|
-
|
|
159
|
+
const { projectName: promptProjectName } = await (0, enquirer_1.prompt)({
|
|
160
|
+
type: 'input',
|
|
161
|
+
name: 'projectName',
|
|
162
|
+
message: (0, i18n_1.t)('请输入项目名称'),
|
|
163
|
+
initial: selectedTemplate.path
|
|
164
|
+
});
|
|
165
|
+
projectName = promptProjectName;
|
|
214
166
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (lodash_1.default.isEmpty(credential)) {
|
|
223
|
-
log.info((0, i18n_1.t)('你还没有登录,请在控制台中授权登录'));
|
|
224
|
-
const res = yield (0, utils_1.execWithLoading)(() => (0, auth_1.login)(), {
|
|
225
|
-
startTip: (0, i18n_1.t)('在浏览器中打开的授权页面进行授权...'),
|
|
226
|
-
successTip: (0, i18n_1.t)('授权登录成功!')
|
|
167
|
+
projectPath = path_1.default.join(process.cwd(), projectName);
|
|
168
|
+
if ((0, utils_1.checkFullAccess)(projectPath)) {
|
|
169
|
+
const { cover } = await (0, enquirer_1.prompt)({
|
|
170
|
+
type: 'confirm',
|
|
171
|
+
name: 'cover',
|
|
172
|
+
message: (0, i18n_1.t)('已存在同名文件夹:{{projectName}},是否覆盖?', { projectName }),
|
|
173
|
+
initial: false
|
|
227
174
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
175
|
+
if (!cover) {
|
|
176
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('操作终止!'));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
fs_extra_1.default.removeSync(projectPath);
|
|
234
180
|
}
|
|
235
181
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
-
const env = yield (0, env_1.getEnvInfo)(envId);
|
|
241
|
-
if (env.Status === "UNAVAILABLE") {
|
|
242
|
-
yield this.checkEnvAvaliable(envId);
|
|
243
|
-
}
|
|
244
|
-
else if (env.Status !== "NORMAL") {
|
|
245
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('所有环境状态异常'));
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
checkEnvAvaliable(envId) {
|
|
250
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
let count = 0;
|
|
252
|
-
yield (0, utils_1.execWithLoading)((flush) => {
|
|
253
|
-
const increase = setInterval(() => {
|
|
254
|
-
flush(`${ENV_INIT_TIP} ${++count}S`);
|
|
255
|
-
}, 1000);
|
|
256
|
-
return new Promise((resolve) => {
|
|
257
|
-
const timer = setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
258
|
-
const env = yield (0, env_1.getEnvInfo)(envId);
|
|
259
|
-
if (env.Status === "NORMAL") {
|
|
260
|
-
clearInterval(timer);
|
|
261
|
-
clearInterval(increase);
|
|
262
|
-
resolve();
|
|
263
|
-
}
|
|
264
|
-
}), 3000);
|
|
265
|
-
});
|
|
182
|
+
await (0, utils_1.execWithLoading)(async () => {
|
|
183
|
+
await (0, utils_1.templateDownloadReport)(selectedTemplate.path, selectedTemplate.name);
|
|
184
|
+
await this.extractTemplate(projectPath, selectedTemplate.path, selectedTemplate.url);
|
|
266
185
|
}, {
|
|
267
|
-
startTip:
|
|
268
|
-
successTip: (0, i18n_1.t)('环境 {{envId}} 初始化成功', { envId })
|
|
186
|
+
startTip: (0, i18n_1.t)('下载文件中')
|
|
269
187
|
});
|
|
270
|
-
}
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
projectName = '';
|
|
191
|
+
projectPath = path_1.default.join(process.cwd(), projectName);
|
|
192
|
+
}
|
|
193
|
+
let filepath = (_a = (await (0, toolbox_1.searchConfig)(projectPath))) === null || _a === void 0 ? void 0 : _a.filepath;
|
|
194
|
+
if (!filepath) {
|
|
195
|
+
fs_1.default.writeFileSync(path_1.default.join(projectPath, 'cloudbaserc.json'), JSON.stringify({
|
|
196
|
+
envId: env,
|
|
197
|
+
version: '2.0',
|
|
198
|
+
$schema: 'https://framework-1258016615.tcloudbaseapp.com/schema/latest.json'
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const configContent = fs_1.default.readFileSync(filepath).toString();
|
|
203
|
+
fs_1.default.writeFileSync(filepath, configContent.replace('{{envId}}', env));
|
|
204
|
+
}
|
|
205
|
+
this.initSuccessOutput(projectName);
|
|
271
206
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
type: 'confirm',
|
|
287
|
-
name: 'jump',
|
|
288
|
-
message: (0, i18n_1.t)('你还没有开通云开发服务,是否跳转到控制台开通云开发服务?(取消将无法继续操作)'),
|
|
289
|
-
initial: true
|
|
290
|
-
});
|
|
291
|
-
if (!jump) {
|
|
292
|
-
throw new error_1.CloudBaseError((0, i18n_1.t)('init 操作终止,请开通云开发服务后再进行操作!'));
|
|
207
|
+
async checkLogin(log) {
|
|
208
|
+
var _a;
|
|
209
|
+
const credential = await (0, utils_1.checkAndGetCredential)();
|
|
210
|
+
if (lodash_1.default.isEmpty(credential)) {
|
|
211
|
+
log.info((0, i18n_1.t)('你还没有登录,请在控制台中授权登录'));
|
|
212
|
+
const res = await (0, utils_1.execWithLoading)(() => (0, auth_1.login)(), {
|
|
213
|
+
startTip: (0, i18n_1.t)('在浏览器中打开的授权页面进行授权...'),
|
|
214
|
+
successTip: (0, i18n_1.t)('授权登录成功!')
|
|
215
|
+
});
|
|
216
|
+
const envId = (_a = res === null || res === void 0 ? void 0 : res.credential) === null || _a === void 0 ? void 0 : _a.envId;
|
|
217
|
+
if (envId) {
|
|
218
|
+
const env = await (0, env_1.getEnvInfo)(envId);
|
|
219
|
+
if (env.Status === "UNAVAILABLE") {
|
|
220
|
+
await this.checkEnvAvaliable(envId);
|
|
293
221
|
}
|
|
294
|
-
(0, open_1.default)(consoleUrl);
|
|
295
|
-
log.success((0, i18n_1.t)('已打开云开发控制台,请登录并在云开发控制台中开通服务!'));
|
|
296
|
-
yield (0, utils_1.execWithLoading)(() => this.waitForServiceEnable(), {
|
|
297
|
-
startTip: (0, i18n_1.t)('等待云开发服务开通中'),
|
|
298
|
-
successTip: (0, i18n_1.t)('云开发服务开通成功!')
|
|
299
|
-
});
|
|
300
|
-
return true;
|
|
301
222
|
}
|
|
302
|
-
|
|
303
|
-
});
|
|
223
|
+
}
|
|
304
224
|
}
|
|
305
|
-
|
|
306
|
-
|
|
225
|
+
async checkEnvStatus(envId) {
|
|
226
|
+
const env = await (0, env_1.getEnvInfo)(envId);
|
|
227
|
+
if (env.Status === "UNAVAILABLE") {
|
|
228
|
+
await this.checkEnvAvaliable(envId);
|
|
229
|
+
}
|
|
230
|
+
else if (env.Status !== "NORMAL") {
|
|
231
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('所有环境状态异常'));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async checkEnvAvaliable(envId) {
|
|
235
|
+
let count = 0;
|
|
236
|
+
await (0, utils_1.execWithLoading)((flush) => {
|
|
237
|
+
const increase = setInterval(() => {
|
|
238
|
+
flush(`${ENV_INIT_TIP} ${++count}S`);
|
|
239
|
+
}, 1000);
|
|
307
240
|
return new Promise((resolve) => {
|
|
308
|
-
const timer = setInterval(() =>
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
setTimeout(() => {
|
|
315
|
-
resolve();
|
|
316
|
-
}, 5000);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
catch (e) {
|
|
320
|
-
if (!(0, toolbox_1.isCamRefused)(e)) {
|
|
321
|
-
throw e;
|
|
322
|
-
}
|
|
241
|
+
const timer = setInterval(async () => {
|
|
242
|
+
const env = await (0, env_1.getEnvInfo)(envId);
|
|
243
|
+
if (env.Status === "NORMAL") {
|
|
244
|
+
clearInterval(timer);
|
|
245
|
+
clearInterval(increase);
|
|
246
|
+
resolve();
|
|
323
247
|
}
|
|
324
|
-
}
|
|
248
|
+
}, 3000);
|
|
325
249
|
});
|
|
250
|
+
}, {
|
|
251
|
+
startTip: ENV_INIT_TIP,
|
|
252
|
+
successTip: (0, i18n_1.t)('环境 {{envId}} 初始化成功', { envId })
|
|
326
253
|
});
|
|
327
254
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
255
|
+
async checkTcbService(log) {
|
|
256
|
+
const app = await (0, utils_1.getMangerService)();
|
|
257
|
+
let Initialized;
|
|
258
|
+
try {
|
|
259
|
+
Initialized = (await app.env.checkTcbService()).Initialized;
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
if (!(0, toolbox_1.isCamRefused)(e)) {
|
|
263
|
+
throw e;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if (!Initialized) {
|
|
267
|
+
const { jump } = await (0, enquirer_1.prompt)({
|
|
268
|
+
type: 'confirm',
|
|
269
|
+
name: 'jump',
|
|
270
|
+
message: (0, i18n_1.t)('你还没有开通云开发服务,是否跳转到控制台开通云开发服务?(取消将无法继续操作)'),
|
|
271
|
+
initial: true
|
|
272
|
+
});
|
|
273
|
+
if (!jump) {
|
|
274
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('init 操作终止,请开通云开发服务后再进行操作!'));
|
|
275
|
+
}
|
|
276
|
+
(0, open_1.default)(consoleUrl);
|
|
277
|
+
log.success((0, i18n_1.t)('已打开云开发控制台,请登录并在云开发控制台中开通服务!'));
|
|
278
|
+
await (0, utils_1.execWithLoading)(() => this.waitForServiceEnable(), {
|
|
279
|
+
startTip: (0, i18n_1.t)('等待云开发服务开通中'),
|
|
280
|
+
successTip: (0, i18n_1.t)('云开发服务开通成功!')
|
|
281
|
+
});
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
async waitForServiceEnable() {
|
|
287
|
+
return new Promise((resolve) => {
|
|
288
|
+
const timer = setInterval(async () => {
|
|
289
|
+
const app = await (0, utils_1.getMangerService)();
|
|
290
|
+
try {
|
|
291
|
+
const { Initialized } = await app.env.checkTcbService();
|
|
292
|
+
if (Initialized) {
|
|
293
|
+
clearInterval(timer);
|
|
294
|
+
setTimeout(() => {
|
|
295
|
+
resolve();
|
|
296
|
+
}, 5000);
|
|
297
|
+
}
|
|
334
298
|
}
|
|
335
|
-
|
|
336
|
-
|
|
299
|
+
catch (e) {
|
|
300
|
+
if (!(0, toolbox_1.isCamRefused)(e)) {
|
|
301
|
+
throw e;
|
|
302
|
+
}
|
|
337
303
|
}
|
|
338
|
-
|
|
339
|
-
|
|
304
|
+
}, 3000);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
async extractTemplate(projectPath, templatePath, remoteUrl) {
|
|
308
|
+
const url = remoteUrl || getTemplateAddress(templatePath);
|
|
309
|
+
return (0, utils_1.fetchStream)(url).then(async (res) => {
|
|
310
|
+
if (!res) {
|
|
311
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('请求异常'));
|
|
312
|
+
}
|
|
313
|
+
if (res.status !== 200) {
|
|
314
|
+
throw new error_1.CloudBaseError((0, i18n_1.t)('未找到文件'));
|
|
315
|
+
}
|
|
316
|
+
await (0, toolbox_1.unzipStream)(res.body, projectPath);
|
|
340
317
|
});
|
|
341
318
|
}
|
|
342
319
|
initSuccessOutput(projectName, log) {
|
|
@@ -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
|
};
|
|
@@ -53,47 +44,45 @@ let NewCommand = class NewCommand extends common_1.Command {
|
|
|
53
44
|
withoutAuth: true
|
|
54
45
|
};
|
|
55
46
|
}
|
|
56
|
-
execute(ctx, log) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
yield (0, execa_1.default)('git', ['clone', '--depth', 1, templateUri, appName], {
|
|
80
|
-
stdio: 'inherit'
|
|
81
|
-
});
|
|
82
|
-
yield (0, utils_1.delSync)([path_1.default.join(process.cwd(), appName, '.git')]);
|
|
83
|
-
}
|
|
84
|
-
projectPath = path_1.default.join(process.cwd(), appName);
|
|
47
|
+
async execute(ctx, log) {
|
|
48
|
+
const { params, options, envId } = ctx;
|
|
49
|
+
const { clone } = options;
|
|
50
|
+
let appName = params === null || params === void 0 ? void 0 : params[0];
|
|
51
|
+
const templateUri = params === null || params === void 0 ? void 0 : params[1];
|
|
52
|
+
await (0, auth_1.checkLogin)();
|
|
53
|
+
let region = await (0, toolbox_1.getRegion)(true);
|
|
54
|
+
if (!region) {
|
|
55
|
+
region = await (0, utils_1.getSelectRegion)();
|
|
56
|
+
}
|
|
57
|
+
let env = envId;
|
|
58
|
+
if (!env) {
|
|
59
|
+
env = await (0, utils_1.getSelectedEnv)(envId);
|
|
60
|
+
}
|
|
61
|
+
let projectPath;
|
|
62
|
+
if (templateUri && isGitUrl(templateUri)) {
|
|
63
|
+
if (clone) {
|
|
64
|
+
await (0, execa_1.default)('git', ['clone', templateUri, appName], {
|
|
65
|
+
stdio: 'inherit'
|
|
66
|
+
});
|
|
85
67
|
}
|
|
86
68
|
else {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
projectPath,
|
|
90
|
-
templateUri,
|
|
91
|
-
newProject: true
|
|
69
|
+
await (0, execa_1.default)('git', ['clone', '--depth', 1, templateUri, appName], {
|
|
70
|
+
stdio: 'inherit'
|
|
92
71
|
});
|
|
72
|
+
await (0, utils_1.delSync)([path_1.default.join(process.cwd(), appName, '.git')]);
|
|
93
73
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
74
|
+
projectPath = path_1.default.join(process.cwd(), appName);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
projectPath = await (0, utils_1.downloadTemplate)({
|
|
78
|
+
appName,
|
|
79
|
+
projectPath,
|
|
80
|
+
templateUri,
|
|
81
|
+
newProject: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
await (0, utils_1.initProjectConfig)(env, region, projectPath);
|
|
85
|
+
this.initSuccessOutput(appName);
|
|
97
86
|
}
|
|
98
87
|
initSuccessOutput(appName, log) {
|
|
99
88
|
log.success(appName ? (0, i18n_1.t)('创建应用 {{appName}} 成功!\n', { appName }) : (0, i18n_1.t)('创建应用成功!'));
|