esa-cli 0.0.2-beta.12 → 0.0.2-beta.14
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/dist/commands/commit/index.js +20 -119
- package/dist/commands/commit/prodBuild.js +2 -3
- package/dist/commands/common/routineUtils.js +276 -0
- package/dist/commands/config.js +1 -1
- package/dist/commands/deploy/helper.js +31 -36
- package/dist/commands/deploy/index.js +78 -165
- package/dist/commands/deployments/delete.js +31 -6
- package/dist/commands/deployments/index.js +3 -3
- package/dist/commands/deployments/list.js +18 -27
- package/dist/commands/dev/build.js +3 -3
- package/dist/commands/dev/doProcess.js +5 -5
- package/dist/commands/dev/ew2/devPack.js +17 -8
- package/dist/commands/dev/ew2/mock/kv.js +2 -2
- package/dist/commands/dev/ew2/server.js +13 -10
- package/dist/commands/dev/index.js +12 -12
- package/dist/commands/dev/mockWorker/devPack.js +16 -7
- package/dist/commands/dev/mockWorker/server.js +7 -6
- package/dist/commands/domain/add.js +3 -3
- package/dist/commands/domain/delete.js +3 -3
- package/dist/commands/domain/index.js +3 -3
- package/dist/commands/domain/list.js +7 -7
- package/dist/commands/init/helper.js +59 -9
- package/dist/commands/init/index.js +380 -76
- package/dist/commands/init/template.jsonc +39 -0
- package/dist/commands/lang.js +2 -2
- package/dist/commands/login/index.js +9 -5
- package/dist/commands/logout.js +6 -6
- package/dist/commands/route/add.js +134 -43
- package/dist/commands/route/delete.js +6 -6
- package/dist/commands/route/index.js +3 -3
- package/dist/commands/route/list.js +4 -4
- package/dist/commands/routine/delete.js +2 -2
- package/dist/commands/routine/index.js +3 -3
- package/dist/commands/routine/list.js +5 -16
- package/dist/commands/site/index.js +2 -2
- package/dist/commands/site/list.js +6 -7
- package/dist/commands/utils.js +55 -19
- package/dist/components/descriptionInput.js +1 -1
- package/dist/components/mutiSelectTable.js +1 -1
- package/dist/components/selectInput.js +2 -3
- package/dist/components/selectItem.js +1 -1
- package/dist/docs/Commands_en.md +12 -16
- package/dist/docs/Commands_zh_CN.md +12 -16
- package/dist/docs/eslint-config-en.md +1 -0
- package/dist/docs/eslint-config.md +73 -0
- package/dist/docs/init-command-quick-test.md +208 -0
- package/dist/docs/init-command-test-guide.md +598 -0
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/locales.json +161 -9
- package/dist/index.js +11 -11
- package/dist/libs/apiService.js +177 -14
- package/dist/libs/git/index.js +8 -5
- package/dist/libs/logger.js +62 -7
- package/dist/libs/service.js +2 -2
- package/dist/libs/templates/index.js +1 -1
- package/dist/utils/checkAssetsExist.js +80 -0
- package/dist/utils/checkDevPort.js +3 -17
- package/dist/utils/checkEntryFileExist.js +10 -0
- package/dist/utils/checkIsRoutineCreated.js +18 -16
- package/dist/utils/checkVersion.js +1 -1
- package/dist/utils/compress.js +80 -0
- package/dist/utils/download.js +5 -5
- package/dist/utils/fileMd5.js +1 -1
- package/dist/utils/fileUtils/index.js +71 -22
- package/dist/utils/installDeno.js +3 -3
- package/dist/utils/installEw2.js +7 -7
- package/dist/utils/openInBrowser.js +1 -1
- package/package.json +9 -3
- package/dist/docs/Dev_en.md +0 -0
- package/dist/docs/Dev_zh_CN.md +0 -0
|
@@ -7,17 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
|
|
10
|
+
import { exit } from 'process';
|
|
12
11
|
import { descriptionInput } from '../../components/descriptionInput.js';
|
|
13
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
14
|
-
import prodBuild from './prodBuild.js';
|
|
15
|
-
import logger from '../../libs/logger.js';
|
|
16
12
|
import t from '../../i18n/index.js';
|
|
17
|
-
import {
|
|
13
|
+
import { validateAndInitializeProject, generateCodeVersion } from '../common/routineUtils.js';
|
|
18
14
|
const commit = {
|
|
19
15
|
command: 'commit [entry]',
|
|
20
|
-
describe:
|
|
16
|
+
describe: `📥 ${t('commit_describe').d('Commit your code, save as a new version')}`,
|
|
21
17
|
builder: (yargs) => {
|
|
22
18
|
return yargs
|
|
23
19
|
.option('minify', {
|
|
@@ -25,16 +21,21 @@ const commit = {
|
|
|
25
21
|
describe: t('commit_option_minify').d('Minify code before committing'),
|
|
26
22
|
type: 'boolean',
|
|
27
23
|
default: false
|
|
24
|
+
})
|
|
25
|
+
.option('assets', {
|
|
26
|
+
alias: 'a',
|
|
27
|
+
describe: t('commit_option_assets').d('Assets directory'),
|
|
28
|
+
type: 'string'
|
|
28
29
|
})
|
|
29
30
|
.option('description', {
|
|
30
31
|
alias: 'd',
|
|
31
32
|
describe: t('commit_option_description').d('Description for the routine/version (skip interactive input)'),
|
|
32
33
|
type: 'string'
|
|
33
34
|
})
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
.option('name', {
|
|
36
|
+
alias: 'n',
|
|
37
|
+
describe: t('commit_option_name').d('Edge Routine name'),
|
|
38
|
+
type: 'string'
|
|
38
39
|
});
|
|
39
40
|
},
|
|
40
41
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -45,117 +46,17 @@ const commit = {
|
|
|
45
46
|
export default commit;
|
|
46
47
|
export function handleCommit(argv) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const projectConfig = getProjectConfig();
|
|
51
|
-
if (!projectConfig)
|
|
52
|
-
return logger.notInProject();
|
|
53
|
-
if (!(yield checkIsLoginSuccess()))
|
|
49
|
+
const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name);
|
|
50
|
+
if (!projectInfo)
|
|
54
51
|
return;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const response = yield server.getRoutine(req, false);
|
|
60
|
-
let action = 'Creating';
|
|
61
|
-
let description;
|
|
62
|
-
if (!response) {
|
|
63
|
-
logger.log(`🙅 ${t('commit_er_not_exist').d('No routine found, creating a new one')}`);
|
|
64
|
-
if (argv.description) {
|
|
65
|
-
description = argv.description;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
description = yield descriptionInput(`🖊️ ${t('commit_er_description').d('Enter a description for the routine')}:`, false);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
logger.log(`🔄 ${t('commit_er_exist').d('Routine exists, updating the code')}`);
|
|
73
|
-
if (argv.description) {
|
|
74
|
-
description = argv.description;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
description = yield descriptionInput(`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
|
|
78
|
-
}
|
|
79
|
-
action = 'Updating';
|
|
80
|
-
}
|
|
81
|
-
const code = readEdgeRoutineFile() || '';
|
|
82
|
-
if (action === 'Creating') {
|
|
83
|
-
const edgeRoutineProps = {
|
|
84
|
-
name: projectConfig.name,
|
|
85
|
-
code,
|
|
86
|
-
description: ''
|
|
87
|
-
};
|
|
88
|
-
yield createEdgeRoutine(edgeRoutineProps);
|
|
89
|
-
}
|
|
90
|
-
const versionProps = {
|
|
91
|
-
name: projectConfig.name,
|
|
92
|
-
code,
|
|
93
|
-
description: description
|
|
94
|
-
};
|
|
95
|
-
const uploadResult = yield uploadEdgeRoutineCode(versionProps);
|
|
96
|
-
if (uploadResult) {
|
|
97
|
-
yield releaseOfficialVersion(versionProps);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
export function createEdgeRoutine(edgeRoutine) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
try {
|
|
108
|
-
const server = yield ApiService.getInstance();
|
|
109
|
-
const res = yield server.createRoutine(edgeRoutine);
|
|
110
|
-
const createResult = (res === null || res === void 0 ? void 0 : res.data.Status) === 'OK';
|
|
111
|
-
if (!createResult) {
|
|
112
|
-
logger.error(t('commit_create_er_fail').d('An error occurred while trying to create a routine'));
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
logger.success(t('commit_create_er_success').d('Routine created successfully.'));
|
|
116
|
-
return yield uploadEdgeRoutineCode(edgeRoutine);
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
export function uploadEdgeRoutineCode(edgeRoutine) {
|
|
125
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
try {
|
|
127
|
-
const server = yield ApiService.getInstance();
|
|
128
|
-
const uploadResult = yield server.getRoutineStagingCodeUploadInfo(edgeRoutine);
|
|
129
|
-
if (!uploadResult) {
|
|
130
|
-
logger.error(t('commit_upload_fail').d('An error occurred while trying to upload your code'));
|
|
131
|
-
process.exit(0);
|
|
132
|
-
}
|
|
133
|
-
logger.success(t('commit_upload_success').d('Code uploaded successfully.'));
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
logger.error('123');
|
|
138
|
-
logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
|
|
139
|
-
process.exit(0);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
export function releaseOfficialVersion(edgeRoutine) {
|
|
144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
var _a;
|
|
146
|
-
const param = {
|
|
147
|
-
Name: edgeRoutine.name,
|
|
148
|
-
CodeDescription: (_a = edgeRoutine.description) !== null && _a !== void 0 ? _a : ''
|
|
149
|
-
};
|
|
150
|
-
const server = yield ApiService.getInstance();
|
|
151
|
-
const commitResult = yield server.commitRoutineStagingCode(param);
|
|
152
|
-
if (commitResult) {
|
|
153
|
-
logger.success(t('commit_success').d('Code version committed successfully.'));
|
|
154
|
-
return true;
|
|
52
|
+
const { projectName } = projectInfo;
|
|
53
|
+
let description;
|
|
54
|
+
if (argv.description) {
|
|
55
|
+
description = argv.description;
|
|
155
56
|
}
|
|
156
57
|
else {
|
|
157
|
-
|
|
158
|
-
return false;
|
|
58
|
+
description = yield descriptionInput(`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
|
|
159
59
|
}
|
|
60
|
+
yield generateCodeVersion(projectName, description, argv === null || argv === void 0 ? void 0 : argv.entry, argv === null || argv === void 0 ? void 0 : argv.assets, argv === null || argv === void 0 ? void 0 : argv.minify);
|
|
160
61
|
});
|
|
161
62
|
}
|
|
@@ -7,15 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
10
12
|
import esbuild from 'esbuild';
|
|
11
13
|
import { lessLoader } from 'esbuild-plugin-less';
|
|
12
|
-
import path from 'path';
|
|
13
|
-
import fs from 'fs';
|
|
14
14
|
import { getRoot } from '../../utils/fileUtils/base.js';
|
|
15
15
|
import { NODE_EXTERNALS } from '../common/constant.js';
|
|
16
16
|
const userRoot = getRoot();
|
|
17
17
|
const entry = path.resolve(userRoot, 'src/index.js');
|
|
18
|
-
const outfile = path.resolve(userRoot, '.dev/pub.js');
|
|
19
18
|
export default function () {
|
|
20
19
|
return __awaiter(this, arguments, void 0, function* (minify = false, customEntry, outputPath) {
|
|
21
20
|
const entryPoint = customEntry
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import t from '../../i18n/index.js';
|
|
12
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
13
|
+
import logger from '../../libs/logger.js';
|
|
14
|
+
import { ensureRoutineExists } from '../../utils/checkIsRoutineCreated.js';
|
|
15
|
+
import compress from '../../utils/compress.js';
|
|
16
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
17
|
+
import sleep from '../../utils/sleep.js';
|
|
18
|
+
import { checkIsLoginSuccess } from '../utils.js';
|
|
19
|
+
export function commitRoutineWithAssets(requestParams, zipBuffer) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
const server = yield ApiService.getInstance();
|
|
23
|
+
const apiResult = yield server.CreateRoutineWithAssetsCodeVersion(requestParams);
|
|
24
|
+
if (!apiResult || !apiResult.data.OssPostConfig) {
|
|
25
|
+
return {
|
|
26
|
+
isSuccess: false,
|
|
27
|
+
res: null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const ossConfig = apiResult.data.OssPostConfig;
|
|
31
|
+
if (!ossConfig.OSSAccessKeyId ||
|
|
32
|
+
!ossConfig.Signature ||
|
|
33
|
+
!ossConfig.Url ||
|
|
34
|
+
!ossConfig.Key ||
|
|
35
|
+
!ossConfig.Policy) {
|
|
36
|
+
console.error('Missing required OSS configuration fields');
|
|
37
|
+
return {
|
|
38
|
+
isSuccess: false,
|
|
39
|
+
res: null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
let uploadSuccess = false;
|
|
43
|
+
for (let i = 0; i < 3; i++) {
|
|
44
|
+
uploadSuccess = yield server.uploadToOss({
|
|
45
|
+
OSSAccessKeyId: ossConfig.OSSAccessKeyId,
|
|
46
|
+
Signature: ossConfig.Signature,
|
|
47
|
+
Url: ossConfig.Url,
|
|
48
|
+
Key: ossConfig.Key,
|
|
49
|
+
Policy: ossConfig.Policy,
|
|
50
|
+
XOssSecurityToken: ossConfig.XOssSecurityToken || ''
|
|
51
|
+
}, zipBuffer);
|
|
52
|
+
if (uploadSuccess) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
isSuccess: uploadSuccess,
|
|
58
|
+
res: apiResult
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error('Error in createRoutineWithAssetsCodeVersion:', error);
|
|
63
|
+
return {
|
|
64
|
+
isSuccess: false,
|
|
65
|
+
res: null
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 通用的项目验证和初始化函数
|
|
72
|
+
* 包含目录检查、项目配置获取、登录检查、routine存在性检查
|
|
73
|
+
*/
|
|
74
|
+
export function validateAndInitializeProject(name) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
const projectConfig = getProjectConfig();
|
|
77
|
+
if (!projectConfig) {
|
|
78
|
+
logger.notInProject();
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const projectName = name || projectConfig.name;
|
|
82
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
83
|
+
if (!isSuccess) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
yield ensureRoutineExists(projectName);
|
|
87
|
+
return { projectConfig, projectName };
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 通用的routine详情获取函数
|
|
92
|
+
*/
|
|
93
|
+
export function getRoutineDetails(projectName) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const server = yield ApiService.getInstance();
|
|
96
|
+
const req = { Name: projectName };
|
|
97
|
+
return yield server.getRoutine(req, false);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 通用的代码压缩和提交函数
|
|
102
|
+
* 支持assets和普通代码两种模式
|
|
103
|
+
*/
|
|
104
|
+
export function generateCodeVersion(projectName_1, description_1, entry_1, assets_1) {
|
|
105
|
+
return __awaiter(this, arguments, void 0, function* (projectName, description, entry, assets, minify = false, projectPath) {
|
|
106
|
+
const zip = yield compress(entry, assets, minify, projectPath);
|
|
107
|
+
const res = yield commitRoutineWithAssets({
|
|
108
|
+
Name: projectName,
|
|
109
|
+
CodeDescription: description
|
|
110
|
+
}, zip === null || zip === void 0 ? void 0 : zip.toBuffer());
|
|
111
|
+
if (res === null || res === void 0 ? void 0 : res.isSuccess) {
|
|
112
|
+
logger.success('Your code has been successfully committed');
|
|
113
|
+
return {
|
|
114
|
+
isSuccess: true,
|
|
115
|
+
res: res === null || res === void 0 ? void 0 : res.res
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
logger.error('Generate code version failed');
|
|
120
|
+
return {
|
|
121
|
+
isSuccess: false,
|
|
122
|
+
res: null
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 根据 env 在一个或多个环境部署
|
|
129
|
+
*/
|
|
130
|
+
export function deployToEnvironments(name, codeVersion, env) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
if (env === 'all') {
|
|
133
|
+
const isStagingSuccess = yield deployCodeVersion(name, codeVersion, 'staging');
|
|
134
|
+
const isProdSuccess = yield deployCodeVersion(name, codeVersion, 'production');
|
|
135
|
+
return isStagingSuccess && isProdSuccess;
|
|
136
|
+
}
|
|
137
|
+
return yield deployCodeVersion(name, codeVersion, env);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 通用的快速部署函数
|
|
142
|
+
* 结合了压缩、提交和部署的完整流程
|
|
143
|
+
*/
|
|
144
|
+
export function commitAndDeployVersion(projectConfig_1, scriptEntry_1, assets_1) {
|
|
145
|
+
return __awaiter(this, arguments, void 0, function* (projectConfig, scriptEntry, assets, description = '', projectPath, env = 'production', minify = false, version) {
|
|
146
|
+
var _a, _b, _c;
|
|
147
|
+
if (version) {
|
|
148
|
+
return yield deployToEnvironments(projectConfig.name, version, env);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const res = yield generateCodeVersion(projectConfig.name, description, scriptEntry || projectConfig.entry, assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory), minify || projectConfig.minify, projectPath);
|
|
152
|
+
const isCommitSuccess = res === null || res === void 0 ? void 0 : res.isSuccess;
|
|
153
|
+
if (isCommitSuccess) {
|
|
154
|
+
const codeVersion = (_c = (_b = res === null || res === void 0 ? void 0 : res.res) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.CodeVersion;
|
|
155
|
+
if (!codeVersion) {
|
|
156
|
+
logger.error('Failed to read CodeVersion from response.');
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
return yield deployToEnvironments(projectConfig.name, codeVersion, env);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* 通用的版本部署函数
|
|
169
|
+
*/
|
|
170
|
+
export function deployCodeVersion(name, codeVersion, environment) {
|
|
171
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
+
const server = yield ApiService.getInstance();
|
|
173
|
+
// Ensure the committed code version is ready before deploying
|
|
174
|
+
const isReady = yield waitForCodeVersionReady(name, codeVersion);
|
|
175
|
+
if (!isReady) {
|
|
176
|
+
logger.error('The code version is not ready for deployment.');
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const res = yield server.createRoutineCodeDeployment({
|
|
180
|
+
Name: name,
|
|
181
|
+
CodeVersions: [{ Percentage: 100, CodeVersion: codeVersion }],
|
|
182
|
+
Strategy: 'percentage',
|
|
183
|
+
Env: environment
|
|
184
|
+
});
|
|
185
|
+
if (res) {
|
|
186
|
+
logger.success(`Your code has been successfully deployed to ${chalk.cyan(environment)}`);
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
logger.error('Your code has not been deployed');
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Poll routine code version status until it becomes ready
|
|
197
|
+
*/
|
|
198
|
+
export function waitForCodeVersionReady(name_1, codeVersion_1) {
|
|
199
|
+
return __awaiter(this, arguments, void 0, function* (name, codeVersion, timeoutMs = 5 * 60 * 1000, intervalMs = 1000) {
|
|
200
|
+
var _a, _b;
|
|
201
|
+
if (!name || !codeVersion) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
const server = yield ApiService.getInstance();
|
|
205
|
+
const start = Date.now();
|
|
206
|
+
logger.log(`⏳ Waiting for code version ${chalk.cyan(codeVersion)} to be ready...`);
|
|
207
|
+
while (Date.now() - start < timeoutMs) {
|
|
208
|
+
try {
|
|
209
|
+
const info = yield server.getRoutineCodeVersionInfo({
|
|
210
|
+
Name: name,
|
|
211
|
+
CodeVersion: codeVersion
|
|
212
|
+
});
|
|
213
|
+
const status = (_b = (_a = info === null || info === void 0 ? void 0 : info.data) === null || _a === void 0 ? void 0 : _a.Status) === null || _b === void 0 ? void 0 : _b.toLowerCase();
|
|
214
|
+
if (status === 'init') {
|
|
215
|
+
yield sleep(intervalMs);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
else if (status === 'available') {
|
|
219
|
+
logger.log(`✅ Code version ${chalk.cyan(codeVersion)} is ready.`);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
logger.error(`Code version ${chalk.cyan(codeVersion)} build ${status}.`);
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
catch (e) {
|
|
228
|
+
// swallow and retry until timeout
|
|
229
|
+
console.log(e);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
logger.error(`⏰ Waiting for code version ${chalk.cyan(codeVersion)} timed out.`);
|
|
233
|
+
return false;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 通用的部署成功显示函数
|
|
238
|
+
* 显示部署成功信息、访问链接和后续操作指南
|
|
239
|
+
*/
|
|
240
|
+
export function displayDeploySuccess(projectName_1) {
|
|
241
|
+
return __awaiter(this, arguments, void 0, function* (projectName, showDomainGuide = true, showRouteGuide = true) {
|
|
242
|
+
var _a;
|
|
243
|
+
const service = yield ApiService.getInstance();
|
|
244
|
+
const res = yield service.getRoutine({ Name: projectName });
|
|
245
|
+
const defaultUrl = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.DefaultRelatedRecord;
|
|
246
|
+
const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
|
|
247
|
+
if (showDomainGuide) {
|
|
248
|
+
logger.log(`👉 ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
249
|
+
}
|
|
250
|
+
if (showRouteGuide) {
|
|
251
|
+
logger.log(`👉 ${t('deploy_success_guide_2').d('Run this command to add routes')}: ${chalk.green('esa route add -r <ROUTE> -s <SITE>')}`);
|
|
252
|
+
}
|
|
253
|
+
logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
|
|
254
|
+
logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* 通用的快速部署函数(用于init命令)
|
|
259
|
+
* 结合了登录检查、routine创建、代码提交和部署的完整流程
|
|
260
|
+
*/
|
|
261
|
+
export function quickDeployForInit(targetPath_1, projectConfig_1) {
|
|
262
|
+
return __awaiter(this, arguments, void 0, function* (targetPath, projectConfig, description = 'Quick deploy from init') {
|
|
263
|
+
var _a, _b;
|
|
264
|
+
const isLoginSuccess = yield checkIsLoginSuccess();
|
|
265
|
+
if (!isLoginSuccess) {
|
|
266
|
+
logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
yield ensureRoutineExists(projectConfig.name);
|
|
270
|
+
const isProdSuccess = yield commitAndDeployVersion(projectConfig, projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.entry, (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory, description, targetPath, 'all');
|
|
271
|
+
if (isProdSuccess) {
|
|
272
|
+
yield displayDeploySuccess((_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '');
|
|
273
|
+
}
|
|
274
|
+
return isProdSuccess;
|
|
275
|
+
});
|
|
276
|
+
}
|
package/dist/commands/config.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import spawn from 'cross-spawn';
|
|
3
|
-
import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
|
|
4
3
|
import t from '../i18n/index.js';
|
|
5
4
|
import logger from '../libs/logger.js';
|
|
5
|
+
import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
|
|
6
6
|
const editConfigFile = (configPath) => {
|
|
7
7
|
const editor = process.env.EDITOR || 'vi';
|
|
8
8
|
spawn(editor, [configPath], {
|
|
@@ -7,16 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import moment from 'moment';
|
|
10
12
|
import SelectItems from '../../components/selectInput.js';
|
|
11
13
|
import { yesNoPrompt } from '../../components/yesNoPrompt.js';
|
|
14
|
+
import t from '../../i18n/index.js';
|
|
12
15
|
import { PublishType } from '../../libs/interface.js';
|
|
13
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
14
|
-
import { descriptionInput } from '../../components/descriptionInput.js';
|
|
15
|
-
import { readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
|
|
16
|
-
import { createEdgeRoutine, releaseOfficialVersion, uploadEdgeRoutineCode } from '../commit/index.js';
|
|
17
16
|
import logger from '../../libs/logger.js';
|
|
18
|
-
import t from '../../i18n/index.js';
|
|
19
|
-
import prodBuild from '../commit/prodBuild.js';
|
|
20
17
|
export function yesNoPromptAndExecute(message, execute) {
|
|
21
18
|
return new Promise((resolve) => {
|
|
22
19
|
yesNoPrompt((item) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -47,7 +44,7 @@ export function promptSelectVersion(versionList) {
|
|
|
47
44
|
SelectItems({ items, handleSelect: handleSelection });
|
|
48
45
|
});
|
|
49
46
|
}
|
|
50
|
-
export function
|
|
47
|
+
export function displaySelectDeployEnv() {
|
|
51
48
|
logger.log(`📃 ${t('deploy_env_select_description').d('Please select which environment you want to deploy')}`);
|
|
52
49
|
const selectItems = [
|
|
53
50
|
{ label: t('deploy_env_staging').d('Staging'), value: PublishType.Staging },
|
|
@@ -63,35 +60,33 @@ export function displaySelectDeployType() {
|
|
|
63
60
|
SelectItems({ items: selectItems, handleSelect: handleSelection });
|
|
64
61
|
});
|
|
65
62
|
}
|
|
66
|
-
export function
|
|
67
|
-
return __awaiter(this,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return yield releaseOfficialVersion(edgeRoutine);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
logger.error(`
|
|
93
|
-
${t('deploy_error').d('An error occurred during the creation or publishing process')}: ${error}`);
|
|
94
|
-
return false;
|
|
63
|
+
export function displayVersionList(allVersions, stagingVersions, productionVersions) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
var _a, _b, _c;
|
|
66
|
+
logger.log(`${chalk.bgYellow('Active')} ${t('deploy_env_staging').d('Staging')}`);
|
|
67
|
+
logger.log(`${chalk.bgGreen('Active')} ${t('deploy_env_production').d('Production')}`);
|
|
68
|
+
const data = [];
|
|
69
|
+
for (let i = 0; i < allVersions.length; i++) {
|
|
70
|
+
const version = allVersions[i];
|
|
71
|
+
const createTime = moment(version.createTime).format('YYYY/MM/DD HH:mm:ss');
|
|
72
|
+
const tags = [
|
|
73
|
+
stagingVersions.includes((_a = version.codeVersion) !== null && _a !== void 0 ? _a : '')
|
|
74
|
+
? chalk.bgYellow('Active')
|
|
75
|
+
: '',
|
|
76
|
+
productionVersions.includes((_b = version.codeVersion) !== null && _b !== void 0 ? _b : '')
|
|
77
|
+
? chalk.bgGreen('Active')
|
|
78
|
+
: ''
|
|
79
|
+
];
|
|
80
|
+
data.push([
|
|
81
|
+
`${version.codeVersion} ${tags.join(' ')}`,
|
|
82
|
+
createTime,
|
|
83
|
+
(_c = version.codeDescription) !== null && _c !== void 0 ? _c : ''
|
|
84
|
+
]);
|
|
95
85
|
}
|
|
86
|
+
logger.table([
|
|
87
|
+
t('deploy_table_header_version').d('Version'),
|
|
88
|
+
t('deploy_table_header_created').d('Created'),
|
|
89
|
+
t('deploy_table_header_description').d('Description')
|
|
90
|
+
], data);
|
|
96
91
|
});
|
|
97
92
|
}
|