esa-cli 0.0.1-beta.1
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/LICENSE +21 -0
- package/README.md +175 -0
- package/bin/enter.cjs +52 -0
- package/dist/README.md +175 -0
- package/dist/bin/enter.cjs +52 -0
- package/dist/cliconfig.toml +6 -0
- package/dist/commands/commit/index.js +147 -0
- package/dist/commands/commit/prodBuild.js +50 -0
- package/dist/commands/common/constant.js +54 -0
- package/dist/commands/config.js +51 -0
- package/dist/commands/deploy/helper.js +108 -0
- package/dist/commands/deploy/index.js +217 -0
- package/dist/commands/deployments/delete.js +92 -0
- package/dist/commands/deployments/index.js +27 -0
- package/dist/commands/deployments/list.js +89 -0
- package/dist/commands/dev/config/devBuild.js +26 -0
- package/dist/commands/dev/config/devEntry.js +71 -0
- package/dist/commands/dev/config/mock/cache.js +31 -0
- package/dist/commands/dev/config/mock/kv.js +87 -0
- package/dist/commands/dev/devPack.js +113 -0
- package/dist/commands/dev/doProcess.js +73 -0
- package/dist/commands/dev/index.js +240 -0
- package/dist/commands/dev/server.js +100 -0
- package/dist/commands/domain/add.js +72 -0
- package/dist/commands/domain/delete.js +74 -0
- package/dist/commands/domain/index.js +29 -0
- package/dist/commands/domain/list.js +51 -0
- package/dist/commands/init/index.js +149 -0
- package/dist/commands/lang.js +32 -0
- package/dist/commands/login/index.js +108 -0
- package/dist/commands/logout.js +44 -0
- package/dist/commands/route/add.js +115 -0
- package/dist/commands/route/delete.js +74 -0
- package/dist/commands/route/index.js +29 -0
- package/dist/commands/route/list.js +63 -0
- package/dist/commands/routine/delete.js +54 -0
- package/dist/commands/routine/index.js +27 -0
- package/dist/commands/routine/list.js +101 -0
- package/dist/commands/site/index.js +25 -0
- package/dist/commands/site/list.js +47 -0
- package/dist/commands/utils.js +139 -0
- package/dist/components/descriptionInput.js +38 -0
- package/dist/components/filterSelector.js +132 -0
- package/dist/components/mutiSelectTable.js +95 -0
- package/dist/components/selectInput.js +17 -0
- package/dist/components/selectItem.js +6 -0
- package/dist/components/yesNoPrompt.js +9 -0
- package/dist/docs/Commands_en.md +224 -0
- package/dist/docs/Commands_zh_CN.md +224 -0
- package/dist/docs/dev.png +0 -0
- package/dist/i18n/index.js +27 -0
- package/dist/i18n/locales.json +766 -0
- package/dist/index.js +80 -0
- package/dist/libs/apiService.js +914 -0
- package/dist/libs/git/index.js +52 -0
- package/dist/libs/interface.js +21 -0
- package/dist/libs/logger.js +149 -0
- package/dist/libs/request.js +98 -0
- package/dist/libs/templates/index.js +16 -0
- package/dist/package.json +93 -0
- package/dist/utils/checkDevPort.js +113 -0
- package/dist/utils/checkIsRoutineCreated.js +56 -0
- package/dist/utils/checkVersion.js +26 -0
- package/dist/utils/debounce.js +18 -0
- package/dist/utils/fileUtils/index.js +219 -0
- package/dist/utils/fileUtils/interface.js +1 -0
- package/dist/utils/install/install.ps1 +33 -0
- package/dist/utils/install/install.sh +53 -0
- package/dist/utils/installRuntime.js +80 -0
- package/dist/utils/openInBrowser.js +24 -0
- package/dist/utils/sleep.js +6 -0
- package/dist/zh_CN.md +177 -0
- package/package.json +93 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import t from '../../i18n/index.js';
|
|
2
|
+
export const SUMMARIES_LIST = [
|
|
3
|
+
{
|
|
4
|
+
title: t('summery_cd').d('Enter your routine project folder'),
|
|
5
|
+
command: 'π‘ cd [Your Routine Name]'
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
title: t('summery_dev').d('Start a local development server for your project'),
|
|
9
|
+
command: 'π‘ esa dev'
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
title: t('summery_commit').d('Save a new version of code'),
|
|
13
|
+
command: 'π‘ esa commit'
|
|
14
|
+
},
|
|
15
|
+
// Use Deploy or Release?
|
|
16
|
+
{
|
|
17
|
+
title: t('summery_deploy').d('Deploy your project to different environments'),
|
|
18
|
+
command: 'π‘ esa deploy'
|
|
19
|
+
}
|
|
20
|
+
];
|
|
21
|
+
export const getSummary = (routineName) => {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
title: t('summery_cd').d('Enter your routine project folder'),
|
|
25
|
+
command: `π‘ cd ${routineName}`
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: t('summery_dev').d('Start a local development server for your project'),
|
|
29
|
+
command: 'π‘ esa dev'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
title: t('summery_commit').d('Save a new version of code'),
|
|
33
|
+
command: 'π‘ esa commit'
|
|
34
|
+
},
|
|
35
|
+
// Use Deploy or Release?
|
|
36
|
+
{
|
|
37
|
+
title: t('summery_deploy').d('Deploy your project to different environments'),
|
|
38
|
+
command: 'π‘ esa deploy'
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
};
|
|
42
|
+
export const NODE_EXTERNALS = [
|
|
43
|
+
'node:assert',
|
|
44
|
+
'node:crypto',
|
|
45
|
+
'node:async_hooks',
|
|
46
|
+
'node:buffer',
|
|
47
|
+
'node:diagnostics_channel',
|
|
48
|
+
'node:events',
|
|
49
|
+
'node:path',
|
|
50
|
+
'node:process',
|
|
51
|
+
'node:stream',
|
|
52
|
+
'node:string_decoder',
|
|
53
|
+
'node:util'
|
|
54
|
+
];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import spawn from 'cross-spawn';
|
|
3
|
+
import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
|
|
4
|
+
import t from '../i18n/index.js';
|
|
5
|
+
import logger from '../libs/logger.js';
|
|
6
|
+
const editConfigFile = (configPath) => {
|
|
7
|
+
const editor = process.env.EDITOR || 'vi';
|
|
8
|
+
spawn(editor, [configPath], {
|
|
9
|
+
stdio: 'inherit'
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
const check = {
|
|
13
|
+
command: 'config',
|
|
14
|
+
describe: `π ${t('config_describe').d('Modify your local or global configuration using -l, -g')}`,
|
|
15
|
+
builder: (yargs) => {
|
|
16
|
+
return yargs
|
|
17
|
+
.option('local', {
|
|
18
|
+
alias: 'l',
|
|
19
|
+
describe: t('config_local_describe').d('Edit local config file'),
|
|
20
|
+
type: 'boolean',
|
|
21
|
+
default: false
|
|
22
|
+
})
|
|
23
|
+
.option('global', {
|
|
24
|
+
alias: 'g',
|
|
25
|
+
describe: t('config_global_describe').d('Edit global config file'),
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
default: false
|
|
28
|
+
})
|
|
29
|
+
.usage(`${t('common_usage').d('Usage')}: esa config [-l | -g]`)
|
|
30
|
+
.check((argv) => {
|
|
31
|
+
if (!argv.local && !argv.global) {
|
|
32
|
+
yargs.showHelp();
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
handler: (argv) => {
|
|
38
|
+
if (argv.local) {
|
|
39
|
+
if (fs.existsSync(projectConfigPath)) {
|
|
40
|
+
editConfigFile(projectConfigPath);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
logger.error(t('config_local_not_exist').d('Local config file does not exist'));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (argv.global) {
|
|
47
|
+
editConfigFile(cliConfigPath);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
export default check;
|
|
@@ -0,0 +1,108 @@
|
|
|
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 SelectItems from '../../components/selectInput.js';
|
|
11
|
+
import { yesNoPrompt } from '../../components/yesNoPrompt.js';
|
|
12
|
+
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 { displaySelectSpec } from './index.js';
|
|
17
|
+
import { createEdgeRoutine, releaseOfficialVersion, uploadEdgeRoutineCode } from '../commit/index.js';
|
|
18
|
+
import logger from '../../libs/logger.js';
|
|
19
|
+
import t from '../../i18n/index.js';
|
|
20
|
+
import prodBuild from '../commit/prodBuild.js';
|
|
21
|
+
export function yesNoPromptAndExecute(message, execute) {
|
|
22
|
+
return new Promise((resolve) => {
|
|
23
|
+
yesNoPrompt((item) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
if (item.value === 'yes') {
|
|
25
|
+
const result = yield execute();
|
|
26
|
+
resolve(result);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
resolve(false);
|
|
30
|
+
}
|
|
31
|
+
}), message);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export function promptSelectVersion(versionList) {
|
|
35
|
+
const items = versionList
|
|
36
|
+
.filter((version) => version.CodeVersion !== 'unstable')
|
|
37
|
+
.map((version, index) => ({
|
|
38
|
+
label: version.CodeVersion,
|
|
39
|
+
value: String(index)
|
|
40
|
+
}));
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
resolve(item.label);
|
|
44
|
+
});
|
|
45
|
+
SelectItems({ items, handleSelect: handleSelection });
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function displaySelectDeployType() {
|
|
49
|
+
logger.log(`π ${t('deploy_env_select_description').d('Please select which environment you want to deploy')}`);
|
|
50
|
+
const selectItems = [
|
|
51
|
+
{ label: t('deploy_env_staging').d('Staging'), value: PublishType.Staging },
|
|
52
|
+
{
|
|
53
|
+
label: t('deploy_env_production').d('Production'),
|
|
54
|
+
value: PublishType.Production
|
|
55
|
+
},
|
|
56
|
+
{ label: t('deploy_env_canary').d('Canary'), value: PublishType.Canary }
|
|
57
|
+
];
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
resolve(item.value);
|
|
61
|
+
});
|
|
62
|
+
SelectItems({ items: selectItems, handleSelect: handleSelection });
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export function createAndDeployVersion(projectConfig_1) {
|
|
66
|
+
return __awaiter(this, arguments, void 0, function* (projectConfig, createUnstable = false, customEntry) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
try {
|
|
69
|
+
const server = yield ApiService.getInstance();
|
|
70
|
+
const description = yield descriptionInput(createUnstable
|
|
71
|
+
? `ποΈ ${t('deploy_description_routine').d('Enter the description of the routine')}:`
|
|
72
|
+
: `ποΈ ${t('deploy_description_version').d('Enter the description of the code version')}:`, false);
|
|
73
|
+
yield prodBuild(false, customEntry);
|
|
74
|
+
const code = readEdgeRoutineFile();
|
|
75
|
+
const specList = yield server.listRoutineSpecs();
|
|
76
|
+
let specName;
|
|
77
|
+
if (createUnstable) {
|
|
78
|
+
specName = yield displaySelectSpec((_a = specList === null || specList === void 0 ? void 0 : specList.data.Specs) !== null && _a !== void 0 ? _a : []);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
const req = { Name: (_b = projectConfig.name) !== null && _b !== void 0 ? _b : '' };
|
|
82
|
+
const response = yield server.getRoutine(req);
|
|
83
|
+
specName = (_c = response === null || response === void 0 ? void 0 : response.data.Envs[0].SpecName) !== null && _c !== void 0 ? _c : '50ms';
|
|
84
|
+
}
|
|
85
|
+
const edgeRoutine = {
|
|
86
|
+
name: projectConfig.name,
|
|
87
|
+
code: code || '',
|
|
88
|
+
description: description,
|
|
89
|
+
specName: specName
|
|
90
|
+
};
|
|
91
|
+
if (createUnstable) {
|
|
92
|
+
return yield createEdgeRoutine(edgeRoutine);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const uploadResult = yield uploadEdgeRoutineCode(edgeRoutine);
|
|
96
|
+
if (!uploadResult) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
return yield releaseOfficialVersion(edgeRoutine);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
logger.error(`
|
|
104
|
+
${t('deploy_error').d('An error occurred during the creation or publishing process')}: ${error}`);
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
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 { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
|
|
12
|
+
import SelectItems from '../../components/selectInput.js';
|
|
13
|
+
import { Environment, PublishType } from '../../libs/interface.js';
|
|
14
|
+
import logger from '../../libs/logger.js';
|
|
15
|
+
import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
|
|
16
|
+
import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
|
|
17
|
+
import { Base64 } from 'js-base64';
|
|
18
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
19
|
+
import { createAndDeployVersion, displaySelectDeployType, promptSelectVersion, yesNoPromptAndExecute } from './helper.js';
|
|
20
|
+
import t from '../../i18n/index.js';
|
|
21
|
+
import prodBuild from '../commit/prodBuild.js';
|
|
22
|
+
import { exit } from 'process';
|
|
23
|
+
import path from 'path';
|
|
24
|
+
import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
|
|
25
|
+
const deploy = {
|
|
26
|
+
command: 'deploy [entry]',
|
|
27
|
+
builder: (yargs) => {
|
|
28
|
+
return yargs
|
|
29
|
+
.positional('entry', {
|
|
30
|
+
describe: t('dev_entry_describe').d('Entry file of the Routine'),
|
|
31
|
+
type: 'string',
|
|
32
|
+
demandOption: false
|
|
33
|
+
})
|
|
34
|
+
.option('quick', {
|
|
35
|
+
alias: 'q',
|
|
36
|
+
type: 'boolean'
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
describe: `π ${t('deploy_describe').d('Deploy your project')}`,
|
|
40
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
handleDeploy(argv);
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
export default deploy;
|
|
45
|
+
export function quickDeploy(entry, projectConfig) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const server = yield ApiService.getInstance();
|
|
48
|
+
const entryFile = path.resolve(entry !== null && entry !== void 0 ? entry : '', 'src/index.js');
|
|
49
|
+
yield prodBuild(false, entryFile, entry);
|
|
50
|
+
const code = readEdgeRoutineFile(entry) || '';
|
|
51
|
+
const res = yield server.quickDeployRoutine({
|
|
52
|
+
name: projectConfig.name,
|
|
53
|
+
code: code
|
|
54
|
+
});
|
|
55
|
+
if (res) {
|
|
56
|
+
logger.success(t('quick_deploy_success').d('Your code has been successfully deployed'));
|
|
57
|
+
logger.log(`π ${t('quick_deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
logger.error(t('quick_deploy_failed').d('Quick deploy failed'));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export function handleDeploy(argv) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a, _b, _c, _d, _e;
|
|
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 = ((_a = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _a === void 0 ? void 0 : _a.CodeVersions) || [];
|
|
82
|
+
const customEntry = argv.entry;
|
|
83
|
+
const stagingVersion = (_c = (_b = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _b === void 0 ? void 0 : _b.Envs[1]) === null || _c === void 0 ? void 0 : _c.CodeVersion;
|
|
84
|
+
const productionVersion = (_e = (_d = routineDetail === null || routineDetail === void 0 ? void 0 : routineDetail.data) === null || _d === void 0 ? void 0 : _d.Envs[0]) === null || _e === void 0 ? void 0 : _e.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
|
+
export function displaySelectSpec(specList) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
logger.log(`π ${t('deploy_spec_select').d('Please select the spec of the routine you want to create')}`);
|
|
105
|
+
const selectItems = specList.map((spec) => {
|
|
106
|
+
return { label: spec, value: spec };
|
|
107
|
+
});
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
const handleSelection = (item) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
resolve(item.value);
|
|
111
|
+
});
|
|
112
|
+
SelectItems({ items: selectItems, handleSelect: handleSelection });
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
function handleNoVersionsFound(projectConfig, customEntry) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
logger.log(`π ${t('deploy_first_time').d("This is first time to deploy. Let's create a version first!")}`);
|
|
119
|
+
const created = yield yesNoPromptAndExecute(`π ${t('deploy_create_formal_version_ques').d('Do you want to create an unstable version now?')}`, () => createAndDeployVersion(projectConfig, true));
|
|
120
|
+
if (created) {
|
|
121
|
+
yield handleOnlyUnstableVersionFound(projectConfig);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
function promptAndDeployVersion(projectConfig) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
128
|
+
yield displayVersionList(versionList);
|
|
129
|
+
logger.log(`π ${t('deploy_select_version').d("Select which version you'd like to deploy")}`);
|
|
130
|
+
const selectedVersion = yield promptSelectVersion(versionList);
|
|
131
|
+
const selectedType = yield displaySelectDeployType();
|
|
132
|
+
yield deploySelectedCodeVersion(projectConfig.name, selectedType, selectedVersion);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
const specialAreaTransfer = (canaryAreaSelectList) => {
|
|
136
|
+
return canaryAreaSelectList.map((item) => {
|
|
137
|
+
if (item.label === 'HongKong') {
|
|
138
|
+
return { label: 'HongKong(China)' };
|
|
139
|
+
}
|
|
140
|
+
if (item.label === 'Macau') {
|
|
141
|
+
return { label: 'Macau(China)' };
|
|
142
|
+
}
|
|
143
|
+
if (item.label === 'Taiwan') {
|
|
144
|
+
return { label: 'Taiwan(China)' };
|
|
145
|
+
}
|
|
146
|
+
return { label: item.label };
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
export function handleOnlyUnstableVersionFound(projectConfig, customEntry) {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
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));
|
|
152
|
+
if (created) {
|
|
153
|
+
yield promptAndDeployVersion(projectConfig);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
export function deploySelectedCodeVersion(name, selectedType, version) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
var _a;
|
|
160
|
+
const server = yield ApiService.getInstance();
|
|
161
|
+
const param = {
|
|
162
|
+
Name: name,
|
|
163
|
+
Env: selectedType === PublishType.Staging
|
|
164
|
+
? Environment.Staging
|
|
165
|
+
: Environment.Production
|
|
166
|
+
};
|
|
167
|
+
if (selectedType === PublishType.Canary) {
|
|
168
|
+
const res = yield server.listRoutineCanaryAreas();
|
|
169
|
+
const canaryList = (_a = res === null || res === void 0 ? void 0 : res.CanaryAreas) !== null && _a !== void 0 ? _a : [];
|
|
170
|
+
logger.log(`π ${t('deploy_select_canary').d('Please select the canary area(s) you want to deploy to')}`);
|
|
171
|
+
const canaryAreaSelectList = canaryList.map((area) => {
|
|
172
|
+
return { label: area };
|
|
173
|
+
});
|
|
174
|
+
const selectedCanaryList = yield displayMultiSelectTable(specialAreaTransfer(canaryAreaSelectList));
|
|
175
|
+
param.CanaryAreaList = selectedCanaryList;
|
|
176
|
+
param.CanaryCodeVersion = version;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
param.CodeVersion = version;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const res = yield server.publishRoutineCodeVersion(param);
|
|
183
|
+
if (res) {
|
|
184
|
+
logger.success(t('deploy_success').d('Your code has been successfully deployed'));
|
|
185
|
+
logger.log(`π ${t('deploy_success_guide').d('Run this command to add domains')}: ${chalk.green('esa domain add <DOMAIN>')}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
catch (e) {
|
|
189
|
+
console.error(e);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
export function displayVersionList(versionList_1) {
|
|
194
|
+
return __awaiter(this, arguments, void 0, function* (versionList, stagingVersion = 'unstable', productionVersion = 'unstable') {
|
|
195
|
+
logger.log(`${chalk.bgYellow('Active')} ${t('deploy_env_staging').d('Staging')}`);
|
|
196
|
+
logger.log(`${chalk.bgGreen('Active')} ${t('deploy_env_production').d('Production')}`);
|
|
197
|
+
const data = [];
|
|
198
|
+
for (let i = 0; i < versionList.length; i++) {
|
|
199
|
+
const version = versionList[i];
|
|
200
|
+
const createTime = new Date(version.CreateTime).toLocaleString();
|
|
201
|
+
const tags = [
|
|
202
|
+
version.CodeVersion === stagingVersion ? chalk.bgYellow('Active') : '',
|
|
203
|
+
version.CodeVersion === productionVersion ? chalk.bgGreen('Active') : ''
|
|
204
|
+
];
|
|
205
|
+
data.push([
|
|
206
|
+
`${version.CodeVersion} ${tags.join(' ')}`,
|
|
207
|
+
createTime,
|
|
208
|
+
Base64.decode(version.CodeDescription)
|
|
209
|
+
]);
|
|
210
|
+
}
|
|
211
|
+
logger.table([
|
|
212
|
+
t('deploy_table_header_version').d('Version'),
|
|
213
|
+
t('deploy_table_header_created').d('Created'),
|
|
214
|
+
t('deploy_table_header_description').d('Description')
|
|
215
|
+
], data);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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 { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
11
|
+
import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
|
|
12
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
13
|
+
import t from '../../i18n/index.js';
|
|
14
|
+
import logger from '../../libs/logger.js';
|
|
15
|
+
import { displayMultiSelectTable } from '../../components/mutiSelectTable.js';
|
|
16
|
+
import { Base64 } from 'js-base64';
|
|
17
|
+
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
18
|
+
const deploymentsDelete = {
|
|
19
|
+
command: 'delete [deploymentId..]',
|
|
20
|
+
describe: `π ${t('deployments_delete_describe').d('Delete one or more deployment versions')}`,
|
|
21
|
+
builder: (yargs) => {
|
|
22
|
+
return yargs
|
|
23
|
+
.positional('deploymentId', {
|
|
24
|
+
describe: t('deployments_delete_id_describe').d('The ID of the deployments to delete'),
|
|
25
|
+
type: 'string',
|
|
26
|
+
demandOption: true
|
|
27
|
+
})
|
|
28
|
+
.option('i', {
|
|
29
|
+
describe: t('delete_interactive_mode').d('Delete deployments by using interactive mode'),
|
|
30
|
+
type: 'boolean'
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
handleDeleteDeployments(argv);
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
export default deploymentsDelete;
|
|
38
|
+
export function handleDeleteDeployments(argv) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!checkDirectory()) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const projectConfig = getProjectConfig();
|
|
44
|
+
if (!projectConfig)
|
|
45
|
+
return logger.notInProject();
|
|
46
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
47
|
+
if (!isSuccess)
|
|
48
|
+
return;
|
|
49
|
+
yield validRoutine(projectConfig.name);
|
|
50
|
+
const server = yield ApiService.getInstance();
|
|
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
|
+
const isInteractive = argv.i;
|
|
67
|
+
if (isInteractive) {
|
|
68
|
+
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
69
|
+
logger.log(t('delete_deployments_table_title').d(' Version ID Description'));
|
|
70
|
+
const selectList = versionList.map((item) => {
|
|
71
|
+
return {
|
|
72
|
+
label: item.CodeVersion + ' ' + Base64.decode(item.CodeDescription)
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
versions = (yield displayMultiSelectTable(selectList, 1, 100)).map((item) => item.slice(0, item.indexOf(' ')));
|
|
76
|
+
}
|
|
77
|
+
for (let i = 0; i < versions.length; i++) {
|
|
78
|
+
const version = versions[i];
|
|
79
|
+
const req = {
|
|
80
|
+
Name: projectConfig.name,
|
|
81
|
+
CodeVersion: version
|
|
82
|
+
};
|
|
83
|
+
const res = yield server.deleteRoutineCodeVersion(req);
|
|
84
|
+
if ((res === null || res === void 0 ? void 0 : res.Status) === 'OK') {
|
|
85
|
+
logger.success(`${t('deployments_delete_success').d('Delete success')}: ${version}`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
logger.error(`π
${t('deployments_delete_failed').d('Delete failed')}: ${version}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import deploymentsList from './list.js';
|
|
2
|
+
import deploymentsDelete from './delete.js';
|
|
3
|
+
import t from '../../i18n/index.js';
|
|
4
|
+
let yargsIns;
|
|
5
|
+
const deploymentsCommand = {
|
|
6
|
+
command: 'deployments [script]',
|
|
7
|
+
describe: `π ${t('deployments_describe').d('Manage your deployments')}`,
|
|
8
|
+
builder: (yargs) => {
|
|
9
|
+
yargsIns = yargs;
|
|
10
|
+
return yargs
|
|
11
|
+
.command(deploymentsList)
|
|
12
|
+
.command(deploymentsDelete)
|
|
13
|
+
.option('help', {
|
|
14
|
+
alias: 'h',
|
|
15
|
+
describe: t('common_help').d('Help'),
|
|
16
|
+
type: 'boolean',
|
|
17
|
+
default: false
|
|
18
|
+
})
|
|
19
|
+
.usage(`${t('common_usage').d('Usage')}: esa deployments [list | delete]`);
|
|
20
|
+
},
|
|
21
|
+
handler: (argv) => {
|
|
22
|
+
if (yargsIns && (argv.help || argv._.length < 2)) {
|
|
23
|
+
yargsIns.showHelp('log');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export default deploymentsCommand;
|
|
@@ -0,0 +1,89 @@
|
|
|
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 { displayVersionList } from '../deploy/index.js';
|
|
11
|
+
import { checkDirectory, checkIsLoginSuccess, getRoutineVersionList } from '../utils.js';
|
|
12
|
+
import { getProjectConfig } from '../../utils/fileUtils/index.js';
|
|
13
|
+
import chalk from 'chalk';
|
|
14
|
+
import { ApiService } from '../../libs/apiService.js';
|
|
15
|
+
import t from '../../i18n/index.js';
|
|
16
|
+
import logger from '../../libs/logger.js';
|
|
17
|
+
import { validRoutine } from '../../utils/checkIsRoutineCreated.js';
|
|
18
|
+
const deploymentsList = {
|
|
19
|
+
command: 'list',
|
|
20
|
+
describe: `π ${t('deployments_list_describe').d('List all deployments')}`,
|
|
21
|
+
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
handleListDeployments(argv);
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
export default deploymentsList;
|
|
26
|
+
export function handleListDeployments(argv) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
var _a, _b, _c, _d;
|
|
29
|
+
if (!checkDirectory()) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const projectConfig = getProjectConfig();
|
|
33
|
+
if (!projectConfig)
|
|
34
|
+
return logger.notInProject();
|
|
35
|
+
const isSuccess = yield checkIsLoginSuccess();
|
|
36
|
+
if (!isSuccess)
|
|
37
|
+
return;
|
|
38
|
+
yield validRoutine(projectConfig.name);
|
|
39
|
+
const server = yield ApiService.getInstance();
|
|
40
|
+
const versionList = yield getRoutineVersionList(projectConfig.name);
|
|
41
|
+
const req = { Name: projectConfig.name };
|
|
42
|
+
const routineDetail = yield server.getRoutine(req);
|
|
43
|
+
if (!routineDetail)
|
|
44
|
+
return;
|
|
45
|
+
//ζ΅θ―η―ε’ηζ¬
|
|
46
|
+
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;
|
|
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);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function displayListPrompt(routineDetail) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
var _a, _b, _c, _d, _e;
|
|
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];
|
|
59
|
+
const server = yield ApiService.getInstance();
|
|
60
|
+
const res = yield server.getRoutineStagingEnvIp();
|
|
61
|
+
const stagingIpList = (_c = (_b = res === null || res === void 0 ? void 0 : res.data) === null || _b === void 0 ? void 0 : _b.IPV4) !== null && _c !== void 0 ? _c : [];
|
|
62
|
+
const coloredStagingIpList = stagingIpList.map((ip) => {
|
|
63
|
+
return chalk.green(ip);
|
|
64
|
+
});
|
|
65
|
+
const showEnvTable = (version, spec, region) => {
|
|
66
|
+
const data = [
|
|
67
|
+
{ Version: version },
|
|
68
|
+
{ Specification: spec }
|
|
69
|
+
];
|
|
70
|
+
if (region) {
|
|
71
|
+
data.push({ Region: region });
|
|
72
|
+
}
|
|
73
|
+
logger.table([], data);
|
|
74
|
+
};
|
|
75
|
+
logger.log(chalk.bold(t('deploy_env_staging').d('Staging')));
|
|
76
|
+
if (stagingIpList.length > 0) {
|
|
77
|
+
logger.log(`Staging IP: ${coloredStagingIpList.join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
showEnvTable(stagingEnv.CodeVersion, stagingEnv.SpecName);
|
|
80
|
+
logger.block();
|
|
81
|
+
logger.log(`${chalk.bold(`${t('deploy_env_production').d('Production')} ${!isCanary ? chalk.green('β') : ''}`)}`);
|
|
82
|
+
showEnvTable(canaryEnv.CodeVersion, canaryEnv.SpecName);
|
|
83
|
+
logger.block();
|
|
84
|
+
logger.log(`${chalk.bold(`${t('deploy_env_canary').d('Canary')} ${isCanary ? chalk.green('β') : ''}`)}`);
|
|
85
|
+
showEnvTable((_d = canaryEnv.CanaryCodeVersion) !== null && _d !== void 0 ? _d : '', canaryEnv.SpecName, (_e = canaryEnv.CanaryAreaList) === null || _e === void 0 ? void 0 : _e.join(', '));
|
|
86
|
+
logger.info(`${t('show_default_url').d(`You can visit:`)} ${chalk.yellowBright(routineDetail.data.DefaultRelatedRecord)}`);
|
|
87
|
+
logger.block();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import esbuild from 'esbuild';
|
|
2
|
+
import { lessLoader } from 'esbuild-plugin-less';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getRoot } from '../../../utils/fileUtils/index.js';
|
|
5
|
+
import { NODE_EXTERNALS } from '../../common/constant.js';
|
|
6
|
+
export default function (options) {
|
|
7
|
+
const userRoot = getRoot();
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
const id = global.id;
|
|
10
|
+
const devEntry = path.resolve(userRoot, `.dev/devEntry-${id}.js`);
|
|
11
|
+
return esbuild.build({
|
|
12
|
+
entryPoints: [devEntry],
|
|
13
|
+
outfile: path.resolve(userRoot, `.dev/index-${id}.js`),
|
|
14
|
+
bundle: true,
|
|
15
|
+
minify: !!options.minify,
|
|
16
|
+
splitting: false,
|
|
17
|
+
format: 'esm',
|
|
18
|
+
platform: 'browser',
|
|
19
|
+
external: NODE_EXTERNALS,
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
plugins: [lessLoader()],
|
|
22
|
+
loader: {
|
|
23
|
+
'.client.js': 'text'
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|