esa-cli 0.0.2-beta.12 → 0.0.2-beta.13
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 +416 -76
- package/dist/commands/init/template.jsonc +34 -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 -4
- package/dist/libs/logger.js +63 -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 +17 -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,19 +7,9 @@ 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 { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
|
|
12
|
-
import { Environment, PublishType } from '../../libs/interface.js';
|
|
13
|
-
import logger from '../../libs/logger.js';
|
|
14
|
-
import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
|
|
15
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
16
|
-
import { createAndDeployVersion, displaySelectDeployType, promptSelectVersion, yesNoPromptAndExecute } from './helper.js';
|
|
17
|
-
import t from '../../i18n/index.js';
|
|
18
|
-
import prodBuild from '../commit/prodBuild.js';
|
|
19
10
|
import { exit } from 'process';
|
|
20
|
-
import
|
|
21
|
-
import {
|
|
22
|
-
import moment from 'moment';
|
|
11
|
+
import t from '../../i18n/index.js';
|
|
12
|
+
import { validateAndInitializeProject, commitAndDeployVersion, displayDeploySuccess } from '../common/routineUtils.js';
|
|
23
13
|
const deploy = {
|
|
24
14
|
command: 'deploy [entry]',
|
|
25
15
|
builder: (yargs) => {
|
|
@@ -28,11 +18,6 @@ const deploy = {
|
|
|
28
18
|
describe: t('dev_entry_describe').d('Entry file of the Routine'),
|
|
29
19
|
type: 'string',
|
|
30
20
|
demandOption: false
|
|
31
|
-
})
|
|
32
|
-
.option('quick', {
|
|
33
|
-
alias: 'q',
|
|
34
|
-
describe: t('deploy_quick_describe').d('Quick deploy the routine to production environment'),
|
|
35
|
-
type: 'boolean'
|
|
36
21
|
})
|
|
37
22
|
.option('version', {
|
|
38
23
|
alias: 'v',
|
|
@@ -44,6 +29,31 @@ const deploy = {
|
|
|
44
29
|
describe: t('deploy_option_environment').d('Environment to deploy to: staging or production (skip interactive selection)'),
|
|
45
30
|
type: 'string',
|
|
46
31
|
choices: ['staging', 'production']
|
|
32
|
+
})
|
|
33
|
+
.option('name', {
|
|
34
|
+
alias: 'n',
|
|
35
|
+
describe: t('deploy_option_name').d('Name of the routine'),
|
|
36
|
+
type: 'string'
|
|
37
|
+
})
|
|
38
|
+
.option('assets', {
|
|
39
|
+
alias: 'a',
|
|
40
|
+
describe: t('deploy_option_assets').d('Deploy assets'),
|
|
41
|
+
type: 'boolean'
|
|
42
|
+
})
|
|
43
|
+
.option('description', {
|
|
44
|
+
alias: 'd',
|
|
45
|
+
describe: t('deploy_option_description').d('Description of the version'),
|
|
46
|
+
type: 'string'
|
|
47
|
+
})
|
|
48
|
+
.option('minify', {
|
|
49
|
+
alias: 'm',
|
|
50
|
+
describe: t('deploy_option_minify').d('Minify the code'),
|
|
51
|
+
type: 'boolean'
|
|
52
|
+
})
|
|
53
|
+
.option('minify', {
|
|
54
|
+
alias: 'm',
|
|
55
|
+
describe: t('deploy_option_minify').d('Minify the code'),
|
|
56
|
+
type: 'boolean'
|
|
47
57
|
});
|
|
48
58
|
},
|
|
49
59
|
describe: `🚀 ${t('deploy_describe').d('Deploy your project')}`,
|
|
@@ -52,157 +62,60 @@ const deploy = {
|
|
|
52
62
|
exit();
|
|
53
63
|
})
|
|
54
64
|
};
|
|
55
|
-
export default deploy;
|
|
56
|
-
export function quickDeploy(entry, projectConfig) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const server = yield ApiService.getInstance();
|
|
59
|
-
const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
|
|
60
|
-
yield prodBuild(false, entryFile, entry);
|
|
61
|
-
const code = readEdgeRoutineFile(entry) || '';
|
|
62
|
-
const res = yield server.quickDeployRoutine({
|
|
63
|
-
name: projectConfig.name,
|
|
64
|
-
code: code
|
|
65
|
-
});
|
|
66
|
-
if (res) {
|
|
67
|
-
logger.success(t('quick_deploy_success').d('Your code has been successfully deployed'));
|
|
68
|
-
logger.log(`👉 ${t('quick_deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
logger.error(t('quick_deploy_failed').d('Quick deploy failed'));
|
|
72
|
-
throw Error(t('quick_deploy_failed').d('Quick deploy failed'));
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
65
|
export function handleDeploy(argv) {
|
|
77
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
var _a, _b, _c, _d;
|
|
79
|
-
if (!checkDirectory()) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const projectConfig = getProjectConfig();
|
|
83
|
-
if (!projectConfig)
|
|
84
|
-
return logger.notInProject();
|
|
85
|
-
const isSuccess = yield checkIsLoginSuccess();
|
|
86
|
-
if (!isSuccess)
|
|
87
|
-
return;
|
|
88
|
-
const server = yield ApiService.getInstance();
|
|
89
|
-
const entry = argv.entry;
|
|
90
|
-
yield checkRoutineExist(projectConfig.name, entry);
|
|
91
|
-
const req = { Name: projectConfig.name };
|
|
92
|
-
const routineDetail = yield server.getRoutine(req, false);
|
|
93
|
-
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
94
|
-
const customEntry = argv.entry;
|
|
95
|
-
const stagingVersion = (_b = (_a = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _a === void 0 ? void 0 : _a.Envs[1]) === null || _b === void 0 ? void 0 : _b.CodeVersion;
|
|
96
|
-
const productionVersion = (_d = (_c = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _c === void 0 ? void 0 : _c.Envs[0]) === null || _d === void 0 ? void 0 : _d.CodeVersion;
|
|
97
|
-
if (argv.quick) {
|
|
98
|
-
yield quickDeploy(customEntry, projectConfig);
|
|
99
|
-
exit(0);
|
|
100
|
-
}
|
|
101
|
-
if (versionList.length === 0) {
|
|
102
|
-
logger.log(t('no_formal_version_found').d('No formal version found, you need to create a version first.'));
|
|
103
|
-
yield handleOnlyUnstableVersionFound(projectConfig, customEntry);
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
yield displayVersionList(versionList, stagingVersion, productionVersion);
|
|
107
|
-
let selectedVersion;
|
|
108
|
-
let selectedType;
|
|
109
|
-
// Check if version and environment are provided via command line arguments
|
|
110
|
-
if (argv.version && argv.environment) {
|
|
111
|
-
// Validate version exists
|
|
112
|
-
const versionExists = versionList.some((v) => v.codeVersion === argv.version);
|
|
113
|
-
if (!versionExists) {
|
|
114
|
-
logger.error(t('deploy_version_not_found').d(`Version '${argv.version}' not found`));
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
selectedVersion = argv.version;
|
|
118
|
-
selectedType =
|
|
119
|
-
argv.environment === 'staging'
|
|
120
|
-
? PublishType.Staging
|
|
121
|
-
: PublishType.Production;
|
|
122
|
-
logger.log(chalk.bold(`${t('deploy_using_version').d('Using version')}: ${selectedVersion}`));
|
|
123
|
-
logger.log(chalk.bold(`${t('deploy_using_environment').d('Using environment')}: ${argv.environment}`));
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
logger.log(chalk.bold(`${t('deploy_version_select').d('Select the version you want to publish')}:`));
|
|
127
|
-
selectedVersion = yield promptSelectVersion(versionList);
|
|
128
|
-
selectedType = yield displaySelectDeployType();
|
|
129
|
-
}
|
|
130
|
-
yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
function handleNoVersionsFound(projectConfig, customEntry) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
logger.log(`😄 ${t('deploy_first_time').d("This is first time to deploy. Let's create a version first!")}`);
|
|
137
|
-
const created = yield yesNoPromptAndExecute(`📃 ${t('deploy_create_formal_version_ques').d('Do you want to create an unstable version now?')}`, () => createAndDeployVersion(projectConfig, true));
|
|
138
|
-
if (created) {
|
|
139
|
-
yield handleOnlyUnstableVersionFound(projectConfig);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
function promptAndDeployVersion(projectConfig) {
|
|
144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
146
|
-
yield displayVersionList(versionList);
|
|
147
|
-
logger.log(`📃 ${t('deploy_select_version').d("Select which version you'd like to deploy")}`);
|
|
148
|
-
const selectedVersion = yield promptSelectVersion(versionList);
|
|
149
|
-
const selectedType = yield displaySelectDeployType();
|
|
150
|
-
yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
export function handleOnlyUnstableVersionFound(projectConfig, customEntry) {
|
|
154
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const created = yield yesNoPromptAndExecute(`📃 ${t('deploy_create_formal_version_ques').d('Do you want to create a formal version to deploy on production environment?')}`, () => createAndDeployVersion(projectConfig));
|
|
156
|
-
if (created) {
|
|
157
|
-
yield promptAndDeployVersion(projectConfig);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
export function deploySelectedCodeVersion(name, selectedType, version) {
|
|
162
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
const server = yield ApiService.getInstance();
|
|
164
|
-
const param = {
|
|
165
|
-
Name: name,
|
|
166
|
-
Env: selectedType === PublishType.Staging
|
|
167
|
-
? Environment.Staging
|
|
168
|
-
: Environment.Production
|
|
169
|
-
};
|
|
170
|
-
param.CodeVersion = version;
|
|
171
|
-
try {
|
|
172
|
-
const res = yield server.publishRoutineCodeVersion(param);
|
|
173
|
-
if (res) {
|
|
174
|
-
logger.success(t('deploy_success').d('Your code has been successfully deployed'));
|
|
175
|
-
logger.log(`👉 ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (e) {
|
|
179
|
-
console.error(e);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
export function displayVersionList(versionList_1) {
|
|
184
|
-
return __awaiter(this, arguments, void 0, function* (versionList, stagingVersion = 'unstable', productionVersion = 'unstable') {
|
|
185
67
|
var _a;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
];
|
|
196
|
-
data.push([
|
|
197
|
-
`${version.codeVersion} ${tags.join(' ')}`,
|
|
198
|
-
createTime,
|
|
199
|
-
(_a = version.codeDescription) !== null && _a !== void 0 ? _a : ''
|
|
200
|
-
]);
|
|
68
|
+
const projectInfo = yield validateAndInitializeProject(argv === null || argv === void 0 ? void 0 : argv.name);
|
|
69
|
+
if (!projectInfo)
|
|
70
|
+
return;
|
|
71
|
+
const { projectConfig, projectName } = projectInfo;
|
|
72
|
+
const entry = argv.entry || projectConfig.entry;
|
|
73
|
+
const assets = argv.assets || ((_a = projectConfig.assets) === null || _a === void 0 ? void 0 : _a.directory);
|
|
74
|
+
const success = yield commitAndDeployVersion(projectConfig, entry, assets, argv.description || '', undefined, argv.environment, argv.minify, argv.version);
|
|
75
|
+
if (success) {
|
|
76
|
+
yield displayDeploySuccess(projectName, true, false);
|
|
201
77
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
78
|
+
// if (allVersions.length === 0) {
|
|
79
|
+
// logger.log(
|
|
80
|
+
// t('no_formal_version_found').d(
|
|
81
|
+
// 'No formal version found, you need to create a version first.'
|
|
82
|
+
// )
|
|
83
|
+
// );
|
|
84
|
+
// const commitRes = await generateCodeVersion(projectName, '', entry, assets);
|
|
85
|
+
// if (!commitRes?.isSuccess) {
|
|
86
|
+
// exit(0);
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
// const {
|
|
90
|
+
// allVersions: committedVersionList,
|
|
91
|
+
// stagingVersions,
|
|
92
|
+
// productionVersions
|
|
93
|
+
// } = await getRoutineCodeVersions(projectName);
|
|
94
|
+
// await displayVersionList(
|
|
95
|
+
// committedVersionList,
|
|
96
|
+
// stagingVersions,
|
|
97
|
+
// productionVersions
|
|
98
|
+
// );
|
|
99
|
+
// const selectedVersion =
|
|
100
|
+
// (argv.version as string) ||
|
|
101
|
+
// (await promptSelectVersion(committedVersionList));
|
|
102
|
+
// const selectedEnvironment =
|
|
103
|
+
// (argv.environment as string) || (await displaySelectDeployEnv());
|
|
104
|
+
// if (
|
|
105
|
+
// selectedEnvironment !== PublishType.Staging &&
|
|
106
|
+
// selectedEnvironment !== PublishType.Production
|
|
107
|
+
// ) {
|
|
108
|
+
// logger.error(t('deploy_invalid_environment').d('Invalid environment'));
|
|
109
|
+
// exit(0);
|
|
110
|
+
// }
|
|
111
|
+
// const success = await deployCodeVersion(
|
|
112
|
+
// projectName,
|
|
113
|
+
// selectedVersion,
|
|
114
|
+
// selectedEnvironment as PublishType
|
|
115
|
+
// );
|
|
116
|
+
// if (success) {
|
|
117
|
+
// await displayDeploySuccess(projectName, true, true);
|
|
118
|
+
// }
|
|
207
119
|
});
|
|
208
120
|
}
|
|
121
|
+
export default deploy;
|
|
@@ -7,13 +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
|
|
11
|
-
import {
|
|
12
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
10
|
+
import chalk from 'chalk';
|
|
11
|
+
import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
|
|
13
12
|
import t from '../../i18n/index.js';
|
|
13
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
14
14
|
import logger from '../../libs/logger.js';
|
|
15
|
-
import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
|
|
16
15
|
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
16
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
17
|
+
import { checkDirectory, checkIsLoginSuccess, getRoutineCodeVersions } from '../utils.js';
|
|
17
18
|
const deploymentsDelete = {
|
|
18
19
|
command: 'delete [deploymentId..]',
|
|
19
20
|
describe: `🗑 ${t('deployments_delete_describe').d('Delete one or more deployment versions')}`,
|
|
@@ -50,13 +51,37 @@ export function handleDeleteDeployments(argv) {
|
|
|
50
51
|
let versions = argv.deploymentId;
|
|
51
52
|
const isInteractive = argv.i;
|
|
52
53
|
if (isInteractive) {
|
|
53
|
-
const
|
|
54
|
+
const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name);
|
|
55
|
+
// 显示正在部署的版本信息
|
|
56
|
+
if (stagingVersions.length > 0 || productionVersions.length > 0) {
|
|
57
|
+
logger.log(chalk.yellow('⚠️ Currently deploying versions:'));
|
|
58
|
+
if (stagingVersions.length > 0) {
|
|
59
|
+
logger.log(chalk.yellow(` Staging: ${stagingVersions.join(',')}`));
|
|
60
|
+
}
|
|
61
|
+
if (productionVersions.length > 0) {
|
|
62
|
+
logger.log(chalk.yellow(` Production: ${productionVersions.join(',')}`));
|
|
63
|
+
}
|
|
64
|
+
logger.log('');
|
|
65
|
+
}
|
|
54
66
|
logger.log(t('delete_deployments_table_title').d(' Version ID Description'));
|
|
55
|
-
|
|
67
|
+
// 过滤掉正在部署的版本
|
|
68
|
+
const selectList = allVersions
|
|
69
|
+
.filter((item) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (stagingVersions.length === 0 && productionVersions.length === 0)
|
|
72
|
+
return true;
|
|
73
|
+
return (!stagingVersions.includes((_a = item.codeVersion) !== null && _a !== void 0 ? _a : '') &&
|
|
74
|
+
!productionVersions.includes((_b = item.codeVersion) !== null && _b !== void 0 ? _b : ''));
|
|
75
|
+
})
|
|
76
|
+
.map((item) => {
|
|
56
77
|
return {
|
|
57
78
|
label: item.codeVersion + ' ' + item.codeDescription
|
|
58
79
|
};
|
|
59
80
|
});
|
|
81
|
+
if (selectList.length === 0) {
|
|
82
|
+
logger.error('No deletable versions found. All versions are currently deployed.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
60
85
|
versions = (yield displayMultiSelectTable(selectList, 1, 100)).map((item) => item.slice(0, item.indexOf(' ')));
|
|
61
86
|
}
|
|
62
87
|
for (let i = 0; i < versions.length; i++) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import deploymentsList from './list.js';
|
|
2
|
-
import deploymentsDelete from './delete.js';
|
|
3
1
|
import t from '../../i18n/index.js';
|
|
2
|
+
import deploymentsDelete from './delete.js';
|
|
3
|
+
import deploymentsList from './list.js';
|
|
4
4
|
let yargsIns;
|
|
5
5
|
const deploymentsCommand = {
|
|
6
6
|
command: 'deployments [script]',
|
|
7
|
-
describe:
|
|
7
|
+
describe: `🚀 ${t('deployments_describe').d('Manage your deployments')}`,
|
|
8
8
|
builder: (yargs) => {
|
|
9
9
|
yargsIns = yargs;
|
|
10
10
|
return yargs
|
|
@@ -7,28 +7,24 @@ 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 { displayVersionList } from '../deploy/index.js';
|
|
11
|
-
import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
|
|
12
|
-
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
13
10
|
import chalk from 'chalk';
|
|
14
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
15
11
|
import t from '../../i18n/index.js';
|
|
12
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
16
13
|
import logger from '../../libs/logger.js';
|
|
17
14
|
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
15
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
16
|
+
import { displayVersionList } from '../deploy/helper.js';
|
|
17
|
+
import { checkIsLoginSuccess, getRoutineCodeVersions } from '../utils.js';
|
|
18
18
|
const deploymentsList = {
|
|
19
19
|
command: 'list',
|
|
20
20
|
describe: `🔍 ${t('deployments_list_describe').d('List all deployments')}`,
|
|
21
|
-
handler: (
|
|
22
|
-
handleListDeployments(
|
|
21
|
+
handler: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
handleListDeployments();
|
|
23
23
|
})
|
|
24
24
|
};
|
|
25
25
|
export default deploymentsList;
|
|
26
|
-
export function handleListDeployments(
|
|
26
|
+
export function handleListDeployments() {
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
var _a, _b, _c, _d;
|
|
29
|
-
if (!checkDirectory()) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
28
|
const projectConfig = getProjectConfig();
|
|
33
29
|
if (!projectConfig)
|
|
34
30
|
return logger.notInProject();
|
|
@@ -37,45 +33,40 @@ export function handleListDeployments(argv) {
|
|
|
37
33
|
return;
|
|
38
34
|
yield validRoutine(projectConfig.name);
|
|
39
35
|
const server = yield ApiService.getInstance();
|
|
40
|
-
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
41
36
|
const req = { Name: projectConfig.name };
|
|
42
37
|
const routineDetail = yield server.getRoutine(req);
|
|
43
38
|
if (!routineDetail)
|
|
44
39
|
return;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const productionVersion = (_d = (_c = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _c === void 0 ? void 0 : _c.Envs[0]) === null || _d === void 0 ? void 0 : _d.CodeVersion;
|
|
49
|
-
yield displayListPrompt(routineDetail);
|
|
50
|
-
yield displayVersionList(versionList, stagingVersion, productionVersion);
|
|
40
|
+
const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name);
|
|
41
|
+
yield displayDeployingVersions(routineDetail, stagingVersions, productionVersions);
|
|
42
|
+
yield displayVersionList(allVersions, stagingVersions, productionVersions);
|
|
51
43
|
});
|
|
52
44
|
}
|
|
53
|
-
function
|
|
45
|
+
function displayDeployingVersions(routineDetail, stagingVersions, productionVersions) {
|
|
54
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
55
47
|
var _a, _b;
|
|
56
|
-
const stagingEnv = routineDetail.data.Envs[1];
|
|
57
|
-
const prodEnv = routineDetail.data.Envs[0];
|
|
58
48
|
const server = yield ApiService.getInstance();
|
|
59
49
|
const res = yield server.getRoutineStagingEnvIp();
|
|
60
50
|
const stagingIpList = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.IPV4) !== null && _b !== void 0 ? _b : [];
|
|
61
51
|
const coloredStagingIpList = stagingIpList.map((ip) => {
|
|
62
52
|
return chalk.green(ip);
|
|
63
53
|
});
|
|
64
|
-
const showEnvTable = (version
|
|
54
|
+
const showEnvTable = (version) => {
|
|
65
55
|
const data = [{ Version: version }];
|
|
66
|
-
if (region) {
|
|
67
|
-
data.push({ Region: region });
|
|
68
|
-
}
|
|
69
56
|
logger.table([], data);
|
|
70
57
|
};
|
|
71
58
|
logger.log(chalk.bold(t('deploy_env_staging').d('Staging')));
|
|
72
59
|
if (stagingIpList.length > 0) {
|
|
73
60
|
logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`);
|
|
74
61
|
}
|
|
75
|
-
|
|
62
|
+
if (stagingVersions.length > 0) {
|
|
63
|
+
showEnvTable(stagingVersions.join(','));
|
|
64
|
+
}
|
|
76
65
|
logger.block();
|
|
77
66
|
logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${chalk.green('●')}`)}`);
|
|
78
|
-
|
|
67
|
+
if (productionVersions.length > 0) {
|
|
68
|
+
showEnvTable(productionVersions.join(','));
|
|
69
|
+
}
|
|
79
70
|
logger.log(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`);
|
|
80
71
|
logger.info(routineDetail.data.DefaultRelatedRecord);
|
|
81
72
|
logger.block();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import _generator from '@babel/generator';
|
|
4
|
+
import parser from '@babel/parser';
|
|
5
|
+
import _traverse from '@babel/traverse';
|
|
3
6
|
import esbuild from 'esbuild';
|
|
4
7
|
import { lessLoader } from 'esbuild-plugin-less';
|
|
5
8
|
import { getRoot } from '../../utils/fileUtils/base.js';
|
|
6
9
|
import { NODE_EXTERNALS } from '../common/constant.js';
|
|
7
|
-
import parser from '@babel/parser';
|
|
8
|
-
import _traverse from '@babel/traverse';
|
|
9
|
-
import _generator from '@babel/generator';
|
|
10
10
|
const replacements = { cache: 'mockCache', EdgeKV: 'mockKV' };
|
|
11
11
|
const traverse = _traverse.default;
|
|
12
12
|
const generator = _generator.default;
|
|
@@ -7,14 +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 React, { useEffect } from 'react';
|
|
11
|
-
import { Box, Text, useApp, useInput, render } from 'ink';
|
|
12
10
|
import chalk from 'chalk';
|
|
11
|
+
import { Box, Text, useApp, useInput, render } from 'ink';
|
|
12
|
+
import React, { useEffect } from 'react';
|
|
13
|
+
import t from '../../i18n/index.js';
|
|
13
14
|
import logger from '../../libs/logger.js';
|
|
14
|
-
import openInBrowser from '../../utils/openInBrowser.js';
|
|
15
|
-
import { getDevOpenBrowserUrl } from '../../utils/fileUtils/index.js';
|
|
16
15
|
import { checkOS, Platforms } from '../../utils/checkOS.js';
|
|
17
|
-
import
|
|
16
|
+
import { getDevOpenBrowserUrl } from '../../utils/fileUtils/index.js';
|
|
17
|
+
import openInBrowser from '../../utils/openInBrowser.js';
|
|
18
18
|
const InteractionBox = ({ worker }) => {
|
|
19
19
|
const { exit } = useApp();
|
|
20
20
|
const inspectLink = chalk.underline.blue('chrome://inspect/#devices');
|
|
@@ -7,15 +7,15 @@ 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 path from 'path';
|
|
11
10
|
import fs from 'fs';
|
|
12
|
-
import
|
|
13
|
-
import devBuild from '../build.js';
|
|
11
|
+
import path from 'path';
|
|
14
12
|
import t from '../../../i18n/index.js';
|
|
15
|
-
import
|
|
16
|
-
import { getRoot, getDirName } from '../../../utils/fileUtils/base.js';
|
|
13
|
+
import logger from '../../../libs/logger.js';
|
|
17
14
|
import { checkPort } from '../../../utils/checkDevPort.js';
|
|
15
|
+
import { getRoot, getDirName } from '../../../utils/fileUtils/base.js';
|
|
16
|
+
import { getDevConf } from '../../../utils/fileUtils/index.js';
|
|
18
17
|
import { EW2Path } from '../../../utils/installEw2.js';
|
|
18
|
+
import devBuild from '../build.js';
|
|
19
19
|
// 生成可用的Ew2端口
|
|
20
20
|
const generateEw2Port = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
let ew2port = 3322;
|
|
@@ -129,13 +129,22 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
|
|
|
129
129
|
}
|
|
130
130
|
return fs.promises.writeFile(configPath, `export default ${JSON.stringify(Object.assign(options, { [id]: currentOptions }))}`);
|
|
131
131
|
});
|
|
132
|
-
const devPack = (
|
|
132
|
+
const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
133
|
logger.ora.start('Processing...\n');
|
|
134
134
|
const userRoot = getRoot();
|
|
135
|
-
|
|
135
|
+
// Try to find config file in order of preference: .jsonc, .toml
|
|
136
|
+
const configFormats = ['esa.jsonc', 'esa.toml'];
|
|
137
|
+
let configPath = null;
|
|
138
|
+
for (const format of configFormats) {
|
|
139
|
+
const testPath = path.resolve(userRoot, format);
|
|
140
|
+
if (fs.existsSync(testPath)) {
|
|
141
|
+
configPath = testPath;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
136
145
|
let port, minify, localUpstream, entry;
|
|
137
146
|
let projectEntry = path.resolve(userRoot, 'src/index.js');
|
|
138
|
-
if (
|
|
147
|
+
if (configPath) {
|
|
139
148
|
port = getDevConf('port', 'dev', 18080);
|
|
140
149
|
minify = getDevConf('minify', 'dev', false);
|
|
141
150
|
localUpstream = getDevConf('localUpstream', 'dev', '');
|
|
@@ -134,10 +134,10 @@ class EdgeKV {
|
|
|
134
134
|
);
|
|
135
135
|
}
|
|
136
136
|
case 'stream':
|
|
137
|
-
const
|
|
137
|
+
const stream = fetchRes.body;
|
|
138
138
|
return new ReadableStream({
|
|
139
139
|
start(controller) {
|
|
140
|
-
controller.enqueue(new TextEncoder().encode(
|
|
140
|
+
controller.enqueue(new TextEncoder().encode('hello world'));
|
|
141
141
|
controller.close();
|
|
142
142
|
}
|
|
143
143
|
});
|
|
@@ -8,17 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import * as http from 'http';
|
|
11
|
+
import chalk from 'chalk';
|
|
11
12
|
import spawn from 'cross-spawn';
|
|
13
|
+
import { HttpProxyAgent } from 'http-proxy-agent';
|
|
12
14
|
import fetch from 'node-fetch';
|
|
15
|
+
import t from '../../../i18n/index.js';
|
|
13
16
|
import logger from '../../../libs/logger.js';
|
|
14
17
|
import { getRoot } from '../../../utils/fileUtils/base.js';
|
|
15
18
|
import { EW2BinPath } from '../../../utils/installEw2.js';
|
|
16
|
-
import
|
|
17
|
-
import chalk from 'chalk';
|
|
19
|
+
import sleep from '../../../utils/sleep.js';
|
|
18
20
|
import CacheService from './cacheService.js';
|
|
19
21
|
import EdgeKV from './kvService.js';
|
|
20
|
-
import t from '../../../i18n/index.js';
|
|
21
|
-
import sleep from '../../../utils/sleep.js';
|
|
22
22
|
const getColorForStatusCode = (statusCode, message) => {
|
|
23
23
|
if (statusCode >= 100 && statusCode < 200) {
|
|
24
24
|
return chalk.blue(`${statusCode} ${message}`);
|
|
@@ -87,8 +87,9 @@ class Ew2Server {
|
|
|
87
87
|
stdio: ['pipe', 'pipe', 'pipe']
|
|
88
88
|
});
|
|
89
89
|
this.workerStartTimeout = setTimeout(() => {
|
|
90
|
+
var _a;
|
|
90
91
|
reject(new Error(t('dev_worker_timeout').d('Worker start timeout')));
|
|
91
|
-
this.worker
|
|
92
|
+
(_a = this.worker) === null || _a === void 0 ? void 0 : _a.kill();
|
|
92
93
|
}, 60000);
|
|
93
94
|
const sendToRuntime = () => {
|
|
94
95
|
return new Promise((resolveStart) => {
|
|
@@ -102,7 +103,7 @@ class Ew2Server {
|
|
|
102
103
|
const req = http.get(options, (res) => {
|
|
103
104
|
resolveStart(res.statusCode);
|
|
104
105
|
});
|
|
105
|
-
req.on('error', (
|
|
106
|
+
req.on('error', () => {
|
|
106
107
|
resolveStart(null);
|
|
107
108
|
});
|
|
108
109
|
req.end();
|
|
@@ -125,7 +126,8 @@ class Ew2Server {
|
|
|
125
126
|
this.worker.on('close', this.closeHandler.bind(this));
|
|
126
127
|
this.worker.on('error', this.errorHandler.bind(this));
|
|
127
128
|
process.on('SIGTERM', () => {
|
|
128
|
-
|
|
129
|
+
var _a;
|
|
130
|
+
(_a = this.worker) === null || _a === void 0 ? void 0 : _a.kill();
|
|
129
131
|
});
|
|
130
132
|
});
|
|
131
133
|
}
|
|
@@ -277,17 +279,18 @@ class Ew2Server {
|
|
|
277
279
|
}
|
|
278
280
|
this.stop();
|
|
279
281
|
}
|
|
280
|
-
closeHandler(
|
|
282
|
+
closeHandler() {
|
|
281
283
|
if (this.restarting) {
|
|
282
284
|
this.restarting = false;
|
|
283
285
|
return;
|
|
284
286
|
}
|
|
285
287
|
this.stop().then(() => {
|
|
288
|
+
var _a;
|
|
286
289
|
logger.log(t('dev_server_closed').d('Worker server closed'));
|
|
287
290
|
logger.info('Worker server closed');
|
|
288
291
|
// @ts-ignore
|
|
289
292
|
global.port = undefined;
|
|
290
|
-
this.onClose
|
|
293
|
+
(_a = this.onClose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
291
294
|
});
|
|
292
295
|
}
|
|
293
296
|
parseCacheBody(req) {
|
|
@@ -343,7 +346,7 @@ class Ew2Server {
|
|
|
343
346
|
resolve(false);
|
|
344
347
|
return;
|
|
345
348
|
}
|
|
346
|
-
const onExit = (
|
|
349
|
+
const onExit = () => {
|
|
347
350
|
this.worker = null;
|
|
348
351
|
resolve(true);
|
|
349
352
|
};
|