esa-cli 0.0.1-beta.8 → 0.0.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/bin/enter.cjs +0 -1
- package/dist/README.md +4 -6
- package/dist/bin/enter.cjs +0 -1
- package/dist/commands/commit/index.js +2 -2
- package/dist/commands/commit/prodBuild.js +1 -1
- package/dist/commands/deploy/index.js +4 -2
- package/dist/commands/deployments/list.js +2 -1
- package/dist/commands/dev/build.js +57 -0
- package/dist/commands/dev/doProcess.js +10 -2
- package/dist/commands/dev/ew2/devEntry.js +9 -0
- package/dist/commands/dev/ew2/devPack.js +185 -0
- package/dist/commands/dev/ew2/mock/cache.js +32 -0
- package/dist/commands/dev/ew2/mock/kv.js +45 -0
- package/dist/commands/dev/ew2/server.js +234 -0
- package/dist/commands/dev/index.js +113 -50
- package/dist/commands/dev/{config → mockWorker}/devEntry.js +3 -2
- package/dist/commands/dev/{devPack.js → mockWorker/devPack.js} +10 -7
- package/dist/commands/dev/{server.js → mockWorker/server.js} +43 -36
- package/dist/commands/init/index.js +119 -47
- package/dist/commands/login/index.js +2 -2
- package/dist/commands/logout.js +0 -4
- package/dist/commands/route/list.js +2 -1
- package/dist/commands/routine/list.js +6 -4
- package/dist/commands/utils.js +2 -1
- package/dist/components/mutiLevelSelect.js +69 -0
- package/dist/i18n/index.js +4 -1
- package/dist/i18n/locales.json +897 -781
- package/dist/index.js +10 -3
- package/dist/libs/api.js +155 -0
- package/dist/libs/logger.js +42 -31
- package/dist/libs/service.js +178 -0
- package/dist/package.json +14 -7
- package/dist/utils/checkDevPort.js +19 -14
- package/dist/utils/checkOS.js +32 -0
- package/dist/utils/checkVersion.js +1 -1
- package/dist/utils/fileMd5.js +18 -0
- package/dist/utils/fileUtils/base.js +31 -0
- package/dist/utils/fileUtils/index.js +5 -33
- package/dist/utils/install/installEw2.sh +33 -0
- package/dist/utils/{installRuntime.js → installDeno.js} +16 -16
- package/dist/utils/installEw2.js +127 -0
- package/dist/utils/readJson.js +10 -0
- package/dist/utils/stepsRunner.js +33 -0
- package/dist/zh_CN.md +4 -5
- package/package.json +14 -7
- package/dist/commands/dev/config/devBuild.js +0 -26
- package/dist/libs/request.js +0 -98
- /package/dist/commands/dev/{config → mockWorker}/mock/cache.js +0 -0
- /package/dist/commands/dev/{config → mockWorker}/mock/kv.js +0 -0
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import yargs from 'yargs';
|
|
11
11
|
import { hideBin } from 'yargs/helpers';
|
|
12
|
+
import chalk from 'chalk';
|
|
12
13
|
import login from './commands/login/index.js';
|
|
13
14
|
import config from './commands/config.js';
|
|
14
15
|
import dev from './commands/dev/index.js';
|
|
@@ -25,6 +26,7 @@ import { getCliConfig } from './utils/fileUtils/index.js';
|
|
|
25
26
|
import { handleCheckVersion } from './utils/checkVersion.js';
|
|
26
27
|
import t from './i18n/index.js';
|
|
27
28
|
import site from './commands/site/index.js';
|
|
29
|
+
import { quickDeployRoutine } from './libs/service.js';
|
|
28
30
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
31
|
const argv = hideBin(process.argv);
|
|
30
32
|
const cliConfig = getCliConfig();
|
|
@@ -38,9 +40,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
38
40
|
.version(false)
|
|
39
41
|
.wrap(null)
|
|
40
42
|
.help(false)
|
|
41
|
-
|
|
42
|
-
// `${t('main_epilogue').d('For more information, visit DCDN')}: ${chalk.underline.blue('https://dcdnnext.console.aliyun.com/')}`
|
|
43
|
-
// )
|
|
43
|
+
.epilogue(`${t('main_epilogue').d('For more information, visit ESA')}: ${chalk.underline.blue('https://www.aliyun.com/product/esa')}`)
|
|
44
44
|
.options('version', {
|
|
45
45
|
describe: t('main_version_describe').d('Show version'),
|
|
46
46
|
alias: 'v'
|
|
@@ -74,6 +74,13 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
74
74
|
esa.command(logout);
|
|
75
75
|
esa.command(config);
|
|
76
76
|
esa.command(lang);
|
|
77
|
+
esa.command('t', false, () => { }, (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
+
const res = yield quickDeployRoutine({
|
|
79
|
+
name: 'test',
|
|
80
|
+
code: 'test'
|
|
81
|
+
});
|
|
82
|
+
// console.log(res);
|
|
83
|
+
}));
|
|
77
84
|
esa.group(['help', 'version'], 'Options:');
|
|
78
85
|
esa.parse();
|
|
79
86
|
});
|
package/dist/libs/api.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
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 ESA, * as $ESA from '@alicloud/esa20240910';
|
|
11
|
+
import * as $OpenApi from '@alicloud/openapi-client';
|
|
12
|
+
import * as $Util from '@alicloud/tea-util';
|
|
13
|
+
import { getApiConfig } from '../utils/fileUtils/index.js';
|
|
14
|
+
import logger from './logger.js';
|
|
15
|
+
class Client {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.callApi = (action, request) => __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
logger.info(`Called api ${action.name}, Request: ${request ? JSON.stringify(request) : 'no request'}`);
|
|
20
|
+
const runtime = new $Util.RuntimeOptions({
|
|
21
|
+
connectTimeout: 10000,
|
|
22
|
+
readTimeout: 10000,
|
|
23
|
+
autoretry: true,
|
|
24
|
+
maxAttempts: 3
|
|
25
|
+
});
|
|
26
|
+
const response = request
|
|
27
|
+
? yield action(request, runtime)
|
|
28
|
+
: yield action(runtime);
|
|
29
|
+
return response;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
const err = error;
|
|
33
|
+
logger.error(`Code: ${err.code}, Message: ${err.message}}`);
|
|
34
|
+
logger.debug(`Data: ${JSON.stringify(err.data)}`);
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
this.callOpenApi = (apiName, requestParams) => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
logger.info(`Called api ${apiName} with openApi, Request: ${requestParams ? JSON.stringify(requestParams) : 'no request'}`);
|
|
40
|
+
try {
|
|
41
|
+
let params = {
|
|
42
|
+
action: apiName,
|
|
43
|
+
version: '2024-09-10',
|
|
44
|
+
protocol: 'https',
|
|
45
|
+
method: 'GET',
|
|
46
|
+
authType: 'AK',
|
|
47
|
+
bodyType: 'json',
|
|
48
|
+
reqBodyType: 'json',
|
|
49
|
+
style: 'RPC',
|
|
50
|
+
pathname: '/',
|
|
51
|
+
toMap: function () {
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const request = new $OpenApi.OpenApiRequest(requestParams);
|
|
56
|
+
const runtime = new $Util.RuntimeOptions({
|
|
57
|
+
connectTimeout: 10000,
|
|
58
|
+
readTimeout: 10000,
|
|
59
|
+
autoretry: true,
|
|
60
|
+
maxAttempts: 3
|
|
61
|
+
});
|
|
62
|
+
const response = yield this.client.callApi(params, request, runtime);
|
|
63
|
+
return response;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
const err = error;
|
|
67
|
+
logger.error(`Code: ${err.code}, Message: ${err.message}}`);
|
|
68
|
+
logger.debug(`Data: ${JSON.stringify(err.data)}`);
|
|
69
|
+
throw err;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
const config = getApiConfig();
|
|
73
|
+
this.client = Client.createClient(config);
|
|
74
|
+
}
|
|
75
|
+
static createClient(config) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const apiConfig = new $OpenApi.Config({
|
|
78
|
+
accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
79
|
+
accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
80
|
+
endpoint: config.endpoint
|
|
81
|
+
});
|
|
82
|
+
return new ESA.default(apiConfig);
|
|
83
|
+
}
|
|
84
|
+
updateConfig(config) {
|
|
85
|
+
this.client = Client.createClient(config);
|
|
86
|
+
}
|
|
87
|
+
getErService() {
|
|
88
|
+
const request = new $ESA.GetErServiceRequest({});
|
|
89
|
+
return this.callApi(this.client.getErServiceWithOptions.bind(this.client), request);
|
|
90
|
+
}
|
|
91
|
+
getRoutineStagingCodeUploadInfo(params) {
|
|
92
|
+
const request = new $ESA.GetRoutineStagingCodeUploadInfoRequest(params);
|
|
93
|
+
return this.callApi(this.client.getRoutineStagingCodeUploadInfoWithOptions.bind(this.client), request);
|
|
94
|
+
}
|
|
95
|
+
commitRoutineStagingCode(params) {
|
|
96
|
+
const request = new $ESA.CommitRoutineStagingCodeRequest(params);
|
|
97
|
+
return this.callApi(this.client.commitRoutineStagingCodeWithOptions.bind(this.client), request);
|
|
98
|
+
}
|
|
99
|
+
publishRoutineCodeVersion(params) {
|
|
100
|
+
const request = new $ESA.PublishRoutineCodeVersionRequest(params);
|
|
101
|
+
return this.callApi(this.client.publishRoutineCodeVersionWithOptions.bind(this.client), request);
|
|
102
|
+
}
|
|
103
|
+
getMatchSite(params) {
|
|
104
|
+
return this.callOpenApi('getMatchSite', params);
|
|
105
|
+
}
|
|
106
|
+
listRoutineCanaryAreas() {
|
|
107
|
+
return this.callApi(this.client.listRoutineCanaryAreasWithOptions.bind(this.client));
|
|
108
|
+
}
|
|
109
|
+
getRoutineUserInfo() {
|
|
110
|
+
return this.callApi(this.client.getRoutineUserInfoWithOptions.bind(this.client));
|
|
111
|
+
}
|
|
112
|
+
deleteRoutine(params) {
|
|
113
|
+
const request = new $ESA.DeleteRoutineRequest(params);
|
|
114
|
+
return this.callApi(this.client.deleteRoutineWithOptions.bind(this.client), request);
|
|
115
|
+
}
|
|
116
|
+
deleteRoutineCodeVersion(params) {
|
|
117
|
+
const request = new $ESA.DeleteRoutineCodeVersionRequest(params);
|
|
118
|
+
return this.callApi(this.client.deleteRoutineCodeVersionWithOptions.bind(this.client), request);
|
|
119
|
+
}
|
|
120
|
+
createRoutineRelatedRoute(params) {
|
|
121
|
+
const request = new $ESA.CreateRoutineRelatedRouteRequest(params);
|
|
122
|
+
return this.callApi(this.client.createRoutineRelatedRouteWithOptions.bind(this.client), request);
|
|
123
|
+
}
|
|
124
|
+
deleteRoutineRelatedRoute(params) {
|
|
125
|
+
const request = new $ESA.DeleteRoutineRelatedRouteRequest(params);
|
|
126
|
+
return this.callApi(this.client.deleteRoutineRelatedRouteWithOptions.bind(this.client), request);
|
|
127
|
+
}
|
|
128
|
+
listSites(params) {
|
|
129
|
+
const request = new $ESA.ListSitesRequest(params);
|
|
130
|
+
return this.callApi(this.client.listSitesWithOptions.bind(this.client), request);
|
|
131
|
+
}
|
|
132
|
+
getRoutineStagingEnvIp() {
|
|
133
|
+
return this.callApi(this.client.getRoutineStagingEnvIpWithOptions.bind(this.client));
|
|
134
|
+
}
|
|
135
|
+
getRoutine(params) {
|
|
136
|
+
const request = new $ESA.GetRoutineRequest(params);
|
|
137
|
+
return this.callApi(this.client.getRoutineWithOptions.bind(this.client), request);
|
|
138
|
+
}
|
|
139
|
+
createRoutine(params) {
|
|
140
|
+
const request = new $ESA.CreateRoutineRequest(params);
|
|
141
|
+
return this.callApi(this.client.createRoutineWithOptions.bind(this.client), request);
|
|
142
|
+
}
|
|
143
|
+
listRoutineOptionalSpecs() {
|
|
144
|
+
return this.callApi(this.client.listRoutineOptionalSpecsWithOptions.bind(this.client));
|
|
145
|
+
}
|
|
146
|
+
createRoutineRelatedRecord(params) {
|
|
147
|
+
const request = new $ESA.CreateRoutineRelatedRecordRequest(params);
|
|
148
|
+
return this.callApi(this.client.createRoutineRelatedRecordWithOptions.bind(this.client), request);
|
|
149
|
+
}
|
|
150
|
+
deleteRoutineRelatedRecord(params) {
|
|
151
|
+
const request = new $ESA.DeleteRoutineRelatedRecordRequest(params);
|
|
152
|
+
return this.callApi(this.client.deleteRoutineRelatedRecordWithOptions.bind(this.client), request);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
export default new Client();
|
package/dist/libs/logger.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import { format, createLogger
|
|
2
|
+
import { format, createLogger } from 'winston';
|
|
3
|
+
import DailyRotateFile from 'winston-daily-rotate-file';
|
|
3
4
|
import Table from 'cli-table3';
|
|
4
5
|
import path from 'path';
|
|
5
6
|
import os from 'os';
|
|
6
7
|
import ora from 'ora';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
8
|
import t from '../i18n/index.js';
|
|
9
|
-
|
|
9
|
+
import { getProjectConfig } from '../utils/fileUtils/index.js';
|
|
10
|
+
const transport = new DailyRotateFile({
|
|
11
|
+
filename: path.join(os.homedir(), '.esa-logs/esa-debug-%DATE%.log'),
|
|
12
|
+
level: 'info',
|
|
13
|
+
datePattern: 'YYYY-MM-DD-HH:mm:ss',
|
|
14
|
+
zippedArchive: true,
|
|
15
|
+
maxSize: '10m',
|
|
16
|
+
maxFiles: '7d'
|
|
17
|
+
});
|
|
10
18
|
class Logger {
|
|
11
19
|
constructor() {
|
|
12
20
|
const { combine, timestamp, label, printf } = format;
|
|
13
21
|
const customFormat = printf(({ level, message, label: printLabel, timestamp: printTimestamp }) => {
|
|
22
|
+
var _a;
|
|
14
23
|
let colorizedLevel;
|
|
24
|
+
const projName = ((_a = getProjectConfig()) === null || _a === void 0 ? void 0 : _a.name) || 'Outside';
|
|
15
25
|
switch (level) {
|
|
26
|
+
case 'warn':
|
|
27
|
+
colorizedLevel = chalk.yellow(level);
|
|
28
|
+
break;
|
|
29
|
+
case 'info':
|
|
30
|
+
colorizedLevel = chalk.green(level);
|
|
31
|
+
break;
|
|
16
32
|
case 'error':
|
|
17
|
-
colorizedLevel = chalk.
|
|
18
|
-
return `❌ ${colorizedLevel} ${chalk.red(message)}`;
|
|
33
|
+
colorizedLevel = chalk.red(level);
|
|
19
34
|
case 'verbose':
|
|
20
35
|
colorizedLevel = chalk.magenta(level);
|
|
21
36
|
break;
|
|
@@ -28,18 +43,12 @@ class Logger {
|
|
|
28
43
|
default:
|
|
29
44
|
colorizedLevel = level;
|
|
30
45
|
}
|
|
31
|
-
return `${printTimestamp} [${chalk.green(printLabel)}] ${colorizedLevel}: ${message}`;
|
|
46
|
+
return `${printTimestamp} [${chalk.green(printLabel)}] ${colorizedLevel} in ${chalk.italic(projName)}: ${message}`;
|
|
32
47
|
});
|
|
33
48
|
this.logger = createLogger({
|
|
34
49
|
level: 'info',
|
|
35
|
-
format: combine(label({ label: '
|
|
36
|
-
transports: [
|
|
37
|
-
new transports.Console(),
|
|
38
|
-
new transports.File({
|
|
39
|
-
filename: path.join(os.homedir(), '.asea-logs/esa-debug.log'),
|
|
40
|
-
level: 'error'
|
|
41
|
-
})
|
|
42
|
-
]
|
|
50
|
+
format: combine(label({ label: 'ESA' }), timestamp(), customFormat),
|
|
51
|
+
transports: [transport]
|
|
43
52
|
});
|
|
44
53
|
this.spinner = ora('Loading...');
|
|
45
54
|
}
|
|
@@ -63,13 +72,16 @@ class Logger {
|
|
|
63
72
|
console.log(`\t${message}`);
|
|
64
73
|
}
|
|
65
74
|
success(message) {
|
|
66
|
-
console.log(
|
|
75
|
+
console.log(`\n🎉 ${chalk.bgGreen(' SUCCESS ')} ${chalk.green(message)}`);
|
|
67
76
|
}
|
|
68
77
|
debug(message) {
|
|
69
78
|
this.logger.debug(message);
|
|
79
|
+
if (this.logger.level === 'debug') {
|
|
80
|
+
console.log(`${chalk.grey('[DEBUG]')} ${message}`);
|
|
81
|
+
}
|
|
70
82
|
}
|
|
71
83
|
info(message) {
|
|
72
|
-
|
|
84
|
+
this.logger.info(message);
|
|
73
85
|
}
|
|
74
86
|
ask(message) {
|
|
75
87
|
console.log(`❓ ${message}`);
|
|
@@ -78,16 +90,18 @@ class Logger {
|
|
|
78
90
|
console.log(`👉🏻 ${chalk.green(message)}`);
|
|
79
91
|
}
|
|
80
92
|
block() {
|
|
81
|
-
console.log('
|
|
93
|
+
console.log('\n');
|
|
82
94
|
}
|
|
83
95
|
warn(message) {
|
|
84
|
-
|
|
96
|
+
this.logger.warn(message);
|
|
97
|
+
console.log(`\n${chalk.bgYellow(' WARNING ')} ${chalk.yellow(message)}`);
|
|
85
98
|
}
|
|
86
99
|
error(message) {
|
|
87
100
|
this.logger.error(message);
|
|
101
|
+
console.log(`\n❌ ${chalk.bgRed(' ERROR ')} ${chalk.red(message)}`);
|
|
88
102
|
}
|
|
89
103
|
subError(message) {
|
|
90
|
-
console.log(
|
|
104
|
+
console.log(`\n${chalk.red(message)}`);
|
|
91
105
|
}
|
|
92
106
|
http(message) {
|
|
93
107
|
this.logger.http(message);
|
|
@@ -107,7 +121,7 @@ class Logger {
|
|
|
107
121
|
}
|
|
108
122
|
notInProject() {
|
|
109
123
|
const initCommand = chalk.green('esa init');
|
|
110
|
-
this.
|
|
124
|
+
this.error(t('common_not_edge_project', { initCommand }).d(`You are not in an esa project, Please run ${initCommand} to initialize a project, or enter an esa project.`));
|
|
111
125
|
}
|
|
112
126
|
pathEacces(localPath) {
|
|
113
127
|
this.block();
|
|
@@ -119,9 +133,10 @@ class Logger {
|
|
|
119
133
|
this.block();
|
|
120
134
|
this.log(chalk.green(`$ sudo chmod -R 777 ${localPath}`));
|
|
121
135
|
}
|
|
122
|
-
table(head, data) {
|
|
136
|
+
table(head, data, width = []) {
|
|
123
137
|
const table = new Table({
|
|
124
|
-
head
|
|
138
|
+
head,
|
|
139
|
+
colWidths: width
|
|
125
140
|
});
|
|
126
141
|
table.push(...data);
|
|
127
142
|
this.log(table.toString());
|
|
@@ -130,19 +145,15 @@ class Logger {
|
|
|
130
145
|
tree(messages) {
|
|
131
146
|
if (messages.length === 0)
|
|
132
147
|
return;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
console.log(`╭─ ${messages[0]}`);
|
|
148
|
+
const lines = [];
|
|
149
|
+
lines.push(`╭─ ${messages[0]}`);
|
|
138
150
|
for (let i = 1; i < messages.length - 1; i++) {
|
|
139
|
-
|
|
140
|
-
console.log(`├─ ${messages[i]}`);
|
|
151
|
+
lines.push(`│ ${messages[i]}`);
|
|
141
152
|
}
|
|
142
153
|
if (messages.length > 1) {
|
|
143
|
-
|
|
144
|
-
console.log(`╰─ ${messages[messages.length - 1]}`);
|
|
154
|
+
lines.push(`╰─ ${messages[messages.length - 1]}`);
|
|
145
155
|
}
|
|
156
|
+
console.log(lines.join('\n'));
|
|
146
157
|
}
|
|
147
158
|
}
|
|
148
159
|
const logger = Logger.getInstance();
|
|
@@ -0,0 +1,178 @@
|
|
|
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 ora from 'ora';
|
|
11
|
+
import chain from 'lodash';
|
|
12
|
+
import FormData from 'form-data';
|
|
13
|
+
import fetch from 'node-fetch';
|
|
14
|
+
import t from '../i18n/index.js';
|
|
15
|
+
import api from './api.js';
|
|
16
|
+
import { Environment } from './interface.js';
|
|
17
|
+
import logger from './logger.js';
|
|
18
|
+
export const checkLogin = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
const result = new ServiceOutput();
|
|
20
|
+
try {
|
|
21
|
+
const response = yield api.getErService();
|
|
22
|
+
if (response.statusCode === 200) {
|
|
23
|
+
result.success = true;
|
|
24
|
+
result.message = t('login_success').d('Login success!');
|
|
25
|
+
}
|
|
26
|
+
else if (response.statusCode === 403) {
|
|
27
|
+
result.message = t('login_permission_denied').d('Permission denied: Access key or secret is incorrect, or does not have the necessary permissions.');
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
result.message = `${t('common_error_occurred').d('An error occurred')}: ${response.statusCode}`;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
result.message = t('login_failed').d('An error occurred while trying to log in.');
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
});
|
|
38
|
+
const commonUploadCodeError = t('upload_code_failed').d('An error occurred while trying to upload the code.');
|
|
39
|
+
export const getRoutineStagingCodeUploadInfo = (edgeRoutine) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const result = new ServiceOutput();
|
|
41
|
+
let ossConfig;
|
|
42
|
+
try {
|
|
43
|
+
const uploadResult = yield api.getRoutineStagingCodeUploadInfo({
|
|
44
|
+
name: edgeRoutine.name
|
|
45
|
+
});
|
|
46
|
+
ossConfig = chain(uploadResult).get('body.OssPostConfig');
|
|
47
|
+
if (!ossConfig) {
|
|
48
|
+
result.message = t('oss_config_not_found').d('Failed to retrieve OSS configuration information.');
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
result.message = commonUploadCodeError;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const { OSSAccessKeyId, Signature, callback, Url, key, policy } = ossConfig;
|
|
58
|
+
const formData = new FormData();
|
|
59
|
+
formData.append('OSSAccessKeyId', OSSAccessKeyId);
|
|
60
|
+
formData.append('Signature', Signature);
|
|
61
|
+
formData.append('callback', callback);
|
|
62
|
+
formData.append('x:codeDescription', ossConfig['x:codeDescription']);
|
|
63
|
+
formData.append('policy', policy);
|
|
64
|
+
formData.append('key', key);
|
|
65
|
+
formData.append('file', edgeRoutine.code);
|
|
66
|
+
const ossRes = yield fetch(Url, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
body: formData,
|
|
69
|
+
headers: formData.getHeaders()
|
|
70
|
+
});
|
|
71
|
+
if (ossRes && ossRes.status === 200) {
|
|
72
|
+
result.success = true;
|
|
73
|
+
result.message = t('upload_oss_success').d('Upload code success!');
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
logger.error(`${t('oss_upload_failed').d('Failed to upload to OSS')}: ${ossRes.status}, ${ossRes.statusText}}`);
|
|
77
|
+
result.message = commonUploadCodeError;
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const err = error;
|
|
83
|
+
logger.error(err.message);
|
|
84
|
+
result.message = commonUploadCodeError;
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
export const commitRoutineStagingCode = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
const result = new ServiceOutput();
|
|
90
|
+
try {
|
|
91
|
+
const res = yield api.commitRoutineStagingCode(params);
|
|
92
|
+
if (res.statusCode === 200 && res.body) {
|
|
93
|
+
result.success = true;
|
|
94
|
+
result.message = t('commit_success').d('Generate code version success!');
|
|
95
|
+
result.data = {
|
|
96
|
+
code: res.statusCode,
|
|
97
|
+
data: {
|
|
98
|
+
RequestId: res.body.RequestId,
|
|
99
|
+
CodeVersion: res.body.CodeVersion
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
result.message = commonUploadCodeError;
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const publishRoutineCodeVersion = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
const result = new ServiceOutput();
|
|
112
|
+
try {
|
|
113
|
+
const res = yield api.publishRoutineCodeVersion(params);
|
|
114
|
+
if (res.statusCode === 200 && res.body) {
|
|
115
|
+
result.success = true;
|
|
116
|
+
result.message = t('publish_success').d('Publish success!');
|
|
117
|
+
result.data = {
|
|
118
|
+
code: res.statusCode,
|
|
119
|
+
data: {
|
|
120
|
+
CodeVersion: res.body.CodeVersion,
|
|
121
|
+
RequestId: res.body.RequestId
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
result.message = commonUploadCodeError;
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
export const quickDeployRoutine = (edgeRoutineProps) => __awaiter(void 0, void 0, void 0, function* () {
|
|
133
|
+
const result = new ServiceOutput();
|
|
134
|
+
result.success = true;
|
|
135
|
+
const steps = [
|
|
136
|
+
{
|
|
137
|
+
action: () => getRoutineStagingCodeUploadInfo(edgeRoutineProps),
|
|
138
|
+
message: t('upload_code').d('Uploading code...')
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
action: () => commitRoutineStagingCode({
|
|
142
|
+
name: edgeRoutineProps.name,
|
|
143
|
+
codeDescription: edgeRoutineProps.description
|
|
144
|
+
}),
|
|
145
|
+
message: t('commit_code').d('Generating code version...')
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
action: () => publishRoutineCodeVersion({
|
|
149
|
+
Name: edgeRoutineProps.name,
|
|
150
|
+
CodeVersion: '',
|
|
151
|
+
Env: Environment.Staging
|
|
152
|
+
}),
|
|
153
|
+
message: t('publish_code').d('Publishing code to production environment...')
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
const spinner = ora(t('start_quick_deploy').d('Starting quick deploy...')).start();
|
|
157
|
+
for (const step of steps) {
|
|
158
|
+
spinner.text = step.message;
|
|
159
|
+
const stepRes = yield step.action();
|
|
160
|
+
if (stepRes.success) {
|
|
161
|
+
spinner.succeed(stepRes.message);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
result.success = false;
|
|
165
|
+
spinner.fail('Error: ' + stepRes.message);
|
|
166
|
+
result.message = stepRes.message;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
});
|
|
172
|
+
export class ServiceOutput {
|
|
173
|
+
constructor() {
|
|
174
|
+
this.success = false;
|
|
175
|
+
this.message = '';
|
|
176
|
+
this.data = {};
|
|
177
|
+
}
|
|
178
|
+
}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esa-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-beta.0",
|
|
4
4
|
"description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
|
|
5
5
|
"main": "bin/enter.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -16,14 +16,14 @@
|
|
|
16
16
|
"eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
17
17
|
"lint-staged": "lint-staged",
|
|
18
18
|
"prepare": "npm run build",
|
|
19
|
-
"test": "vitest",
|
|
20
|
-
"coverage": "vitest --coverage"
|
|
21
|
-
"preuninstall": "rm -rf ~/.esa/config"
|
|
19
|
+
"test": "FORCE_COLOR=0 npx vitest ",
|
|
20
|
+
"coverage": "vitest --coverage"
|
|
22
21
|
},
|
|
23
22
|
"keywords": [
|
|
24
23
|
"cli",
|
|
25
24
|
"edge",
|
|
26
25
|
"esa",
|
|
26
|
+
"edgeRoutine",
|
|
27
27
|
"alibaba",
|
|
28
28
|
"ali"
|
|
29
29
|
],
|
|
@@ -31,8 +31,11 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@babel/plugin-syntax-import-attributes": "^7.24.7",
|
|
34
|
+
"@testing-library/dom": "^10.4.0",
|
|
34
35
|
"@testing-library/jest-dom": "^6.5.0",
|
|
35
36
|
"@testing-library/react": "^16.0.1",
|
|
37
|
+
"@types/babel__generator": "^7.6.8",
|
|
38
|
+
"@types/babel__traverse": "^7.20.6",
|
|
36
39
|
"@types/cli-table": "^0.3.4",
|
|
37
40
|
"@types/cross-spawn": "^6.0.6",
|
|
38
41
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -50,7 +53,6 @@
|
|
|
50
53
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
54
|
"husky": "^8.0.3",
|
|
52
55
|
"jsdom": "^25.0.1",
|
|
53
|
-
"@testing-library/dom": "^10.4.0",
|
|
54
56
|
"lint-staged": "^15.0.2",
|
|
55
57
|
"prettier": "^3.0.3",
|
|
56
58
|
"react": "^18.2.0",
|
|
@@ -61,33 +63,38 @@
|
|
|
61
63
|
"vitest": "^2.0.4"
|
|
62
64
|
},
|
|
63
65
|
"dependencies": {
|
|
66
|
+
"@alicloud/esa20240910": "2.8.1",
|
|
64
67
|
"@alicloud/openapi-client": "^0.4.7",
|
|
68
|
+
"@babel/generator": "^7.26.3",
|
|
65
69
|
"@babel/parser": "^7.24.4",
|
|
66
70
|
"@babel/traverse": "^7.24.1",
|
|
67
71
|
"@iarna/toml": "^2.2.5",
|
|
68
|
-
"@tqman/ink-table": "^0.0.0-development",
|
|
69
72
|
"@types/inquirer": "^9.0.7",
|
|
70
73
|
"@vitest/coverage-istanbul": "^2.0.4",
|
|
74
|
+
"axios": "^1.7.7",
|
|
71
75
|
"chalk": "^5.3.0",
|
|
72
76
|
"chokidar": "^3.5.3",
|
|
73
77
|
"cli-table3": "^0.6.5",
|
|
74
78
|
"cross-spawn": "^7.0.3",
|
|
75
|
-
"esa-template": "^0.0.
|
|
79
|
+
"esa-template": "^0.0.3",
|
|
76
80
|
"esbuild": "^0.21.1",
|
|
77
81
|
"esbuild-plugin-less": "^1.3.8",
|
|
78
82
|
"form-data": "^4.0.0",
|
|
79
83
|
"fs-extra": "^11.2.0",
|
|
84
|
+
"http-proxy-agent": "^7.0.2",
|
|
80
85
|
"ink": "^5.0.1",
|
|
81
86
|
"ink-select-input": "^6.0.0",
|
|
82
87
|
"ink-text-input": "^6.0.0",
|
|
83
88
|
"inquirer": "^9.2.15",
|
|
84
89
|
"js-base64": "^3.7.7",
|
|
90
|
+
"moment": "^2.30.1",
|
|
85
91
|
"node-fetch": "^3.3.2",
|
|
86
92
|
"open": "^9.1.0",
|
|
87
93
|
"ora": "^7.0.1",
|
|
88
94
|
"os-locale": "^6.0.2",
|
|
89
95
|
"portscanner": "^2.2.0",
|
|
90
96
|
"winston": "^3.11.0",
|
|
97
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
91
98
|
"yargs": "^17.7.2"
|
|
92
99
|
},
|
|
93
100
|
"repository": {
|
|
@@ -52,17 +52,16 @@ const echoNewInspectTip = () => {
|
|
|
52
52
|
logger.point(t('dev_inspect_tip5').d('Now you can use Chrome inspect with new port 😉'));
|
|
53
53
|
logger.block();
|
|
54
54
|
};
|
|
55
|
-
const checkAndInputPort = (
|
|
56
|
-
let
|
|
55
|
+
const checkAndInputPort = (port, inspectPort) => __awaiter(void 0, void 0, void 0, function* () {
|
|
56
|
+
let finalPort = port;
|
|
57
57
|
let finalInspectPort = inspectPort;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
logger.error(t('dev_port_used', { stringDenoPort }).d(`Port ${stringDenoPort} already in use.`));
|
|
58
|
+
const isPortAvailable = yield checkPort(port);
|
|
59
|
+
const stringPort = port.toString();
|
|
60
|
+
if (!isPortAvailable) {
|
|
61
|
+
logger.error(t('dev_port_used', { stringPort }).d(`Port ${stringPort} already in use.`));
|
|
63
62
|
try {
|
|
64
|
-
const availablePort = yield findAvailablePort(
|
|
65
|
-
|
|
63
|
+
const availablePort = yield findAvailablePort(port);
|
|
64
|
+
finalPort = (yield inquirer.prompt([
|
|
66
65
|
{
|
|
67
66
|
type: 'number',
|
|
68
67
|
name: 'port',
|
|
@@ -70,18 +69,24 @@ const checkAndInputPort = (denoPort, inspectPort) => __awaiter(void 0, void 0, v
|
|
|
70
69
|
default: availablePort
|
|
71
70
|
}
|
|
72
71
|
])).port;
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
72
|
+
const isNewPortAvailable = yield checkPort(finalPort);
|
|
73
|
+
if (!isNewPortAvailable) {
|
|
75
74
|
logger.error(t('dev_port_invalid').d('This port is invalid.'));
|
|
76
75
|
throw new Error('Specified port already in use.');
|
|
77
76
|
}
|
|
78
77
|
}
|
|
79
78
|
catch (_) {
|
|
80
79
|
const option = chalk.green('esa dev --port <port>');
|
|
81
|
-
logger.
|
|
80
|
+
logger.log(t('dev_port_used_advice', { option }).d(`You can use ${option} to specify another port.`));
|
|
82
81
|
throw new Error('Specified port already in use.');
|
|
83
82
|
}
|
|
84
83
|
}
|
|
84
|
+
if (!inspectPort) {
|
|
85
|
+
return {
|
|
86
|
+
port: finalPort
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const stringInspectPort = inspectPort.toString();
|
|
85
90
|
const isInspectPortAvailable = yield checkPort(inspectPort);
|
|
86
91
|
if (!isInspectPortAvailable) {
|
|
87
92
|
logger.error(t('dev_inspect_port_used', { stringInspectPort }).d(`Inspect port ${stringInspectPort} already in use.`));
|
|
@@ -98,7 +103,7 @@ const checkAndInputPort = (denoPort, inspectPort) => __awaiter(void 0, void 0, v
|
|
|
98
103
|
}
|
|
99
104
|
catch (_) {
|
|
100
105
|
const option = chalk.green('esa dev --inspect-port <port>');
|
|
101
|
-
logger.
|
|
106
|
+
logger.log(t('dev_port_used_advice', { option }).d(`You can use ${option} to specify another port.`));
|
|
102
107
|
throw new Error('Inspect port already in use.');
|
|
103
108
|
}
|
|
104
109
|
}
|
|
@@ -106,7 +111,7 @@ const checkAndInputPort = (denoPort, inspectPort) => __awaiter(void 0, void 0, v
|
|
|
106
111
|
echoNewInspectTip();
|
|
107
112
|
}
|
|
108
113
|
return {
|
|
109
|
-
|
|
114
|
+
port: finalPort,
|
|
110
115
|
inspectPort: finalInspectPort
|
|
111
116
|
};
|
|
112
117
|
});
|