esa-cli 0.0.1-beta.9 → 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/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 +111 -49
- package/dist/commands/dev/{config → mockWorker}/devEntry.js +3 -2
- package/dist/commands/dev/{devPack.js → mockWorker/devPack.js} +10 -8
- package/dist/commands/dev/{server.js → mockWorker/server.js} +43 -37
- package/dist/commands/init/index.js +117 -42
- 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/components/mutiLevelSelect.js +69 -0
- package/dist/i18n/locales.json +120 -4
- package/dist/index.js +8 -0
- 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 +13 -5
- package/dist/utils/checkDevPort.js +19 -14
- package/dist/utils/checkOS.js +32 -0
- package/dist/utils/fileMd5.js +18 -0
- package/dist/utils/fileUtils/index.js +1 -1
- package/dist/utils/install/installEw2.sh +33 -0
- package/dist/utils/{installRuntime.js → installDeno.js} +15 -15
- package/dist/utils/installEw2.js +127 -0
- package/dist/utils/stepsRunner.js +33 -0
- package/dist/zh_CN.md +4 -5
- package/package.json +13 -5
- 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/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,13 +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",
|
|
19
|
+
"test": "FORCE_COLOR=0 npx vitest ",
|
|
20
20
|
"coverage": "vitest --coverage"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"cli",
|
|
24
24
|
"edge",
|
|
25
25
|
"esa",
|
|
26
|
+
"edgeRoutine",
|
|
26
27
|
"alibaba",
|
|
27
28
|
"ali"
|
|
28
29
|
],
|
|
@@ -30,8 +31,11 @@
|
|
|
30
31
|
"license": "MIT",
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@babel/plugin-syntax-import-attributes": "^7.24.7",
|
|
34
|
+
"@testing-library/dom": "^10.4.0",
|
|
33
35
|
"@testing-library/jest-dom": "^6.5.0",
|
|
34
36
|
"@testing-library/react": "^16.0.1",
|
|
37
|
+
"@types/babel__generator": "^7.6.8",
|
|
38
|
+
"@types/babel__traverse": "^7.20.6",
|
|
35
39
|
"@types/cli-table": "^0.3.4",
|
|
36
40
|
"@types/cross-spawn": "^6.0.6",
|
|
37
41
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -49,7 +53,6 @@
|
|
|
49
53
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
50
54
|
"husky": "^8.0.3",
|
|
51
55
|
"jsdom": "^25.0.1",
|
|
52
|
-
"@testing-library/dom": "^10.4.0",
|
|
53
56
|
"lint-staged": "^15.0.2",
|
|
54
57
|
"prettier": "^3.0.3",
|
|
55
58
|
"react": "^18.2.0",
|
|
@@ -60,33 +63,38 @@
|
|
|
60
63
|
"vitest": "^2.0.4"
|
|
61
64
|
},
|
|
62
65
|
"dependencies": {
|
|
66
|
+
"@alicloud/esa20240910": "2.8.1",
|
|
63
67
|
"@alicloud/openapi-client": "^0.4.7",
|
|
68
|
+
"@babel/generator": "^7.26.3",
|
|
64
69
|
"@babel/parser": "^7.24.4",
|
|
65
70
|
"@babel/traverse": "^7.24.1",
|
|
66
71
|
"@iarna/toml": "^2.2.5",
|
|
67
|
-
"@tqman/ink-table": "^0.0.0-development",
|
|
68
72
|
"@types/inquirer": "^9.0.7",
|
|
69
73
|
"@vitest/coverage-istanbul": "^2.0.4",
|
|
74
|
+
"axios": "^1.7.7",
|
|
70
75
|
"chalk": "^5.3.0",
|
|
71
76
|
"chokidar": "^3.5.3",
|
|
72
77
|
"cli-table3": "^0.6.5",
|
|
73
78
|
"cross-spawn": "^7.0.3",
|
|
74
|
-
"esa-template": "^0.0.
|
|
79
|
+
"esa-template": "^0.0.3",
|
|
75
80
|
"esbuild": "^0.21.1",
|
|
76
81
|
"esbuild-plugin-less": "^1.3.8",
|
|
77
82
|
"form-data": "^4.0.0",
|
|
78
83
|
"fs-extra": "^11.2.0",
|
|
84
|
+
"http-proxy-agent": "^7.0.2",
|
|
79
85
|
"ink": "^5.0.1",
|
|
80
86
|
"ink-select-input": "^6.0.0",
|
|
81
87
|
"ink-text-input": "^6.0.0",
|
|
82
88
|
"inquirer": "^9.2.15",
|
|
83
89
|
"js-base64": "^3.7.7",
|
|
90
|
+
"moment": "^2.30.1",
|
|
84
91
|
"node-fetch": "^3.3.2",
|
|
85
92
|
"open": "^9.1.0",
|
|
86
93
|
"ora": "^7.0.1",
|
|
87
94
|
"os-locale": "^6.0.2",
|
|
88
95
|
"portscanner": "^2.2.0",
|
|
89
96
|
"winston": "^3.11.0",
|
|
97
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
90
98
|
"yargs": "^17.7.2"
|
|
91
99
|
},
|
|
92
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
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import os from 'os';
|
|
2
|
+
export var Platforms;
|
|
3
|
+
(function (Platforms) {
|
|
4
|
+
Platforms["Win"] = "win";
|
|
5
|
+
Platforms["AppleArm"] = "darwin-arm64";
|
|
6
|
+
Platforms["AppleIntel"] = "darwin-x86_64";
|
|
7
|
+
Platforms["LinuxX86"] = "linux-x86_64";
|
|
8
|
+
Platforms["Linux"] = "linux";
|
|
9
|
+
Platforms["others"] = "others";
|
|
10
|
+
})(Platforms || (Platforms = {}));
|
|
11
|
+
export const checkOS = () => {
|
|
12
|
+
const platform = os.platform();
|
|
13
|
+
const cpus = os.cpus();
|
|
14
|
+
const cpuModel = cpus[0].model.toLowerCase();
|
|
15
|
+
const arch = os.arch();
|
|
16
|
+
if (platform === 'win32') {
|
|
17
|
+
return Platforms.Win;
|
|
18
|
+
}
|
|
19
|
+
if (platform === 'darwin') {
|
|
20
|
+
if (cpuModel.includes('apple')) {
|
|
21
|
+
return Platforms.AppleArm;
|
|
22
|
+
}
|
|
23
|
+
return Platforms.AppleIntel;
|
|
24
|
+
}
|
|
25
|
+
if (platform === 'linux') {
|
|
26
|
+
if (arch === 'x64') {
|
|
27
|
+
return Platforms.LinuxX86;
|
|
28
|
+
}
|
|
29
|
+
return Platforms.Linux;
|
|
30
|
+
}
|
|
31
|
+
return Platforms.others;
|
|
32
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
export function calculateFileMD5(filePath) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const hash = crypto.createHash('md5');
|
|
6
|
+
const fileStream = fs.createReadStream(filePath);
|
|
7
|
+
fileStream.on('data', (data) => {
|
|
8
|
+
hash.update(data);
|
|
9
|
+
});
|
|
10
|
+
fileStream.on('end', () => {
|
|
11
|
+
const md5sum = hash.digest('hex');
|
|
12
|
+
resolve(md5sum);
|
|
13
|
+
});
|
|
14
|
+
fileStream.on('error', (err) => {
|
|
15
|
+
reject(err);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -188,7 +188,7 @@ export const getApiConfig = () => {
|
|
|
188
188
|
};
|
|
189
189
|
return config;
|
|
190
190
|
};
|
|
191
|
-
export const templateHubPath = path.join(getDirName(import.meta.url), '
|
|
191
|
+
export const templateHubPath = path.join(getDirName(import.meta.url), '../../node_modules/esa-template/src');
|
|
192
192
|
export const getTemplatesConfig = () => {
|
|
193
193
|
const manifestPath = path.join(templateHubPath, 'manifest.json');
|
|
194
194
|
const config = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
os_type=$(uname -s)
|
|
5
|
+
|
|
6
|
+
if [ "$os_type" = "Darwin" ]; then
|
|
7
|
+
cpu_info=$(sysctl -n machdep.cpu.brand_string)
|
|
8
|
+
if echo "$cpu_info" | grep -q "Apple M"; then
|
|
9
|
+
target="darwin-arm64"
|
|
10
|
+
else
|
|
11
|
+
target="darwin-x86_64"
|
|
12
|
+
fi
|
|
13
|
+
else
|
|
14
|
+
target="linux-x86_64"
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
version="$1"
|
|
18
|
+
ew2_uri="http://esa-runtime.myalicdn.com/ew2/${version}/${target}/edgeworker2"
|
|
19
|
+
echo "${ew2_uri}"
|
|
20
|
+
bin_dir="$HOME/.ew2"
|
|
21
|
+
exe="$bin_dir/edgeworker2"
|
|
22
|
+
|
|
23
|
+
if [ ! -d "$bin_dir" ]; then
|
|
24
|
+
mkdir -p "$bin_dir"
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
curl --fail --location --progress-bar --output "$exe" "$ew2_uri"
|
|
28
|
+
|
|
29
|
+
chmod +rwx "$exe"
|
|
30
|
+
chmod +rw "$bin_dir"
|
|
31
|
+
|
|
32
|
+
echo "Runtime was installed successfully to $exe"
|
|
33
|
+
|
|
@@ -13,9 +13,9 @@ import { getDirName } from './fileUtils/base.js';
|
|
|
13
13
|
import logger from '../libs/logger.js';
|
|
14
14
|
import path from 'path';
|
|
15
15
|
import t from '../i18n/index.js';
|
|
16
|
-
export function
|
|
16
|
+
export function preCheckDeno() {
|
|
17
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const command = yield
|
|
18
|
+
const command = yield checkDenoInstalled();
|
|
19
19
|
if (!command) {
|
|
20
20
|
logger.error(t('install_runtime_explain').d('Under the beta phase, we are temporarily using Deno as the local development runtime. It needs to be installed first.'));
|
|
21
21
|
installDeno();
|
|
@@ -24,20 +24,20 @@ export function preCheckRuntime() {
|
|
|
24
24
|
return command;
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
return new Promise((resolve, reject) => {
|
|
29
|
-
exec(`${command} --version`, (err) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
reject();
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
resolve(command);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
export function checkRuntimeInstalled() {
|
|
27
|
+
export function checkDenoInstalled() {
|
|
40
28
|
const homeDeno = path.resolve(os.homedir(), '.deno/bin/deno');
|
|
29
|
+
function checkDeno(command) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
exec(`${command} --version`, (err) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
reject();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
resolve(command);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
41
|
return new Promise((resolve) => {
|
|
42
42
|
// @ts-ignore
|
|
43
43
|
Promise.any([checkDeno('deno'), checkDeno(homeDeno)])
|
|
@@ -0,0 +1,127 @@
|
|
|
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 os from 'os';
|
|
11
|
+
import fs from 'fs-extra';
|
|
12
|
+
import path from 'path';
|
|
13
|
+
import util from 'util';
|
|
14
|
+
import https from 'https';
|
|
15
|
+
import { execSync } from 'child_process';
|
|
16
|
+
import logger from '../libs/logger.js';
|
|
17
|
+
import { getDirName } from './fileUtils/base.js';
|
|
18
|
+
import t from '../i18n/index.js';
|
|
19
|
+
import { calculateFileMD5 } from './fileMd5.js';
|
|
20
|
+
import { checkOS } from './checkOS.js';
|
|
21
|
+
export const EW2DirName = '.ew2';
|
|
22
|
+
export const EW2BinName = 'edgeworker2';
|
|
23
|
+
export const EW2Path = path.join(os.homedir(), EW2DirName);
|
|
24
|
+
export const EW2BinPath = path.join(EW2Path, EW2BinName);
|
|
25
|
+
export const EW2ManifestPath = path.join(EW2Path, 'manifest.json');
|
|
26
|
+
export function preCheckEw2() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const fsAccess = util.promisify(fs.access);
|
|
29
|
+
const manifestRes = yield checkManifest();
|
|
30
|
+
function installVersion(manifest) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
try {
|
|
33
|
+
yield installEw2(manifest);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
const err = error;
|
|
38
|
+
logger.error(err.message);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
yield fsAccess(EW2BinPath, fs.constants.X_OK);
|
|
45
|
+
if (!manifestRes.isLatest) {
|
|
46
|
+
logger.warn(t('install_runtime_update_tip').d(`🔔 Runtime must be update to use esa dev. Installing...`));
|
|
47
|
+
return yield installVersion(manifestRes.remoteManifest);
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const err = error;
|
|
53
|
+
if (err.code === 'EACCES') {
|
|
54
|
+
logger.pathEacces(EW2BinPath);
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (err.code === 'ENOENT' || err.code === 'EPERM') {
|
|
58
|
+
logger.warn(t('install_runtime_tip').d(`🔔 Runtime must be installed to use esa dev. Installing...`));
|
|
59
|
+
return yield installVersion(manifestRes.remoteManifest);
|
|
60
|
+
}
|
|
61
|
+
logger.error(err.message);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function fetchRemoteManifest() {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
https
|
|
69
|
+
.get('https://edgestar-cn.oss-cn-beijing.aliyuncs.com/ew2/manifest.json', (res) => {
|
|
70
|
+
let data = '';
|
|
71
|
+
res.on('data', (chunk) => (data += chunk));
|
|
72
|
+
res.on('end', () => {
|
|
73
|
+
try {
|
|
74
|
+
const json = JSON.parse(data);
|
|
75
|
+
resolve(json);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
reject(null);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
})
|
|
82
|
+
.on('error', (err) => reject);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export function checkManifest() {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
let isLatest = false;
|
|
88
|
+
const remoteManifest = yield fetchRemoteManifest();
|
|
89
|
+
const localManifestExists = yield fs.pathExists(EW2ManifestPath);
|
|
90
|
+
logger.info(`Remote version: ${remoteManifest.version}`);
|
|
91
|
+
if (localManifestExists) {
|
|
92
|
+
const localManifest = yield fs.readJSON(EW2ManifestPath);
|
|
93
|
+
isLatest = localManifest.version === remoteManifest.version;
|
|
94
|
+
logger.info(`Local version: ${localManifest.version}`);
|
|
95
|
+
if (!isLatest) {
|
|
96
|
+
logger.log(`Runtime Latest version: ${remoteManifest.version}, Current version: ${localManifest.version}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
remoteManifest,
|
|
101
|
+
isLatest
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
export function installEw2(manifest) {
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const __dirname = getDirName(import.meta.url);
|
|
108
|
+
const p = path.join(__dirname, './install');
|
|
109
|
+
const installCommand = `sh ${p}/installEw2.sh ${manifest.version}`;
|
|
110
|
+
try {
|
|
111
|
+
execSync(installCommand, { stdio: 'inherit', env: Object.assign({}, process.env) });
|
|
112
|
+
const md5 = yield calculateFileMD5(EW2BinPath);
|
|
113
|
+
const os = checkOS();
|
|
114
|
+
// @ts-ignore;
|
|
115
|
+
if (md5 === manifest[`${os}_checksum`]) {
|
|
116
|
+
logger.success('Runtime checksum success.');
|
|
117
|
+
}
|
|
118
|
+
yield fs.writeJSON(EW2ManifestPath, manifest);
|
|
119
|
+
logger.success(t('install_runtime_success').d(`Runtime installed.`));
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
logger.error(`Failed to install: ${error.message}`);
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
function stepsRunner(promises) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
const results = [];
|
|
14
|
+
for (const promise of promises) {
|
|
15
|
+
const spinner = ora('Loading...').start();
|
|
16
|
+
try {
|
|
17
|
+
const result = yield promise();
|
|
18
|
+
spinner.succeed('Success!');
|
|
19
|
+
results.push({ status: 'success', message: result });
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
spinner.fail('Error: ' + (error instanceof Error ? error.message : 'Unknown Error'));
|
|
23
|
+
results.push({
|
|
24
|
+
status: 'error',
|
|
25
|
+
message: error instanceof Error ? error.message : 'Unknown Error'
|
|
26
|
+
});
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return results;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export default stepsRunner;
|
package/dist/zh_CN.md
CHANGED
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
- [边缘安全加速(ESA)](https://www.aliyun.com/product/esa)
|
|
10
10
|
- [边缘函数概述](https://help.aliyun.com/document_detail/2710021.html)
|
|
11
11
|
|
|
12
|
-
> **注意**: ESA CLI
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
> **注意**: **ESA CLI 在0.0.2以上版本的本地开发模式替换成了ESA边缘函数相同的Runtime,目前实际表现与线上相同,欢迎体验!**
|
|
13
|
+
|
|
14
|
+
ESA CLI 处于公测阶段,如果您在使用中遇到任何问题,或者有任何建议,请随时提交 issue 或 pull request。
|
|
15
|
+
我们正在积极改进,并欢迎任何反馈。感谢您的理解与支持!
|
|
15
16
|
|
|
16
17
|
## 安装
|
|
17
18
|
|
|
@@ -75,8 +76,6 @@ export default {
|
|
|
75
76
|

|
|
76
77
|
|
|
77
78
|
- 在界面上按 `b` 即可在浏览器中打开调试页面。
|
|
78
|
-
- 在界面上按 `d` 可以查看调试引导。**Chrome 不允许命令行打开调试页面。**
|
|
79
|
-
- 在 Chrome 浏览器中打开 `Chrome://inspect#devices` 页面,可以看到一个运行的`Remote Target`,点击下面的`inspect`即可查看 console 信息。**注意,EdgeRoutine 的代码为服务端代码,所以预览页面的控制台并不会输出入口文件中的 `console`,只能通过`inspect`调试。**
|
|
80
79
|
- 在界面上按 `c` 可以清空面板。
|
|
81
80
|
- 在界面上按 `x` 可以退出调试。
|
|
82
81
|
- 可以用 `esa dev --port <port>` 临时指定端口,也可以使用 `esa config -l` 按照项目配置端口。
|
package/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,13 +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",
|
|
19
|
+
"test": "FORCE_COLOR=0 npx vitest ",
|
|
20
20
|
"coverage": "vitest --coverage"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"cli",
|
|
24
24
|
"edge",
|
|
25
25
|
"esa",
|
|
26
|
+
"edgeRoutine",
|
|
26
27
|
"alibaba",
|
|
27
28
|
"ali"
|
|
28
29
|
],
|
|
@@ -30,8 +31,11 @@
|
|
|
30
31
|
"license": "MIT",
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"@babel/plugin-syntax-import-attributes": "^7.24.7",
|
|
34
|
+
"@testing-library/dom": "^10.4.0",
|
|
33
35
|
"@testing-library/jest-dom": "^6.5.0",
|
|
34
36
|
"@testing-library/react": "^16.0.1",
|
|
37
|
+
"@types/babel__generator": "^7.6.8",
|
|
38
|
+
"@types/babel__traverse": "^7.20.6",
|
|
35
39
|
"@types/cli-table": "^0.3.4",
|
|
36
40
|
"@types/cross-spawn": "^6.0.6",
|
|
37
41
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -49,7 +53,6 @@
|
|
|
49
53
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
50
54
|
"husky": "^8.0.3",
|
|
51
55
|
"jsdom": "^25.0.1",
|
|
52
|
-
"@testing-library/dom": "^10.4.0",
|
|
53
56
|
"lint-staged": "^15.0.2",
|
|
54
57
|
"prettier": "^3.0.3",
|
|
55
58
|
"react": "^18.2.0",
|
|
@@ -60,33 +63,38 @@
|
|
|
60
63
|
"vitest": "^2.0.4"
|
|
61
64
|
},
|
|
62
65
|
"dependencies": {
|
|
66
|
+
"@alicloud/esa20240910": "2.8.1",
|
|
63
67
|
"@alicloud/openapi-client": "^0.4.7",
|
|
68
|
+
"@babel/generator": "^7.26.3",
|
|
64
69
|
"@babel/parser": "^7.24.4",
|
|
65
70
|
"@babel/traverse": "^7.24.1",
|
|
66
71
|
"@iarna/toml": "^2.2.5",
|
|
67
|
-
"@tqman/ink-table": "^0.0.0-development",
|
|
68
72
|
"@types/inquirer": "^9.0.7",
|
|
69
73
|
"@vitest/coverage-istanbul": "^2.0.4",
|
|
74
|
+
"axios": "^1.7.7",
|
|
70
75
|
"chalk": "^5.3.0",
|
|
71
76
|
"chokidar": "^3.5.3",
|
|
72
77
|
"cli-table3": "^0.6.5",
|
|
73
78
|
"cross-spawn": "^7.0.3",
|
|
74
|
-
"esa-template": "^0.0.
|
|
79
|
+
"esa-template": "^0.0.3",
|
|
75
80
|
"esbuild": "^0.21.1",
|
|
76
81
|
"esbuild-plugin-less": "^1.3.8",
|
|
77
82
|
"form-data": "^4.0.0",
|
|
78
83
|
"fs-extra": "^11.2.0",
|
|
84
|
+
"http-proxy-agent": "^7.0.2",
|
|
79
85
|
"ink": "^5.0.1",
|
|
80
86
|
"ink-select-input": "^6.0.0",
|
|
81
87
|
"ink-text-input": "^6.0.0",
|
|
82
88
|
"inquirer": "^9.2.15",
|
|
83
89
|
"js-base64": "^3.7.7",
|
|
90
|
+
"moment": "^2.30.1",
|
|
84
91
|
"node-fetch": "^3.3.2",
|
|
85
92
|
"open": "^9.1.0",
|
|
86
93
|
"ora": "^7.0.1",
|
|
87
94
|
"os-locale": "^6.0.2",
|
|
88
95
|
"portscanner": "^2.2.0",
|
|
89
96
|
"winston": "^3.11.0",
|
|
97
|
+
"winston-daily-rotate-file": "^5.0.0",
|
|
90
98
|
"yargs": "^17.7.2"
|
|
91
99
|
},
|
|
92
100
|
"repository": {
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import esbuild from 'esbuild';
|
|
2
|
-
import { lessLoader } from 'esbuild-plugin-less';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { getRoot } from '../../../utils/fileUtils/base.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
|
-
}
|