esa-cli 0.0.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -149
- package/dist/commands/commit/index.js +49 -104
- package/dist/commands/commit/prodBuild.js +2 -3
- package/dist/commands/common/constant.js +4 -4
- package/dist/commands/common/utils.js +419 -0
- package/dist/commands/config.js +2 -2
- package/dist/commands/deploy/helper.js +43 -49
- package/dist/commands/deploy/index.js +51 -174
- package/dist/commands/deployments/delete.js +32 -22
- package/dist/commands/deployments/index.js +4 -4
- package/dist/commands/deployments/list.js +21 -34
- package/dist/commands/dev/build.js +3 -3
- package/dist/commands/dev/doProcess.js +5 -5
- package/dist/commands/dev/ew2/cacheService.js +33 -0
- package/dist/commands/dev/ew2/devEntry.js +2 -1
- package/dist/commands/dev/ew2/devPack.js +31 -20
- package/dist/commands/dev/ew2/kvService.js +50 -0
- package/dist/commands/dev/ew2/mock/cache.js +99 -15
- package/dist/commands/dev/ew2/mock/kv.js +142 -21
- package/dist/commands/dev/ew2/server.js +163 -28
- package/dist/commands/dev/index.js +17 -18
- package/dist/commands/dev/mockWorker/devPack.js +19 -10
- package/dist/commands/dev/mockWorker/server.js +7 -6
- package/dist/commands/domain/add.js +4 -4
- package/dist/commands/domain/delete.js +3 -3
- package/dist/commands/domain/index.js +4 -4
- package/dist/commands/domain/list.js +7 -7
- package/dist/commands/init/helper.js +654 -21
- package/dist/commands/init/index.js +88 -152
- package/dist/commands/init/snippets/nextjs/next.config.mjs +6 -0
- package/dist/commands/init/snippets/nextjs/next.config.ts +7 -0
- package/dist/commands/init/snippets/react-router/react-router.config.ts +7 -0
- package/dist/commands/init/template.jsonc +84 -0
- package/dist/commands/init/types.js +1 -0
- package/dist/commands/lang.js +2 -2
- package/dist/commands/login/index.js +74 -34
- package/dist/commands/logout.js +6 -6
- package/dist/commands/route/add.js +101 -43
- package/dist/commands/route/delete.js +6 -6
- package/dist/commands/route/helper.js +9 -10
- package/dist/commands/route/index.js +4 -4
- package/dist/commands/route/list.js +4 -4
- package/dist/commands/routine/delete.js +9 -8
- package/dist/commands/routine/index.js +6 -5
- package/dist/commands/routine/list.js +45 -39
- package/dist/commands/site/index.js +3 -3
- package/dist/commands/site/list.js +6 -7
- package/dist/commands/utils.js +61 -25
- package/dist/components/descriptionInput.js +1 -1
- package/dist/components/filterSelector.js +1 -1
- package/dist/components/mutiLevelSelect.js +19 -20
- package/dist/components/mutiSelectTable.js +1 -1
- package/dist/components/routeBuilder.js +68 -0
- package/dist/components/selectInput.js +2 -3
- package/dist/components/selectItem.js +1 -1
- package/dist/docs/Commands_en.md +164 -117
- package/dist/docs/Commands_zh_CN.md +155 -107
- package/dist/docs/Config_en.md +70 -0
- package/dist/docs/Config_zh_CN.md +68 -0
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/locales.json +414 -82
- package/dist/index.js +28 -13
- package/dist/libs/api.js +3 -6
- package/dist/libs/apiService.js +192 -69
- package/dist/libs/git/index.js +86 -9
- package/dist/libs/interface.js +0 -1
- package/dist/libs/logger.js +162 -10
- 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 +5 -19
- package/dist/utils/checkEntryFileExist.js +10 -0
- package/dist/utils/checkIsRoutineCreated.js +27 -21
- package/dist/utils/checkVersion.js +119 -1
- package/dist/utils/command.js +149 -0
- package/dist/utils/compress.js +142 -0
- package/dist/utils/download.js +8 -8
- package/dist/utils/fileMd5.js +1 -1
- package/dist/utils/fileUtils/index.js +136 -45
- package/dist/utils/installDeno.js +4 -4
- package/dist/utils/installEw2.js +9 -9
- package/dist/utils/openInBrowser.js +1 -1
- package/dist/utils/prompt.js +97 -0
- package/package.json +23 -12
- package/zh_CN.md +29 -154
|
@@ -7,198 +7,75 @@ 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 { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
|
|
16
|
-
import { ApiService } from '../../libs/apiService.js';
|
|
17
|
-
import { createAndDeployVersion, displaySelectDeployType, promptSelectVersion, yesNoPromptAndExecute } from './helper.js';
|
|
18
|
-
import t from '../../i18n/index.js';
|
|
19
|
-
import prodBuild from '../commit/prodBuild.js';
|
|
20
10
|
import { exit } from 'process';
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
11
|
+
import { intro, outro } from '@clack/prompts';
|
|
12
|
+
import t from '../../i18n/index.js';
|
|
13
|
+
import { getRoot } from '../../utils/fileUtils/base.js';
|
|
14
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
15
|
+
import { commitAndDeployVersion, displayDeploySuccess } from '../common/utils.js';
|
|
24
16
|
const deploy = {
|
|
25
17
|
command: 'deploy [entry]',
|
|
26
18
|
builder: (yargs) => {
|
|
27
19
|
return yargs
|
|
28
20
|
.positional('entry', {
|
|
29
|
-
describe: t('dev_entry_describe').d('Entry file of
|
|
21
|
+
describe: t('dev_entry_describe').d('Entry file of Functions& Pages'),
|
|
30
22
|
type: 'string',
|
|
31
23
|
demandOption: false
|
|
32
24
|
})
|
|
33
|
-
.option('
|
|
34
|
-
alias: '
|
|
25
|
+
.option('version', {
|
|
26
|
+
alias: 'v',
|
|
27
|
+
describe: t('deploy_option_version').d('Version to deploy (skip interactive selection)'),
|
|
28
|
+
type: 'string'
|
|
29
|
+
})
|
|
30
|
+
.option('environment', {
|
|
31
|
+
alias: 'e',
|
|
32
|
+
describe: t('deploy_option_environment').d('Environment to deploy to: staging or production (skip interactive selection)'),
|
|
33
|
+
type: 'string',
|
|
34
|
+
choices: ['staging', 'production']
|
|
35
|
+
})
|
|
36
|
+
.option('name', {
|
|
37
|
+
alias: 'n',
|
|
38
|
+
describe: t('deploy_option_name').d('Name of Functions& Pages'),
|
|
39
|
+
type: 'string'
|
|
40
|
+
})
|
|
41
|
+
.option('assets', {
|
|
42
|
+
alias: 'a',
|
|
43
|
+
describe: t('deploy_option_assets').d('Deploy assets'),
|
|
44
|
+
type: 'string'
|
|
45
|
+
})
|
|
46
|
+
.option('description', {
|
|
47
|
+
alias: 'd',
|
|
48
|
+
describe: t('deploy_option_description').d('Description of the version'),
|
|
49
|
+
type: 'string'
|
|
50
|
+
})
|
|
51
|
+
.option('minify', {
|
|
52
|
+
alias: 'm',
|
|
53
|
+
describe: t('deploy_option_minify').d('Minify the code'),
|
|
35
54
|
type: 'boolean'
|
|
36
55
|
});
|
|
37
56
|
},
|
|
38
57
|
describe: `🚀 ${t('deploy_describe').d('Deploy your project')}`,
|
|
39
58
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
handleDeploy(argv);
|
|
59
|
+
yield handleDeploy(argv);
|
|
60
|
+
exit();
|
|
41
61
|
})
|
|
42
62
|
};
|
|
43
|
-
export default deploy;
|
|
44
|
-
export function quickDeploy(entry, projectConfig) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const server = yield ApiService.getInstance();
|
|
47
|
-
const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
|
|
48
|
-
yield prodBuild(false, entryFile, entry);
|
|
49
|
-
const code = readEdgeRoutineFile(entry) || '';
|
|
50
|
-
const res = yield server.quickDeployRoutine({
|
|
51
|
-
name: projectConfig.name,
|
|
52
|
-
code: code
|
|
53
|
-
});
|
|
54
|
-
if (res) {
|
|
55
|
-
logger.success(t('quick_deploy_success').d('Your code has been successfully deployed'));
|
|
56
|
-
logger.log(`👉 ${t('quick_deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
logger.error(t('quick_deploy_failed').d('Quick deploy failed'));
|
|
60
|
-
throw Error(t('quick_deploy_failed').d('Quick deploy failed'));
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
63
|
export function handleDeploy(argv) {
|
|
65
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
var _a, _b, _c, _d;
|
|
67
|
-
if (!checkDirectory()) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const projectConfig = getProjectConfig();
|
|
71
|
-
if (!projectConfig)
|
|
72
|
-
return logger.notInProject();
|
|
73
|
-
const isSuccess = yield checkIsLoginSuccess();
|
|
74
|
-
if (!isSuccess)
|
|
75
|
-
return;
|
|
76
|
-
const server = yield ApiService.getInstance();
|
|
77
|
-
const entry = argv.entry;
|
|
78
|
-
yield checkRoutineExist(projectConfig.name, entry);
|
|
79
|
-
const req = { Name: projectConfig.name };
|
|
80
|
-
const routineDetail = yield server.getRoutine(req, false);
|
|
81
|
-
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
82
|
-
const customEntry = argv.entry;
|
|
83
|
-
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;
|
|
84
|
-
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;
|
|
85
|
-
if (argv.quick) {
|
|
86
|
-
yield quickDeploy(customEntry, projectConfig);
|
|
87
|
-
exit(0);
|
|
88
|
-
}
|
|
89
|
-
if (versionList.length === 0) {
|
|
90
|
-
logger.log(t('no_formal_version_found').d('No formal version found, you need to create a version first.'));
|
|
91
|
-
yield handleOnlyUnstableVersionFound(projectConfig, customEntry);
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
yield displayVersionList(versionList, stagingVersion, productionVersion);
|
|
95
|
-
logger.log(chalk.bold(`${t('deploy_version_select').d('Select the version you want to publish')}:`));
|
|
96
|
-
const selectedVersion = yield promptSelectVersion(versionList);
|
|
97
|
-
const selectedType = yield displaySelectDeployType();
|
|
98
|
-
yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function handleNoVersionsFound(projectConfig, customEntry) {
|
|
103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
logger.log(`😄 ${t('deploy_first_time').d("This is first time to deploy. Let's create a version first!")}`);
|
|
105
|
-
const created = yield yesNoPromptAndExecute(`📃 ${t('deploy_create_formal_version_ques').d('Do you want to create an unstable version now?')}`, () => createAndDeployVersion(projectConfig, true));
|
|
106
|
-
if (created) {
|
|
107
|
-
yield handleOnlyUnstableVersionFound(projectConfig);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
function promptAndDeployVersion(projectConfig) {
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
114
|
-
yield displayVersionList(versionList);
|
|
115
|
-
logger.log(`📃 ${t('deploy_select_version').d("Select which version you'd like to deploy")}`);
|
|
116
|
-
const selectedVersion = yield promptSelectVersion(versionList);
|
|
117
|
-
const selectedType = yield displaySelectDeployType();
|
|
118
|
-
yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
const specialAreaTransfer = (canaryAreaSelectList) => {
|
|
122
|
-
return canaryAreaSelectList.map((item) => {
|
|
123
|
-
if (item.label === 'HongKong') {
|
|
124
|
-
return { label: 'HongKong(China)' };
|
|
125
|
-
}
|
|
126
|
-
if (item.label === 'Macau') {
|
|
127
|
-
return { label: 'Macau(China)' };
|
|
128
|
-
}
|
|
129
|
-
if (item.label === 'Taiwan') {
|
|
130
|
-
return { label: 'Taiwan(China)' };
|
|
131
|
-
}
|
|
132
|
-
return { label: item.label };
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
export function handleOnlyUnstableVersionFound(projectConfig, customEntry) {
|
|
136
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
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));
|
|
138
|
-
if (created) {
|
|
139
|
-
yield promptAndDeployVersion(projectConfig);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
export function deploySelectedCodeVersion(name, selectedType, version) {
|
|
144
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
-
var _a;
|
|
146
|
-
const server = yield ApiService.getInstance();
|
|
147
|
-
const param = {
|
|
148
|
-
Name: name,
|
|
149
|
-
Env: selectedType === PublishType.Staging
|
|
150
|
-
? Environment.Staging
|
|
151
|
-
: Environment.Production
|
|
152
|
-
};
|
|
153
|
-
if (selectedType === PublishType.Canary) {
|
|
154
|
-
const res = yield server.listRoutineCanaryAreas();
|
|
155
|
-
const canaryList = (_a = res === null || res === void 0 ? void 0 : res.CanaryAreas) !== null && _a !== void 0 ? _a : [];
|
|
156
|
-
logger.log(`📃 ${t('deploy_select_canary').d('Please select the canary area(s) you want to deploy to')}`);
|
|
157
|
-
const canaryAreaSelectList = canaryList.map((area) => {
|
|
158
|
-
return { label: area };
|
|
159
|
-
});
|
|
160
|
-
const selectedCanaryList = yield displayMultiSelectTable(specialAreaTransfer(canaryAreaSelectList));
|
|
161
|
-
param.CanaryAreaList = selectedCanaryList;
|
|
162
|
-
param.CanaryCodeVersion = version;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
param.CodeVersion = version;
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
const res = yield server.publishRoutineCodeVersion(param);
|
|
169
|
-
if (res) {
|
|
170
|
-
logger.success(t('deploy_success').d('Your code has been successfully deployed'));
|
|
171
|
-
logger.log(`👉 ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
catch (e) {
|
|
175
|
-
console.error(e);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
export function displayVersionList(versionList_1) {
|
|
180
|
-
return __awaiter(this, arguments, void 0, function* (versionList, stagingVersion = 'unstable', productionVersion = 'unstable') {
|
|
181
65
|
var _a;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
(_a = version.codeDescription) !== null && _a !== void 0 ? _a : ''
|
|
196
|
-
]);
|
|
197
|
-
}
|
|
198
|
-
logger.table([
|
|
199
|
-
t('deploy_table_header_version').d('Version'),
|
|
200
|
-
t('deploy_table_header_created').d('Created'),
|
|
201
|
-
t('deploy_table_header_description').d('Description')
|
|
202
|
-
], data, [30, 25, 15]);
|
|
66
|
+
const entry = argv.entry;
|
|
67
|
+
const assets = (_a = argv.assets) !== null && _a !== void 0 ? _a : undefined;
|
|
68
|
+
intro(`Deploy an application with ESA`);
|
|
69
|
+
const success = yield commitAndDeployVersion(argv.name || undefined, entry, assets, argv.description || '', getRoot(), argv.environment || 'all', argv.minify, argv.version);
|
|
70
|
+
outro(success ? 'Deploy finished' : 'Deploy failed');
|
|
71
|
+
if (success) {
|
|
72
|
+
const projectConfig = getProjectConfig(getRoot());
|
|
73
|
+
yield displayDeploySuccess(argv.name ||
|
|
74
|
+
(projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) ||
|
|
75
|
+
getRoot().split(/[\\/]/).pop() ||
|
|
76
|
+
'', true, true);
|
|
77
|
+
}
|
|
78
|
+
exit(success ? 0 : 1);
|
|
203
79
|
});
|
|
204
80
|
}
|
|
81
|
+
export default deploy;
|
|
@@ -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
|
|
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
|
-
import { Base64 } from 'js-base64';
|
|
17
15
|
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
16
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
17
|
+
import { checkDirectory, checkIsLoginSuccess, getRoutineCodeVersions } from '../utils.js';
|
|
18
18
|
const deploymentsDelete = {
|
|
19
19
|
command: 'delete [deploymentId..]',
|
|
20
20
|
describe: `🗑 ${t('deployments_delete_describe').d('Delete one or more deployment versions')}`,
|
|
@@ -49,29 +49,39 @@ export function handleDeleteDeployments(argv) {
|
|
|
49
49
|
yield validRoutine(projectConfig.name);
|
|
50
50
|
const server = yield ApiService.getInstance();
|
|
51
51
|
let versions = argv.deploymentId;
|
|
52
|
-
// const req: DeleteRoutineCodeVersionReq = {
|
|
53
|
-
// Name: projectConfig.name,
|
|
54
|
-
// CodeVersion: version
|
|
55
|
-
// };
|
|
56
|
-
// const res = await server.deleteRoutineCodeVersion(req);
|
|
57
|
-
// if (res?.Status === 'OK') {
|
|
58
|
-
// logger.success(
|
|
59
|
-
// `${t('deployments_delete_success').d('Delete success')}: ${version}`
|
|
60
|
-
// );
|
|
61
|
-
// } else {
|
|
62
|
-
// logger.error(
|
|
63
|
-
// `🙅 ${t('deployments_delete_failed').d('Delete failed')}: ${version}`
|
|
64
|
-
// );
|
|
65
|
-
// }
|
|
66
52
|
const isInteractive = argv.i;
|
|
67
53
|
if (isInteractive) {
|
|
68
|
-
const
|
|
54
|
+
const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name);
|
|
55
|
+
// Show information about versions being deployed
|
|
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
|
+
}
|
|
69
66
|
logger.log(t('delete_deployments_table_title').d(' Version ID Description'));
|
|
70
|
-
|
|
67
|
+
// Filter out versions being deployed
|
|
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) => {
|
|
71
77
|
return {
|
|
72
|
-
label: item.
|
|
78
|
+
label: item.codeVersion + ' ' + item.codeDescription
|
|
73
79
|
};
|
|
74
80
|
});
|
|
81
|
+
if (selectList.length === 0) {
|
|
82
|
+
logger.error('No deletable versions found. All versions are currently deployed.');
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
75
85
|
versions = (yield displayMultiSelectTable(selectList, 1, 100)).map((item) => item.slice(0, item.indexOf(' ')));
|
|
76
86
|
}
|
|
77
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
|
|
@@ -16,7 +16,7 @@ const deploymentsCommand = {
|
|
|
16
16
|
type: 'boolean',
|
|
17
17
|
default: false
|
|
18
18
|
})
|
|
19
|
-
.usage(`${t('common_usage').d('Usage')}: esa deployments [list | delete]`);
|
|
19
|
+
.usage(`${t('common_usage').d('Usage')}: esa-cli deployments [list | delete]`);
|
|
20
20
|
},
|
|
21
21
|
handler: (argv) => {
|
|
22
22
|
if (yargsIns && (argv.help || argv._.length < 2)) {
|
|
@@ -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,49 +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
|
-
var _a, _b
|
|
56
|
-
const isCanary = ((_a = routineDetail.data.Envs[0].CanaryAreaList) !== null && _a !== void 0 ? _a : []).length !== 0;
|
|
57
|
-
const canaryEnv = routineDetail.data.Envs[0];
|
|
58
|
-
const stagingEnv = routineDetail.data.Envs[1];
|
|
47
|
+
var _a, _b;
|
|
59
48
|
const server = yield ApiService.getInstance();
|
|
60
49
|
const res = yield server.getRoutineStagingEnvIp();
|
|
61
|
-
const stagingIpList = (
|
|
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 : [];
|
|
62
51
|
const coloredStagingIpList = stagingIpList.map((ip) => {
|
|
63
52
|
return chalk.green(ip);
|
|
64
53
|
});
|
|
65
|
-
const showEnvTable = (version
|
|
54
|
+
const showEnvTable = (version) => {
|
|
66
55
|
const data = [{ Version: version }];
|
|
67
|
-
if (region) {
|
|
68
|
-
data.push({ Region: region });
|
|
69
|
-
}
|
|
70
56
|
logger.table([], data);
|
|
71
57
|
};
|
|
72
58
|
logger.log(chalk.bold(t('deploy_env_staging').d('Staging')));
|
|
73
59
|
if (stagingIpList.length > 0) {
|
|
74
60
|
logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`);
|
|
75
61
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
showEnvTable(canaryEnv.CodeVersion);
|
|
62
|
+
if (stagingVersions.length > 0) {
|
|
63
|
+
showEnvTable(stagingVersions.join(','));
|
|
64
|
+
}
|
|
80
65
|
logger.block();
|
|
81
|
-
logger.log(`${chalk.bold(`${t('
|
|
82
|
-
|
|
66
|
+
logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${chalk.green('●')}`)}`);
|
|
67
|
+
if (productionVersions.length > 0) {
|
|
68
|
+
showEnvTable(productionVersions.join(','));
|
|
69
|
+
}
|
|
83
70
|
logger.log(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`);
|
|
84
71
|
logger.info(routineDetail.data.DefaultRelatedRecord);
|
|
85
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');
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class CacheService {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.store = new Map();
|
|
4
|
+
this.maxQuota = 100 * 1024 * 1024;
|
|
5
|
+
}
|
|
6
|
+
put(key, serializedResponse) {
|
|
7
|
+
const expires = serializedResponse.ttl === 0
|
|
8
|
+
? Infinity
|
|
9
|
+
: Date.now() + serializedResponse.ttl * 1000;
|
|
10
|
+
this.store.set(key, {
|
|
11
|
+
serializedResponse,
|
|
12
|
+
expires: expires,
|
|
13
|
+
lastUsed: Date.now()
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
get(key) {
|
|
17
|
+
const entry = this.store.get(key);
|
|
18
|
+
if (!entry || Date.now() > entry.expires) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
entry.lastUsed = Date.now();
|
|
22
|
+
return entry;
|
|
23
|
+
}
|
|
24
|
+
delete(key) {
|
|
25
|
+
return this.deleteEntry(key);
|
|
26
|
+
}
|
|
27
|
+
deleteEntry(key) {
|
|
28
|
+
if (!this.store.has(key))
|
|
29
|
+
return false;
|
|
30
|
+
return this.store.delete(key);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default CacheService;
|
|
@@ -2,8 +2,9 @@ import worker from '$userPath';
|
|
|
2
2
|
import Cache from './mock/cache.js';
|
|
3
3
|
import mockKV from './mock/kv.js';
|
|
4
4
|
|
|
5
|
-
var mock_cache =
|
|
5
|
+
var mock_cache = new Cache($userPort);
|
|
6
6
|
globalThis.mockCache = mock_cache;
|
|
7
|
+
mockKV.port = $userPort;
|
|
7
8
|
globalThis.mockKV = mockKV;
|
|
8
9
|
|
|
9
10
|
export default worker;
|
|
@@ -7,16 +7,16 @@ 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';
|
|
19
|
-
|
|
18
|
+
import devBuild from '../build.js';
|
|
19
|
+
// Generate available Ew2 port
|
|
20
20
|
const generateEw2Port = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
let ew2port = 3322;
|
|
22
22
|
let portAvailable = yield checkPort(ew2port);
|
|
@@ -60,8 +60,8 @@ conf_path = "${erConfPath}"
|
|
|
60
60
|
fs.promises.writeFile(erConfPath, erConf)
|
|
61
61
|
]);
|
|
62
62
|
};
|
|
63
|
-
//
|
|
64
|
-
const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
// Generate entry file
|
|
64
|
+
const generateEntry = (id, projectEntry, userRoot, port) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
65
|
const __dirname = getDirName(import.meta.url);
|
|
66
66
|
const devDir = path.resolve(userRoot, '.dev');
|
|
67
67
|
const devEntry = path.resolve(devDir, `devEntry-${id}.js`);
|
|
@@ -81,22 +81,24 @@ const generateEntry = (id, projectEntry, userRoot) => __awaiter(void 0, void 0,
|
|
|
81
81
|
const destPath = path.resolve(mockDevDir, file);
|
|
82
82
|
yield fs.promises.copyFile(srcPath, destPath);
|
|
83
83
|
}
|
|
84
|
-
return fs.promises.writeFile(devEntry, devEntryTempFile
|
|
84
|
+
return fs.promises.writeFile(devEntry, devEntryTempFile
|
|
85
|
+
.replace(/'\$userPath'/g, `'${projectEntry.replace(/\\/g, '/')}'`)
|
|
86
|
+
.replace(/\$userPort/g, `${port}`));
|
|
85
87
|
});
|
|
86
|
-
//
|
|
88
|
+
// Preliminary preparation
|
|
87
89
|
const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
88
90
|
const options = {};
|
|
89
91
|
const currentOptions = { entry, port, localUpstream };
|
|
90
|
-
//
|
|
92
|
+
// Support running multiple workers simultaneously
|
|
91
93
|
const id = new Date().getTime().toString();
|
|
92
94
|
// @ts-ignore
|
|
93
95
|
global.id = id;
|
|
94
|
-
//
|
|
95
|
-
yield generateEntry(id, entry, userRoot);
|
|
96
|
-
//
|
|
96
|
+
// Generate entry file
|
|
97
|
+
yield generateEntry(id, entry, userRoot, port);
|
|
98
|
+
// Generate Ew2 configuration
|
|
97
99
|
const ew2port = yield generateEw2Port();
|
|
98
100
|
yield writeEw2config(id, ew2port, userRoot);
|
|
99
|
-
//
|
|
101
|
+
// Configuration items for each dev session, distinguished by id in one file
|
|
100
102
|
if (fs.existsSync(configPath)) {
|
|
101
103
|
const currentConfig = fs
|
|
102
104
|
.readFileSync(configPath, 'utf-8')
|
|
@@ -104,7 +106,7 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
|
|
|
104
106
|
const currentConfigObj = JSON.parse(currentConfig);
|
|
105
107
|
const currentIds = Object.keys(currentConfigObj);
|
|
106
108
|
if (currentIds[0] && /^\d+$/.test(currentIds[0])) {
|
|
107
|
-
//
|
|
109
|
+
// Remove unused entries
|
|
108
110
|
for (let currentId of currentIds) {
|
|
109
111
|
const unused = yield checkPort(currentConfigObj[currentId].port);
|
|
110
112
|
if (unused) {
|
|
@@ -127,13 +129,22 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
|
|
|
127
129
|
}
|
|
128
130
|
return fs.promises.writeFile(configPath, `export default ${JSON.stringify(Object.assign(options, { [id]: currentOptions }))}`);
|
|
129
131
|
});
|
|
130
|
-
const devPack = (
|
|
132
|
+
const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
133
|
logger.ora.start('Processing...\n');
|
|
132
134
|
const userRoot = getRoot();
|
|
133
|
-
|
|
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
|
+
}
|
|
134
145
|
let port, minify, localUpstream, entry;
|
|
135
146
|
let projectEntry = path.resolve(userRoot, 'src/index.js');
|
|
136
|
-
if (
|
|
147
|
+
if (configPath) {
|
|
137
148
|
port = getDevConf('port', 'dev', 18080);
|
|
138
149
|
minify = getDevConf('minify', 'dev', false);
|
|
139
150
|
localUpstream = getDevConf('localUpstream', 'dev', '');
|
|
@@ -144,7 +155,7 @@ const devPack = (...args_1) => __awaiter(void 0, [...args_1], void 0, function*
|
|
|
144
155
|
}
|
|
145
156
|
else {
|
|
146
157
|
logger.notInProject();
|
|
147
|
-
process.exit(
|
|
158
|
+
process.exit(1);
|
|
148
159
|
}
|
|
149
160
|
return prepare(path.resolve(userRoot, '.dev/devConfig.js'), projectEntry, port, localUpstream, userRoot)
|
|
150
161
|
.then(() => {
|