esa-cli 0.0.2-beta.21 → 0.0.2-beta.23

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 +31 -149
  2. package/dist/commands/commit/index.js +7 -2
  3. package/dist/commands/common/constant.js +4 -4
  4. package/dist/commands/common/utils.js +89 -89
  5. package/dist/commands/config.js +1 -1
  6. package/dist/commands/deploy/index.js +3 -2
  7. package/dist/commands/deployments/delete.js +2 -2
  8. package/dist/commands/deployments/index.js +1 -1
  9. package/dist/commands/dev/ew2/devPack.js +9 -9
  10. package/dist/commands/dev/ew2/kvService.js +5 -1
  11. package/dist/commands/dev/ew2/mock/kv.js +1 -1
  12. package/dist/commands/dev/ew2/server.js +1 -2
  13. package/dist/commands/dev/index.js +3 -3
  14. package/dist/commands/dev/mockWorker/devPack.js +3 -3
  15. package/dist/commands/domain/add.js +2 -2
  16. package/dist/commands/domain/index.js +2 -2
  17. package/dist/commands/init/helper.js +7 -9
  18. package/dist/commands/init/template.jsonc +1 -1
  19. package/dist/commands/route/add.js +19 -52
  20. package/dist/commands/route/helper.js +9 -10
  21. package/dist/commands/route/index.js +2 -2
  22. package/dist/commands/routine/delete.js +7 -6
  23. package/dist/commands/routine/index.js +4 -3
  24. package/dist/commands/routine/list.js +40 -22
  25. package/dist/commands/site/index.js +1 -1
  26. package/dist/commands/utils.js +5 -5
  27. package/dist/components/filterSelector.js +1 -1
  28. package/dist/components/routeBuilder.js +68 -0
  29. package/dist/docs/Commands_en.md +110 -74
  30. package/dist/docs/Commands_zh_CN.md +110 -74
  31. package/dist/i18n/locales.json +94 -58
  32. package/dist/index.js +2 -2
  33. package/dist/libs/apiService.js +7 -6
  34. package/dist/libs/logger.js +7 -7
  35. package/dist/utils/checkDevPort.js +2 -2
  36. package/dist/utils/checkIsRoutineCreated.js +2 -2
  37. package/dist/utils/compress.js +5 -5
  38. package/dist/utils/download.js +3 -3
  39. package/dist/utils/fileUtils/index.js +69 -18
  40. package/dist/utils/installDeno.js +1 -1
  41. package/dist/utils/installEw2.js +2 -2
  42. package/package.json +3 -2
  43. package/zh_CN.md +28 -154
@@ -17,8 +17,31 @@ import { getDirName, getRoot } from './base.js';
17
17
  const projectConfigFile = 'esa.toml';
18
18
  const __dirname = getDirName(import.meta.url);
19
19
  const root = getRoot();
20
- export const projectConfigPath = path.join(root, projectConfigFile);
20
+ // Function to get the actual project config file path (supports both .jsonc and .toml)
21
+ export const getProjectConfigPath = (filePath = root) => {
22
+ const configFormats = ['esa.jsonc', 'esa.toml'];
23
+ for (const format of configFormats) {
24
+ const configPath = path.join(filePath, format);
25
+ if (fs.existsSync(configPath)) {
26
+ return configPath;
27
+ }
28
+ }
29
+ // Default to .jsonc if no config file exists
30
+ return path.join(filePath, 'esa.jsonc');
31
+ };
32
+ export const projectConfigPath = getProjectConfigPath();
21
33
  export const cliConfigPath = path.join(os.homedir(), '.esa/config/default.toml');
34
+ // Function to get the actual config file path (supports both .toml and .jsonc)
35
+ export const getCliConfigPath = () => {
36
+ const configDir = path.join(os.homedir(), '.esa/config');
37
+ const jsoncPath = path.join(configDir, 'default.jsonc');
38
+ const tomlPath = path.join(configDir, 'default.toml');
39
+ // Check if JSONC file exists first, then fallback to TOML
40
+ if (fs.existsSync(jsoncPath)) {
41
+ return jsoncPath;
42
+ }
43
+ return tomlPath;
44
+ };
22
45
  export const hiddenConfigDir = path.join(os.homedir(), '.esa/config');
23
46
  export const generateHiddenConfigDir = () => {
24
47
  if (!fs.existsSync(hiddenConfigDir)) {
@@ -28,7 +51,7 @@ export const generateHiddenConfigDir = () => {
28
51
  export const generateToml = (path) => {
29
52
  if (!fs.existsSync(path)) {
30
53
  fs.writeFileSync(path, '', 'utf-8');
31
- // 添加默认的endpoint
54
+ // Add default endpoint
32
55
  const defaultConfig = {
33
56
  endpoint: 'esa.cn-hangzhou.aliyuncs.com'
34
57
  };
@@ -37,20 +60,34 @@ export const generateToml = (path) => {
37
60
  };
38
61
  export const generateDefaultConfig = () => {
39
62
  generateHiddenConfigDir();
40
- generateToml(cliConfigPath);
63
+ const configPath = getCliConfigPath();
64
+ generateToml(configPath);
41
65
  };
42
66
  export function updateProjectConfigFile(configUpdate_1) {
43
67
  return __awaiter(this, arguments, void 0, function* (configUpdate, filePath = root) {
44
- const configPath = path.join(filePath, projectConfigFile);
68
+ const configPath = getProjectConfigPath(filePath);
45
69
  try {
46
70
  let configFileContent = yield fsPromises.readFile(configPath, 'utf8');
47
- let config = toml.parse(configFileContent);
48
- config = Object.assign(Object.assign({}, config), configUpdate);
49
- const updatedConfigString = toml.stringify(config);
71
+ let config;
72
+ let updatedConfigString;
73
+ // Detect file format based on file extension
74
+ if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
75
+ // Handle JSONC format
76
+ const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
77
+ config = JSON.parse(jsonContent);
78
+ config = Object.assign(Object.assign({}, config), configUpdate);
79
+ updatedConfigString = JSON.stringify(config, null, 2) + '\n';
80
+ }
81
+ else {
82
+ // Handle TOML format (default)
83
+ config = toml.parse(configFileContent);
84
+ config = Object.assign(Object.assign({}, config), configUpdate);
85
+ updatedConfigString = toml.stringify(config);
86
+ }
50
87
  yield fsPromises.writeFile(configPath, updatedConfigString);
51
88
  }
52
89
  catch (error) {
53
- logger.error(`Error updating TOML file: ${error}`);
90
+ logger.error(`Error updating config file: ${error}`);
54
91
  logger.pathEacces(__dirname);
55
92
  }
56
93
  });
@@ -58,16 +95,30 @@ export function updateProjectConfigFile(configUpdate_1) {
58
95
  export function updateCliConfigFile(configUpdate) {
59
96
  return __awaiter(this, void 0, void 0, function* () {
60
97
  try {
61
- let configFileContent = yield fsPromises.readFile(cliConfigPath, 'utf8');
62
- let config = toml.parse(configFileContent);
63
- config = Object.assign(Object.assign({}, config), configUpdate);
64
- const updatedConfigString = toml.stringify(config);
65
- yield fsPromises.writeFile(cliConfigPath, updatedConfigString);
98
+ const configPath = getCliConfigPath();
99
+ let configFileContent = yield fsPromises.readFile(configPath, 'utf8');
100
+ let config;
101
+ let updatedConfigString;
102
+ // Detect file format based on file extension
103
+ if (configPath.endsWith('.jsonc') || configPath.endsWith('.json')) {
104
+ // Handle JSONC format
105
+ const jsonContent = configFileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
106
+ config = JSON.parse(jsonContent);
107
+ config = Object.assign(Object.assign({}, config), configUpdate);
108
+ updatedConfigString = JSON.stringify(config, null, 2) + '\n';
109
+ }
110
+ else {
111
+ // Handle TOML format (default)
112
+ config = toml.parse(configFileContent);
113
+ config = Object.assign(Object.assign({}, config), configUpdate);
114
+ updatedConfigString = toml.stringify(config);
115
+ }
116
+ yield fsPromises.writeFile(configPath, updatedConfigString);
66
117
  }
67
118
  catch (error) {
68
- logger.error(`Error updating TOML file: ${error}`);
119
+ logger.error(`Error updating config file: ${error}`);
69
120
  logger.pathEacces(__dirname);
70
- throw new Error('Login error');
121
+ throw new Error('Config update error');
71
122
  }
72
123
  });
73
124
  }
@@ -88,7 +139,6 @@ export function readConfigFile(configPath) {
88
139
  }
89
140
  }
90
141
  catch (error) {
91
- console.log(error);
92
142
  logger.error(`Error parsing config file: ${error}`);
93
143
  return null;
94
144
  }
@@ -96,7 +146,8 @@ export function readConfigFile(configPath) {
96
146
  return null;
97
147
  }
98
148
  export function getCliConfig() {
99
- const res = readConfigFile(cliConfigPath);
149
+ const configPath = getCliConfigPath();
150
+ const res = readConfigFile(configPath);
100
151
  if (!res) {
101
152
  return null;
102
153
  }
@@ -133,7 +184,7 @@ export function getConfigurations() {
133
184
  }
134
185
  }
135
186
  export function generateConfigFile(projectName_1, initConfigs_1, targetDir_1) {
136
- return __awaiter(this, arguments, void 0, function* (projectName, initConfigs, targetDir, configFormat = 'toml', notFoundStrategy) {
187
+ return __awaiter(this, arguments, void 0, function* (projectName, initConfigs, targetDir, configFormat = 'jsonc', notFoundStrategy) {
137
188
  var _a, _b;
138
189
  const outputDir = targetDir !== null && targetDir !== void 0 ? targetDir : process.cwd();
139
190
  const currentDirName = path.basename(outputDir);
@@ -66,7 +66,7 @@ export function installDeno() {
66
66
  default:
67
67
  installCommand = `sh ${p}/install.sh`;
68
68
  }
69
- logger.warn(t('install_runtime_tip').d(`🔔 Runtime must be installed to use esa dev. Installing...`));
69
+ logger.warn(t('install_runtime_tip').d(`🔔 Runtime must be installed to use esa-cli dev. Installing...`));
70
70
  try {
71
71
  execSync(installCommand, { stdio: 'inherit' });
72
72
  logger.success(t('install_runtime_success').d(`Runtime installed.`));
@@ -43,7 +43,7 @@ export function preCheckEw2() {
43
43
  try {
44
44
  yield fsAccess(EW2BinPath, fs.constants.X_OK);
45
45
  if (!manifestRes.isLatest) {
46
- logger.warn(t('install_runtime_update_tip').d(`🔔 Runtime must be update to use esa dev. Installing...`));
46
+ logger.warn(t('install_runtime_update_tip').d(`🔔 Runtime must be update to use esa-cli dev. Installing...`));
47
47
  return yield installVersion(manifestRes.remoteManifest);
48
48
  }
49
49
  return true;
@@ -55,7 +55,7 @@ export function preCheckEw2() {
55
55
  return false;
56
56
  }
57
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...`));
58
+ logger.warn(t('install_runtime_tip').d(`🔔 Runtime must be installed to use esa-cli dev. Installing...`));
59
59
  return yield installVersion(manifestRes.remoteManifest);
60
60
  }
61
61
  logger.error(err.message);
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "0.0.2-beta.21",
3
+ "version": "0.0.2-beta.23",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA EdgeRoutine (Edge Functions).",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",
7
7
  "bin": {
8
- "esa": "bin/enter.cjs"
8
+ "esa": "bin/enter.cjs",
9
+ "esa-cli": "bin/enter.cjs"
9
10
  },
10
11
  "files": [
11
12
  "bin",
package/zh_CN.md CHANGED
@@ -1,176 +1,50 @@
1
- # ESA CLI
1
+ # 安装/更新 ESA CLI
2
2
 
3
- 用于操作阿里云 ESA EdgeRoutine(边缘函数) CLI,支持快速创建边缘函数、本地调试、版本发布与部署、触发器管理。
3
+ ESA CLI 是用于构建阿里云 ESA Functions Pages 的命令行工具。
4
4
 
5
- 简体中文 | [English](./README.md)
5
+ <p>
6
+ <a href="https://discord.gg/xygV6MYx">
7
+ <img alt="Discord 中文" src="https://img.shields.io/badge/Discord-中文-5865F2?logo=discord&logoColor=white" />
8
+ </a>
9
+ <a href="https://discord.gg/YeFg4yUA" style="margin-left:8px;">
10
+ <img alt="Discord English" src="https://img.shields.io/badge/Discord-English-5865F2?logo=discord&logoColor=white" />
11
+ </a>
12
+ </p>
6
13
 
7
- #### 参考
14
+ ## 安装 ESA CLI
8
15
 
9
- - [边缘安全加速(ESA)](https://www.aliyun.com/product/esa)
10
- - [边缘函数概述](https://help.aliyun.com/document_detail/2710021.html)
16
+ ### 前置条件
11
17
 
12
- > **注意**: **ESA CLI 在0.0.2以上版本的本地开发模式替换成了ESA边缘函数相同的Runtime,目前实际表现与线上相同,欢迎体验!**
13
-
14
- ESA CLI 处于公测阶段,如果您在使用中遇到任何问题,或者有任何建议,请随时提交 issue pull request。
15
- 我们正在积极改进,并欢迎任何反馈。感谢您的理解与支持!
18
+ - Node.js:18.x 或更高(支持 18.x、20.x、22.x)
19
+ - 操作系统:macOS (Apple Silicon)、Linux
20
+ - 推荐使用 Voltanvm 等 Node 版本管理工具,避免权限问题并便于切换版本
16
21
 
17
22
  ## 安装
18
23
 
19
- 使用npm安装并运行CLI命令:
20
-
21
- ```bash
22
- $ npm install esa-cli -g # 全局安装
23
- $ esa -v # 查看版本
24
- ```
25
-
26
- ## 使用指南
27
-
28
- ### 1. 初始化Routine项目
24
+ 为确保团队协作的一致性,建议在项目中将 `esa-cli` 安装为开发依赖,以便团队成员使用相同版本。
29
25
 
30
- ```bash
31
- & esa init
32
26
  ```
33
-
34
- 初始化命令有完整的流程引导,根据提示输入项目名称、选择模板即可。
35
-
36
- ### 2. 开始本地调试
37
-
38
- 本地调试功能是 CLI 的核心,提供了比阿里云 ESA 控制台更便捷的调试体验。
39
-
40
- ```bash
41
- & cd <Project Name>
42
- & esa dev [options]
27
+ npm i -D esa-cli@latest
43
28
  ```
44
29
 
45
- #### 编写代码
30
+ 当尚未安装 `esa-cli` 时,`npx` 会从注册表拉取并运行最新版本。
46
31
 
47
- 在EdgeRoutine 项目中,入口文件为 `src/index.js`,基本结构如下:
32
+ ## 查看 ESA CLI 版本
48
33
 
49
- ```javascript
50
- const html = `<!DOCTYPE html>
51
- <body>
52
- <h1>Hello World!</h1>
53
- </body>`;
54
-
55
- async function handleRequest(request) {
56
- return new Response(html, {
57
- headers: {
58
- 'content-type': 'text/html;charset=UTF-8'
59
- }
60
- });
61
- }
62
-
63
- export default {
64
- async fetch(event) {
65
- return event.respondWith(handleRequest(event));
66
- }
67
- };
68
34
  ```
69
-
70
- 更多 EdgeRoutine 的 API 与语法,请参考[API文档](https://help.aliyun.com/document_detail/2710024.html)
71
-
72
- #### 本地调试
73
-
74
- 执行 `esa dev` 后,会自动打包入口文件,并启动本地调试服务,界面样式如下:
75
-
76
- ![调试界面](https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/dev.png)
77
-
78
- - 在界面上按 `b` 即可在浏览器中打开调试页面。
79
- - 在界面上按 `c` 可以清空面板。
80
- - 在界面上按 `x` 可以退出调试。
81
- - 可以用 `esa dev --port <port>` 临时指定端口,也可以使用 `esa config -l` 按照项目配置端口。
82
-
83
- ### 3. 登录阿里云账号
84
-
85
- 需要先登录阿里云账号,才能进行远程管理操作。
86
-
87
- 首先请访问[阿里云RAM控制台](https://ram.console.aliyun.com/manage/ak)获取您的AccessKey ID和AccessKey Secret,再执行`esa login`根据提示输入。
88
-
89
- ```bash
90
- & esa login # 登录
91
- & esa logout # 登出
35
+ npx esa-cli --version
36
+ #
37
+ npx esa-cli -v
92
38
  ```
93
39
 
94
- ### 4. 生成版本
95
-
96
- 当本地调试完成后,需要生成一个代码版本用于部署。
40
+ ## 更新 ESA CLI
97
41
 
98
- ```bash
99
- & esa commit # 生成版本
100
42
  ```
101
-
102
- ### 5. 部署到环境 & 管理版本与部署
103
-
104
- 当代码版本生成后,需要部署到边缘节点。
105
-
106
- 通过`esa deployments [script]`命令可以管理版本与部署情况。
107
-
108
- ```bash
109
- & esa deploy # 根据提示选择版本、目标环境即可部署
110
- & esa deployments list # 查看部署情况
111
- & esa deployments delete <versionId> # 删除版本
112
- ```
113
-
114
- _注意:已经被部署的版本无法删除。_
115
-
116
- ### 6. 管理触发器
117
-
118
- 当被部署到节点后,您可以配置触发器,通过触发器可以访问您的边缘函数。触发器有两种:
119
-
120
- - 域名:为您的函数绑定域名,该域名必须是您ESA站点的子域名,您可以通过域名直接访问到该函数,此时边缘函数将作为该域名的源站。
121
- - 路由:为您的ESA站点绑定函数路由,访问该路由可触发边缘函数执行,此时边缘函数可以和站点的源站进行通信。
122
-
123
- ```bash
124
- # 域名
125
- & esa domain list
126
- & esa domain add <domainName> # 需要是您的已备案域名
127
- & esa domain delete <domainName>
128
-
129
- # 路由
130
- & esa route list
131
- & esa route add [route] [site]
132
- & esa route delete <route>
133
- ```
134
-
135
- ### 7. 管理函数
136
-
137
- 可以通过CLI查看、删除Routine函数。
138
-
139
- ```bash
140
- & esa routine list # 查看函数
141
- & esa routine delete <routineName> # 删除函数
142
- ```
143
-
144
- ## 命令
145
-
146
- 查看[命令](./docs/Commands.md)
147
-
148
- ## 配置文件
149
-
150
- ### 全局配置
151
-
152
- ```toml
153
- endpoint = "" # ESA API Endpoint
154
- lang = "zh_CN" # 语言
155
-
156
- [auth]
157
- accessKeyId = "" # AccessKey ID
158
- accessKeySecret = "" # AccessKey Secret
159
- ```
160
-
161
- ### 项目配置
162
-
163
- ```toml
164
- name = "Hello World" # 项目名称
165
- description = "Hello World" # 项目描述
166
- entry = "src/index.js" # 入口文件
167
- codeVersions = [ ] # 代码版本
168
-
169
- [dev]
170
- port = 18080 # 调试端口
171
- localUpstream = '' # 本地调试上游源站,会替换掉回源时当前的origin
43
+ npm i -D esa-cli@latest
172
44
  ```
173
45
 
174
- ## LICENSE
46
+ ## 相关文档
175
47
 
176
- [The MIT License](./LICENSE)
48
+ - [esa-cli 命令](./docs/Commands_zh_CN.md)
49
+ - [阿里云 ESA 文档](https://help.aliyun.com/document_detail/2710021.html)
50
+ - [Functions 和 Pages API 参考](https://help.aliyun.com/document_detail/2710024.html)