esa-cli 0.0.1-beta.9 → 0.0.2-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.
Files changed (43) hide show
  1. package/README.md +3 -5
  2. package/bin/enter.cjs +0 -1
  3. package/dist/bin/enter.cjs +0 -1
  4. package/dist/commands/commit/index.js +2 -2
  5. package/dist/commands/deploy/index.js +4 -2
  6. package/dist/commands/deployments/list.js +2 -1
  7. package/dist/commands/dev/build.js +57 -0
  8. package/dist/commands/dev/doProcess.js +10 -2
  9. package/dist/commands/dev/ew2/devEntry.js +9 -0
  10. package/dist/commands/dev/ew2/devPack.js +185 -0
  11. package/dist/commands/dev/ew2/mock/cache.js +32 -0
  12. package/dist/commands/dev/ew2/mock/kv.js +45 -0
  13. package/dist/commands/dev/ew2/server.js +234 -0
  14. package/dist/commands/dev/index.js +111 -49
  15. package/dist/commands/dev/{config → mockWorker}/devEntry.js +3 -2
  16. package/dist/commands/dev/{devPack.js → mockWorker/devPack.js} +10 -8
  17. package/dist/commands/dev/{server.js → mockWorker/server.js} +43 -37
  18. package/dist/commands/init/index.js +117 -42
  19. package/dist/commands/login/index.js +2 -2
  20. package/dist/commands/logout.js +0 -4
  21. package/dist/commands/route/list.js +2 -1
  22. package/dist/commands/routine/list.js +6 -4
  23. package/dist/components/mutiLevelSelect.js +69 -0
  24. package/dist/i18n/locales.json +120 -4
  25. package/dist/index.js +8 -0
  26. package/dist/libs/api.js +155 -0
  27. package/dist/libs/logger.js +42 -31
  28. package/dist/libs/service.js +178 -0
  29. package/dist/utils/checkDevPort.js +19 -14
  30. package/dist/utils/checkOS.js +32 -0
  31. package/dist/utils/fileMd5.js +18 -0
  32. package/dist/utils/install/installEw2.sh +33 -0
  33. package/dist/utils/{installRuntime.js → installDeno.js} +15 -15
  34. package/dist/utils/installEw2.js +127 -0
  35. package/dist/utils/stepsRunner.js +33 -0
  36. package/package.json +19 -8
  37. package/{dist/zh_CN.md → zh_CN.md} +4 -5
  38. package/dist/README.md +0 -175
  39. package/dist/commands/dev/config/devBuild.js +0 -26
  40. package/dist/libs/request.js +0 -98
  41. package/dist/package.json +0 -96
  42. /package/dist/commands/dev/{config → mockWorker}/mock/cache.js +0 -0
  43. /package/dist/commands/dev/{config → mockWorker}/mock/kv.js +0 -0
@@ -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 = (denoPort, inspectPort) => __awaiter(void 0, void 0, void 0, function* () {
56
- let finalDenoPort = denoPort;
55
+ const checkAndInputPort = (port, inspectPort) => __awaiter(void 0, void 0, void 0, function* () {
56
+ let finalPort = port;
57
57
  let finalInspectPort = inspectPort;
58
- const isDenoPortAvailable = yield checkPort(denoPort);
59
- const stringDenoPort = denoPort.toString();
60
- const stringInspectPort = inspectPort.toString();
61
- if (!isDenoPortAvailable) {
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(denoPort);
65
- finalDenoPort = (yield inquirer.prompt([
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 isNewDenoPortAvailable = yield checkPort(finalDenoPort);
74
- if (!isNewDenoPortAvailable) {
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.info(t('dev_port_used_advice', { option }).d(`You can use ${option} to specify another port.`));
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.info(t('dev_port_used_advice', { option }).d(`You can use ${option} to specify another port.`));
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
- denoPort: finalDenoPort,
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
+ }
@@ -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 preCheckRuntime() {
16
+ export function preCheckDeno() {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
- const command = yield checkRuntimeInstalled();
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 checkDeno(command) {
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/package.json CHANGED
@@ -1,28 +1,32 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "0.0.1-beta.9",
3
+ "version": "0.0.2-beta.1",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
7
- "files": [
8
- "dist/"
9
- ],
10
7
  "bin": {
11
8
  "esa": "bin/enter.cjs"
12
9
  },
10
+ "files": [
11
+ "bin",
12
+ "dist/",
13
+ "zh_CN.md",
14
+ "README.md"
15
+ ],
13
16
  "scripts": {
14
17
  "build": "rm -rf ./dist && rm -rf ./build && node ./genLocale.cjs && tsc && node ./copy.cjs",
15
18
  "watch": "tsc --watch",
16
19
  "eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
17
20
  "lint-staged": "lint-staged",
18
21
  "prepare": "npm run build",
19
- "test": "vitest",
22
+ "test": "FORCE_COLOR=0 npx vitest ",
20
23
  "coverage": "vitest --coverage"
21
24
  },
22
25
  "keywords": [
23
26
  "cli",
24
27
  "edge",
25
28
  "esa",
29
+ "edgeRoutine",
26
30
  "alibaba",
27
31
  "ali"
28
32
  ],
@@ -30,8 +34,11 @@
30
34
  "license": "MIT",
31
35
  "devDependencies": {
32
36
  "@babel/plugin-syntax-import-attributes": "^7.24.7",
37
+ "@testing-library/dom": "^10.4.0",
33
38
  "@testing-library/jest-dom": "^6.5.0",
34
39
  "@testing-library/react": "^16.0.1",
40
+ "@types/babel__generator": "^7.6.8",
41
+ "@types/babel__traverse": "^7.20.6",
35
42
  "@types/cli-table": "^0.3.4",
36
43
  "@types/cross-spawn": "^6.0.6",
37
44
  "@types/fs-extra": "^11.0.4",
@@ -49,7 +56,6 @@
49
56
  "eslint-plugin-react-hooks": "^4.6.0",
50
57
  "husky": "^8.0.3",
51
58
  "jsdom": "^25.0.1",
52
- "@testing-library/dom": "^10.4.0",
53
59
  "lint-staged": "^15.0.2",
54
60
  "prettier": "^3.0.3",
55
61
  "react": "^18.2.0",
@@ -60,33 +66,38 @@
60
66
  "vitest": "^2.0.4"
61
67
  },
62
68
  "dependencies": {
69
+ "@alicloud/esa20240910": "2.8.1",
63
70
  "@alicloud/openapi-client": "^0.4.7",
71
+ "@babel/generator": "^7.26.3",
64
72
  "@babel/parser": "^7.24.4",
65
73
  "@babel/traverse": "^7.24.1",
66
74
  "@iarna/toml": "^2.2.5",
67
- "@tqman/ink-table": "^0.0.0-development",
68
75
  "@types/inquirer": "^9.0.7",
69
76
  "@vitest/coverage-istanbul": "^2.0.4",
77
+ "axios": "^1.7.7",
70
78
  "chalk": "^5.3.0",
71
79
  "chokidar": "^3.5.3",
72
80
  "cli-table3": "^0.6.5",
73
81
  "cross-spawn": "^7.0.3",
74
- "esa-template": "^0.0.1-beta.2",
82
+ "esa-template": "^0.0.3",
75
83
  "esbuild": "^0.21.1",
76
84
  "esbuild-plugin-less": "^1.3.8",
77
85
  "form-data": "^4.0.0",
78
86
  "fs-extra": "^11.2.0",
87
+ "http-proxy-agent": "^7.0.2",
79
88
  "ink": "^5.0.1",
80
89
  "ink-select-input": "^6.0.0",
81
90
  "ink-text-input": "^6.0.0",
82
91
  "inquirer": "^9.2.15",
83
92
  "js-base64": "^3.7.7",
93
+ "moment": "^2.30.1",
84
94
  "node-fetch": "^3.3.2",
85
95
  "open": "^9.1.0",
86
96
  "ora": "^7.0.1",
87
97
  "os-locale": "^6.0.2",
88
98
  "portscanner": "^2.2.0",
89
99
  "winston": "^3.11.0",
100
+ "winston-daily-rotate-file": "^5.0.0",
90
101
  "yargs": "^17.7.2"
91
102
  },
92
103
  "repository": {
@@ -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 处于公测阶段,如果您在使用中遇到任何问题,或者有任何建议,请随时提交 issue 或 pull request。
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
  ![调试界面](https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/dev.png)
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/dist/README.md DELETED
@@ -1,175 +0,0 @@
1
- # ESA CLI
2
-
3
- A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions). It supports quick creation of edge functions, local debugging, version publishing and deployment, and trigger management.
4
-
5
- English | [简体中文](./zh_CN.md)
6
-
7
- #### Reference
8
-
9
- - [Edge Security Acceleration (ESA)](https://www.aliyun.com/product/esa)
10
- - [What is EdgeRoutine?](https://help.aliyun.com/document_detail/2710021.html)
11
-
12
- > **Note**: ESA CLI is in public beta. If you encounter any issues or have any suggestions while using it, please feel free to submit an issue or a pull request.
13
- >
14
- > We are actively working to improve this tool and welcome any feedback. Thank you for your understanding and support!
15
-
16
- ## Installation
17
-
18
- Install and run the CLI using npm:
19
-
20
- ```bash
21
- $ npm install esa-cli -g # Install globally
22
- $ esa -v # Check the version
23
- ```
24
-
25
- ## Usage
26
-
27
- ### 1. Initialize Routine Project
28
-
29
- ```bash
30
- & esa init
31
- ```
32
-
33
- The initialization command has a complete process guide. Follow the prompts to enter the project name and choose a template.
34
-
35
- ### 2. Start a local server for developing your routine
36
-
37
- Local dev is the core feature of the CLI, offering a more convenient debugging experience compared to the Alibaba Cloud ESA console.
38
-
39
- ```bash
40
- & cd <Project Name>
41
- & esa dev [options]
42
- ```
43
-
44
- #### Write Code
45
-
46
- In an EdgeRoutine project, the entry file is `src/index.js`, and the basic structure is as follows:
47
-
48
- ```javascript
49
- const html = `<!DOCTYPE html>
50
- <body>
51
- <h1>Hello World!</h1>
52
- </body>`;
53
-
54
- async function handleRequest(request) {
55
- return new Response(html, {
56
- headers: {
57
- 'content-type': 'text/html;charset=UTF-8'
58
- }
59
- });
60
- }
61
-
62
- export default {
63
- async fetch(event) {
64
- return event.respondWith(handleRequest(event));
65
- }
66
- };
67
- ```
68
-
69
- For more EdgeRoutine APIs and syntax, please refer to the [API Reference](https://help.aliyun.com/document_detail/2710024.html)
70
-
71
- #### Local Debugging
72
-
73
- After executing `esa dev`, the entry file will be automatically packaged and a local debugging service will be started. The interface looks like this:
74
-
75
- ![dev png](https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/dev.png)
76
-
77
- - Press `b` to open the debugging page in the browser.
78
- - Press `d` to view debugging instructions. **Chrome does not allow the command line to open the debugging page**.
79
- - Open `chrome://inspect#devices` in the Chrome browser to see a running Remote Target. Click inspect below it to view console information. **Note that the EdgeRoutine code is server-side, so the console on the preview page will not output console in the entry file. Use inspect for debugging.**
80
- - Press `c` to clear the panel.
81
- - Press `x` to exit debugging.
82
- - You can use `esa dev --port <port>` to temporarily specify the port or use `esa config -l` to set the port by project configuration.
83
-
84
- ### 3. Log in to Alibaba Cloud Account
85
-
86
- You need to log in to your Alibaba Cloud account to perform remote management operations.
87
-
88
- First, visit the [Alibaba Cloud RAM Console](https://ram.console.aliyun.com/manage/ak) to get your AccessKey ID and AccessKey Secret, then execute `esa login` and follow the prompts to enter them.
89
-
90
- ```bash
91
- & esa login
92
- & esa logout
93
- ```
94
-
95
- ### 4. Create a Version
96
-
97
- After local debugging is complete, you need to create a code version for deployment.
98
-
99
- ```bash
100
- & esa commit # Create a Version
101
- ```
102
-
103
- ### 5. Deploy to Environment & Manage Versions and Deployments
104
-
105
- After the code version is created, it needs to be deployed to edge nodes.
106
-
107
- Use the `esa deployments [script]` command to manage versions and deployments.
108
-
109
- ```bash
110
- & esa deploy # Deploy versions to the target environment
111
- & esa deployments list # View deployments
112
- & esa deployments delete <versionId> # Delete a version
113
- ```
114
-
115
- _Note: Deployed versions cannot be deleted._
116
-
117
- ### 6. Manage Triggers
118
-
119
- Once deployed to the nodes, you can configure triggers to access your edge functions. There are two types of triggers:
120
-
121
- - Domain: After you associate the routine with a domain name, you can use the domain name to access the routine.
122
- - Route: After you add a route for requested URLs, the routine is called from the edge to respond to the request.
123
-
124
- ```bash
125
- & esa domain list
126
- & esa domain add <domainName>
127
- & esa domain delete <domainName>
128
-
129
- & esa route list
130
- & esa route add [route] [site]
131
- & esa route delete <route>
132
- ```
133
-
134
- ### 7. Manage Functions
135
-
136
- You can view and delete Routine functions through the CLI.
137
-
138
- ```bash
139
- & esa routine list
140
- & esa routine delete <routineName>
141
- ```
142
-
143
- ## Commands
144
-
145
- see [Commands](./docs/Commands_en.md)
146
-
147
- ## Config files
148
-
149
- ### Global config file
150
-
151
- ```toml
152
- endpoint = "" # ESA API Endpoint
153
- lang = "zh_CN" # language
154
-
155
- [auth]
156
- accessKeyId = "" # AccessKey ID
157
- accessKeySecret = "" # AccessKey Secret
158
- ```
159
-
160
- ### Project config file
161
-
162
- ```toml
163
- name = "Hello World" # Project name
164
- description = "Hello World" # Project description
165
- entry = "src/index.js" # Entry file
166
- codeVersions = [ ] # Code version
167
-
168
- [dev]
169
- port = 18080 # Debug port
170
- localUpstream = '' # When debugging locally, the upstream source site will replace the current origin when returning to the source
171
- ```
172
-
173
- ## LICENSE
174
-
175
- [The MIT License](./LICENSE)