esa-cli 0.0.2-beta.22 → 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.
package/README.md CHANGED
@@ -1,173 +1,55 @@
1
- # ESA CLI
1
+ # Install/Update ESA CLI
2
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.
3
+ ESA CLI is a command-line tool for building with Alibaba Cloud ESA Functions and Pages.
4
4
 
5
- English | [简体中文](./zh_CN.md)
5
+ <p>
6
+ <a href="https://discord.gg/xygV6MYx">
7
+ <img alt="Discord CN" 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 EN" src="https://img.shields.io/badge/Discord-English-5865F2?logo=discord&logoColor=white" />
11
+ </a>
12
+ </p>
6
13
 
7
- #### Reference
14
+ ## Install ESA CLI
8
15
 
9
- - [Edge Security Acceleration (ESA)](https://www.aliyun.com/product/esa)
10
- - [What is EdgeRoutine?](https://help.aliyun.com/document_detail/2710021.html)
16
+ ### Prerequisites
11
17
 
12
- > **Note**: **In version 0.0.2 and above, the local development mode of the ESA CLI has been replaced with the same runtime as the ESA edge functions, ensuring that its actual behavior now matches the live environment. We invite you to experience it.**
13
-
14
- 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.We are actively working to improve this tool and welcome any feedback. Thank you for your understanding and support!
18
+ - Node.js: 18.x or higher (supports 18.x, 20.x, 22.x)
19
+ - OS: macOS (x86, Apple Silicon), Linux
20
+ - Recommended to use a Node version manager like Volta or nvm to avoid permission issues and easily switch Node.js versions.
15
21
 
16
22
  ## Installation
17
23
 
18
- Install and run the CLI using npm:
24
+ To ensure consistent collaboration across your team, we recommend installing `esa-cli` as a dev dependency in your project. This helps everyone use the same version.
19
25
 
20
26
  ```bash
21
- $ npm install esa-cli -g # Install globally
22
- $ esa -v # Check the version
27
+ npm i -D esa-cli@latest
23
28
  ```
24
29
 
25
- ## Usage
26
-
27
- ### 1. Initialize Routine Project
30
+ > [!TIP]
31
+ > When `esa-cli` is not previously installed, `npx` will fetch and run the latest version from the registry.
28
32
 
29
- ```bash
30
- & esa init
31
- ```
33
+ ## Check your ESA CLI version
32
34
 
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.
35
+ **To check your ESA CLI version, run:**
38
36
 
39
37
  ```bash
40
- & cd <Project Name>
41
- & esa dev [options]
38
+ npx esa-cli --version
39
+ # or
40
+ npx esa-cli -v
42
41
  ```
43
42
 
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 `c` to clear the panel.
79
- - Press `x` to exit debugging.
80
- - You can use `esa dev --port <port>` to temporarily specify the port or use `esa config -l` to set the port by project configuration.
81
-
82
- ### 3. Log in to Alibaba Cloud Account
83
-
84
- You need to log in to your Alibaba Cloud account to perform remote management operations.
85
-
86
- 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.
87
-
88
- ```bash
89
- & esa login
90
- & esa logout
91
- ```
92
-
93
- ### 4. Create a Version
94
-
95
- After local debugging is complete, you need to create a code version for deployment.
96
-
97
- ```bash
98
- & esa commit # Create a Version
99
- ```
100
-
101
- ### 5. Deploy to Environment & Manage Versions and Deployments
102
-
103
- After the code version is created, it needs to be deployed to edge nodes.
43
+ ## Update ESA CLI
104
44
 
105
- Use the `esa deployments [script]` command to manage versions and deployments.
45
+ **To update ESA CLI to the latest version, run:**
106
46
 
107
47
  ```bash
108
- & esa deploy # Deploy versions to the target environment
109
- & esa deployments list # View deployments
110
- & esa deployments delete <versionId> # Delete a version
111
- ```
112
-
113
- _Note: Deployed versions cannot be deleted._
114
-
115
- ### 6. Manage Triggers
116
-
117
- Once deployed to the nodes, you can configure triggers to access your edge functions. There are two types of triggers:
118
-
119
- - Domain: After you associate the routine with a domain name, you can use the domain name to access the routine.
120
- - Route: After you add a route for requested URLs, the routine is called from the edge to respond to the request.
121
-
122
- ```bash
123
- & esa domain list
124
- & esa domain add <domainName>
125
- & esa domain delete <domainName>
126
-
127
- & esa route list
128
- & esa route add [route] [site]
129
- & esa route delete <route>
130
- ```
131
-
132
- ### 7. Manage Functions
133
-
134
- You can view and delete Routine functions through the CLI.
135
-
136
- ```bash
137
- & esa routine list
138
- & esa routine delete <routineName>
139
- ```
140
-
141
- ## Commands
142
-
143
- see [Commands](./docs/Commands_en.md)
144
-
145
- ## Config files
146
-
147
- ### Global config file
148
-
149
- ```toml
150
- endpoint = "" # ESA API Endpoint
151
- lang = "zh_CN" # language
152
-
153
- [auth]
154
- accessKeyId = "" # AccessKey ID
155
- accessKeySecret = "" # AccessKey Secret
156
- ```
157
-
158
- ### Project config file
159
-
160
- ```toml
161
- name = "Hello World" # Project name
162
- description = "Hello World" # Project description
163
- entry = "src/index.js" # Entry file
164
- codeVersions = [ ] # Code version
165
-
166
- [dev]
167
- port = 18080 # Debug port
168
- localUpstream = '' # When debugging locally, the upstream source site will replace the current origin when returning to the source
48
+ npm i -D esa-cli@latest
169
49
  ```
170
50
 
171
- ## LICENSE
51
+ ## Related Documentation
172
52
 
173
- [The MIT License](./LICENSE)
53
+ - [esa-cli command](./docs/Commands_en.md)
54
+ - [Alibaba Cloud ESA Documentation](https://www.alibabacloud.com/help/en/edge-security-acceleration/esa/user-guide/what-is-er/)
55
+ - [Functions and Pages API Reference](https://www.alibabacloud.com/help/en/edge-security-acceleration/esa/user-guide/api-documentation/)
@@ -32,12 +32,12 @@ const commit = {
32
32
  })
33
33
  .option('description', {
34
34
  alias: 'd',
35
- describe: t('commit_option_description').d('Description for the routine/version (skip interactive input)'),
35
+ describe: t('commit_option_description').d('Description for Functions& Pages/version (skip interactive input)'),
36
36
  type: 'string'
37
37
  })
38
38
  .option('name', {
39
39
  alias: 'n',
40
- describe: t('commit_option_name').d('Edge Routine name'),
40
+ describe: t('commit_option_name').d('Functions& Pages name'),
41
41
  type: 'string'
42
42
  });
43
43
  },
@@ -2,21 +2,21 @@ import t from '../../i18n/index.js';
2
2
  export const getSummary = (routineName) => {
3
3
  return [
4
4
  {
5
- title: t('summery_cd').d('Enter your routine project folder'),
5
+ title: t('summery_cd').d('Enter your project folder'),
6
6
  command: `💡 cd ${routineName}`
7
7
  },
8
8
  {
9
9
  title: t('summery_dev').d('Start a local development server for your project'),
10
- command: '💡 esa dev'
10
+ command: '💡 esa-cli dev'
11
11
  },
12
12
  {
13
13
  title: t('summery_commit').d('Save a new version of code'),
14
- command: '💡 esa commit'
14
+ command: '💡 esa-cli commit'
15
15
  },
16
16
  // Use Deploy or Release?
17
17
  {
18
18
  title: t('summery_deploy').d('Deploy your project to different environments'),
19
- command: '💡 esa deploy'
19
+ command: '💡 esa-cli deploy'
20
20
  }
21
21
  ];
22
22
  };
@@ -379,10 +379,10 @@ export function displayDeploySuccess(projectName_1) {
379
379
  : '';
380
380
  const guides = [];
381
381
  if (showDomainGuide) {
382
- guides.push(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa domain add <DOMAIN>')}`);
382
+ guides.push(`${label('TIP')} ${t('deploy_success_guide').d('Add a custom domain')}: ${chalk.green('esa-cli domain add <DOMAIN>')}`);
383
383
  }
384
384
  if (showRouteGuide) {
385
- guides.push(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa route add -r <ROUTE> -s <SITE>')}`);
385
+ guides.push(`${label('TIP')} ${t('deploy_success_guide_2').d('Add routes for a site')}: ${chalk.green('esa-cli route add -r <ROUTE> -s <SITE>')}`);
386
386
  }
387
387
  const tip = `${subtle(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'))}`;
388
388
  const lines = [
@@ -26,7 +26,7 @@ const check = {
26
26
  type: 'boolean',
27
27
  default: false
28
28
  })
29
- .usage(`${t('common_usage').d('Usage')}: esa config [-l | -g]`)
29
+ .usage(`${t('common_usage').d('Usage')}: esa-cli config [-l | -g]`)
30
30
  .check((argv) => {
31
31
  if (!argv.local && !argv.global) {
32
32
  yargs.showHelp();
@@ -18,7 +18,7 @@ const deploy = {
18
18
  builder: (yargs) => {
19
19
  return yargs
20
20
  .positional('entry', {
21
- describe: t('dev_entry_describe').d('Entry file of the Routine'),
21
+ describe: t('dev_entry_describe').d('Entry file of Functions& Pages'),
22
22
  type: 'string',
23
23
  demandOption: false
24
24
  })
@@ -35,7 +35,7 @@ const deploy = {
35
35
  })
36
36
  .option('name', {
37
37
  alias: 'n',
38
- describe: t('deploy_option_name').d('Name of the routine'),
38
+ describe: t('deploy_option_name').d('Name of Functions& Pages'),
39
39
  type: 'string'
40
40
  })
41
41
  .option('assets', {
@@ -16,7 +16,7 @@ const deploymentsCommand = {
16
16
  type: 'boolean',
17
17
  default: false
18
18
  })
19
- .usage(`${t('common_usage').d('Usage')}: esa deployments [list | delete]`);
19
+ .usage(`${t('common_usage').d('Usage')}: esa-cli deployments [list | delete]`);
20
20
  },
21
21
  handler: (argv) => {
22
22
  if (yargsIns && (argv.help || argv._.length < 2)) {
@@ -10,7 +10,6 @@ class EdgeKV {
10
10
  try {
11
11
  const kvJson = fs.readFileSync(kvPath, 'utf8');
12
12
  const kvJsonObj = JSON.parse(kvJson);
13
- console.log(kvJsonObj);
14
13
  Object.keys(kvJsonObj).forEach((namespace) => {
15
14
  const childMap = new Map();
16
15
  Object.keys(kvJsonObj[namespace]).forEach((key) => {
@@ -18,7 +17,6 @@ class EdgeKV {
18
17
  });
19
18
  EdgeKV.store.set(namespace, childMap);
20
19
  });
21
- console.log(EdgeKV.store);
22
20
  }
23
21
  catch (err) {
24
22
  console.log(t('kv_parse_failed').d('kv.json parse failed, use empty local kv store.'));
@@ -31,11 +31,11 @@ const EW2OS = [Platforms.AppleArm, Platforms.AppleIntel, Platforms.LinuxX86];
31
31
  const useEw2 = EW2OS.includes(OS);
32
32
  const dev = {
33
33
  command: 'dev [entry]',
34
- describe: `💻 ${t('dev_describe').d('Start a local server for developing your routine')}`,
34
+ describe: `💻 ${t('dev_describe').d('Start a local server for developing your project')}`,
35
35
  builder: (yargs) => {
36
36
  yargsIns = yargs
37
37
  .positional('entry', {
38
- describe: t('dev_entry_describe').d('Entry file of the Routine'),
38
+ describe: t('dev_entry_describe').d('Entry file of Functions& Pages'),
39
39
  type: 'string',
40
40
  demandOption: false
41
41
  })
@@ -14,7 +14,7 @@ import { getProjectConfig } from '../../utils/fileUtils/index.js';
14
14
  import { bindRoutineWithDomain, checkDirectory, checkIsLoginSuccess, validDomain, validName } from '../utils.js';
15
15
  const addDomain = {
16
16
  command: 'add <domain>',
17
- describe: `🔗 ${t('domain_add_describe').d('Bind a domain to a routine')}`,
17
+ describe: `🔗 ${t('domain_add_describe').d('Bind a domain to your project')}`,
18
18
  builder: (yargs) => {
19
19
  return yargs
20
20
  .positional('domain', {
@@ -22,7 +22,7 @@ const addDomain = {
22
22
  type: 'string',
23
23
  demandOption: true
24
24
  })
25
- .usage(`${t('common_usage').d('Usage')}: esa domain add <domain>`)
25
+ .usage(`${t('common_usage').d('Usage')}: esa-cli domain add <domain>`)
26
26
  .option('help', {
27
27
  alias: 'h',
28
28
  describe: t('common_help').d('Help'),
@@ -5,7 +5,7 @@ import listDomain from './list.js';
5
5
  let yargsIns;
6
6
  const domainCommand = {
7
7
  command: 'domain [script]',
8
- describe: `🔗 ${t('domain_describe').d('Manage the domain names bound to your routine')}`,
8
+ describe: `🔗 ${t('domain_describe').d('Manage the domain names bound to your project')}`,
9
9
  builder: (yargs) => {
10
10
  yargsIns = yargs;
11
11
  return yargs
@@ -18,7 +18,7 @@ const domainCommand = {
18
18
  type: 'boolean',
19
19
  default: false
20
20
  })
21
- .usage(`${t('common_usage').d('Usage')}: esa domain <add | list | delete>`);
21
+ .usage(`${t('common_usage').d('Usage')}: esa-cli domain <add | list | delete>`);
22
22
  },
23
23
  handler: (argv) => {
24
24
  if (yargsIns && (argv.help || argv._.length < 2)) {
@@ -5,7 +5,7 @@ import listRoute from './list.js';
5
5
  let yargsIns;
6
6
  const routeCommand = {
7
7
  command: 'route [script]',
8
- describe: `🚄 ${t('route_describe').d('Manage the routes bound to your routine')}`,
8
+ describe: `🚄 ${t('route_describe').d('Manage the routes bound to your project')}`,
9
9
  builder: (yargs) => {
10
10
  yargsIns = yargs;
11
11
  return yargs
@@ -18,7 +18,7 @@ const routeCommand = {
18
18
  type: 'boolean',
19
19
  default: false
20
20
  })
21
- .usage(`${t('common_usage').d('Usage')}: esa route <add | list | delete>`);
21
+ .usage(`${t('common_usage').d('Usage')}: esa-cli route <add | list | delete>`);
22
22
  },
23
23
  handler: (argv) => {
24
24
  if (yargsIns && (argv.help || argv._.length < 2)) {
@@ -12,17 +12,18 @@ import { ApiService } from '../../libs/apiService.js';
12
12
  import logger from '../../libs/logger.js';
13
13
  import { checkIsLoginSuccess } from '../utils.js';
14
14
  const deleteCommand = {
15
- command: 'delete <routineName>',
16
- describe: `🗑 ${t('delete_describe').d('Delete a routine')}`,
15
+ command: 'delete <projectName>',
16
+ aliases: ['delete <routineName>'],
17
+ describe: `🗑 ${t('delete_describe').d('Delete a project')}`,
17
18
  builder: (yargs) => {
18
19
  return yargs
19
- .positional('routineName', {
20
- describe: t('delete_routineName_positional_describe').d('The name of the routine to delete'),
20
+ .positional('projectName', {
21
+ describe: t('delete_routineName_positional_describe').d('The name of the project to delete'),
21
22
  type: 'string',
22
23
  array: true,
23
24
  demandOption: true
24
25
  })
25
- .usage(`${t('common_usage').d('Usage')}: $0 delete <routineName>`);
26
+ .usage(`${t('common_usage').d('Usage')}: $0 delete <projectName>`);
26
27
  },
27
28
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
28
29
  handleDelete(argv);
@@ -34,7 +35,7 @@ export function handleDelete(argv) {
34
35
  const isSuccess = yield checkIsLoginSuccess();
35
36
  if (!isSuccess)
36
37
  return;
37
- const routineName = argv.routineName;
38
+ const routineName = argv.projectName || argv.routineName;
38
39
  const req = { Name: routineName };
39
40
  return yield deleteRoutineFromUserAccount(req);
40
41
  });
@@ -3,8 +3,9 @@ import routineDelete from './delete.js';
3
3
  import routineList from './list.js';
4
4
  let yargsIns;
5
5
  const routineCommand = {
6
- command: 'routine [script]',
7
- describe: `🧭 ${t('routine_describe').d('Manage your routine')}`,
6
+ command: 'project [script]',
7
+ aliases: ['routine'],
8
+ describe: `🧭 ${t('routine_describe').d('Manage your project')}`,
8
9
  builder: (yargs) => {
9
10
  yargsIns = yargs;
10
11
  return yargs
@@ -16,7 +17,7 @@ const routineCommand = {
16
17
  type: 'boolean',
17
18
  default: false
18
19
  })
19
- .usage(`${t('common_usage').d('Usage')}: esa routine [list | delete]`);
20
+ .usage(`${t('common_usage').d('Usage')}: esa-cli project [list | delete]`);
20
21
  },
21
22
  handler: (argv) => {
22
23
  if (yargsIns && (argv.help || argv._.length < 2)) {
@@ -16,12 +16,12 @@ import logger from '../../libs/logger.js';
16
16
  import { checkIsLoginSuccess } from '../utils.js';
17
17
  const list = {
18
18
  command: 'list',
19
- describe: `📋 ${t('list_describe').d('List all your routines')}`,
19
+ describe: `📋 ${t('list_describe').d('List all your projects')}`,
20
20
  builder: (yargs) => {
21
21
  return yargs
22
22
  .option('keyword', {
23
23
  alias: 'k',
24
- describe: t('deploy_option_keyword').d('Keyword to search for routines'),
24
+ describe: t('deploy_option_keyword').d('Keyword to search for projects'),
25
25
  type: 'string'
26
26
  })
27
27
  .usage(`${t('common_usage').d('Usage')}: \$0 list [--keyword <keyword>]`);
@@ -68,7 +68,7 @@ export function handleList(argv) {
68
68
  SearchKeyWord: argv.keyword
69
69
  });
70
70
  if (routineList) {
71
- logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of routine')}:`));
71
+ logger.log(chalk.bold.bgGray(`📃 ${t('list_routine_name_title').d('List all of Functions& Pages')}:`));
72
72
  displayRoutineList(routineList);
73
73
  }
74
74
  });
@@ -14,7 +14,7 @@ const siteCommand = {
14
14
  type: 'boolean',
15
15
  default: false
16
16
  })
17
- .usage(`${t('common_usage').d('Usage')}: esa site [list]`);
17
+ .usage(`${t('common_usage').d('Usage')}: esa-cli site [list]`);
18
18
  },
19
19
  handler: (argv) => {
20
20
  if (yargsIns && (argv.help || argv._.length < 2)) {
@@ -89,7 +89,7 @@ export function checkIsLoginSuccess() {
89
89
  if (!endpoint) {
90
90
  endpoint = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.endpoint;
91
91
  }
92
- const namedCommand = chalk.green('esa login');
92
+ const namedCommand = chalk.green('esa-cli login');
93
93
  if (!accessKeyId || !accessKeySecret) {
94
94
  logger.log(`❌ ${t('utils_login_error').d('Maybe you are not logged in yet.')}`);
95
95
  logger.log(`🔔 ${t('utils_login_error_config', { namedCommand }).d(`Please run command to login: ${namedCommand}`)}`);