esa-cli 0.0.1-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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +175 -0
  3. package/bin/enter.cjs +52 -0
  4. package/dist/README.md +175 -0
  5. package/dist/bin/enter.cjs +52 -0
  6. package/dist/cliconfig.toml +6 -0
  7. package/dist/commands/commit/index.js +147 -0
  8. package/dist/commands/commit/prodBuild.js +50 -0
  9. package/dist/commands/common/constant.js +54 -0
  10. package/dist/commands/config.js +51 -0
  11. package/dist/commands/deploy/helper.js +108 -0
  12. package/dist/commands/deploy/index.js +217 -0
  13. package/dist/commands/deployments/delete.js +92 -0
  14. package/dist/commands/deployments/index.js +27 -0
  15. package/dist/commands/deployments/list.js +89 -0
  16. package/dist/commands/dev/config/devBuild.js +26 -0
  17. package/dist/commands/dev/config/devEntry.js +71 -0
  18. package/dist/commands/dev/config/mock/cache.js +31 -0
  19. package/dist/commands/dev/config/mock/kv.js +87 -0
  20. package/dist/commands/dev/devPack.js +113 -0
  21. package/dist/commands/dev/doProcess.js +73 -0
  22. package/dist/commands/dev/index.js +240 -0
  23. package/dist/commands/dev/server.js +100 -0
  24. package/dist/commands/domain/add.js +72 -0
  25. package/dist/commands/domain/delete.js +74 -0
  26. package/dist/commands/domain/index.js +29 -0
  27. package/dist/commands/domain/list.js +51 -0
  28. package/dist/commands/init/index.js +149 -0
  29. package/dist/commands/lang.js +32 -0
  30. package/dist/commands/login/index.js +108 -0
  31. package/dist/commands/logout.js +44 -0
  32. package/dist/commands/route/add.js +115 -0
  33. package/dist/commands/route/delete.js +74 -0
  34. package/dist/commands/route/index.js +29 -0
  35. package/dist/commands/route/list.js +63 -0
  36. package/dist/commands/routine/delete.js +54 -0
  37. package/dist/commands/routine/index.js +27 -0
  38. package/dist/commands/routine/list.js +101 -0
  39. package/dist/commands/site/index.js +25 -0
  40. package/dist/commands/site/list.js +47 -0
  41. package/dist/commands/utils.js +139 -0
  42. package/dist/components/descriptionInput.js +38 -0
  43. package/dist/components/filterSelector.js +132 -0
  44. package/dist/components/mutiSelectTable.js +95 -0
  45. package/dist/components/selectInput.js +17 -0
  46. package/dist/components/selectItem.js +6 -0
  47. package/dist/components/yesNoPrompt.js +9 -0
  48. package/dist/docs/Commands_en.md +224 -0
  49. package/dist/docs/Commands_zh_CN.md +224 -0
  50. package/dist/docs/dev.png +0 -0
  51. package/dist/i18n/index.js +27 -0
  52. package/dist/i18n/locales.json +766 -0
  53. package/dist/index.js +80 -0
  54. package/dist/libs/apiService.js +914 -0
  55. package/dist/libs/git/index.js +52 -0
  56. package/dist/libs/interface.js +21 -0
  57. package/dist/libs/logger.js +149 -0
  58. package/dist/libs/request.js +98 -0
  59. package/dist/libs/templates/index.js +16 -0
  60. package/dist/package.json +93 -0
  61. package/dist/utils/checkDevPort.js +113 -0
  62. package/dist/utils/checkIsRoutineCreated.js +56 -0
  63. package/dist/utils/checkVersion.js +26 -0
  64. package/dist/utils/debounce.js +18 -0
  65. package/dist/utils/fileUtils/index.js +219 -0
  66. package/dist/utils/fileUtils/interface.js +1 -0
  67. package/dist/utils/install/install.ps1 +33 -0
  68. package/dist/utils/install/install.sh +53 -0
  69. package/dist/utils/installRuntime.js +80 -0
  70. package/dist/utils/openInBrowser.js +24 -0
  71. package/dist/utils/sleep.js +6 -0
  72. package/dist/zh_CN.md +177 -0
  73. package/package.json +93 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Alibaba Cloud
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,175 @@
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](./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)
package/bin/enter.cjs ADDED
@@ -0,0 +1,52 @@
1
+ #! /usr/bin/env node
2
+ const fs = require('fs');
3
+ const spawn = require('cross-spawn');
4
+ const path = require('path');
5
+
6
+ const main = () => {
7
+ let entryPath;
8
+ if (fs.existsSync(path.join(__dirname, '../dist/index.js'))) {
9
+ entryPath = path.join(__dirname, '../dist/index.js');
10
+ } else if (fs.existsSync(path.join(__dirname, '../index.js'))) {
11
+ entryPath = path.join(__dirname, '../index.js');
12
+ } else {
13
+ throw new Error('Neither dist/index.js nor index.js could be found.');
14
+ }
15
+
16
+ return spawn(
17
+ process.execPath,
18
+ ['--no-warnings', ...process.execArgv, entryPath, ...process.argv.slice(2)],
19
+ {
20
+ stdio: [0, 1, 2, 'ipc'],
21
+ env: {
22
+ ...process.env
23
+ }
24
+ }
25
+ )
26
+ .on('error', (err) => {
27
+ console.log('Get Error', err);
28
+ })
29
+ .on('message', (msg) => {
30
+ // console.log('Get Message', msg);
31
+ process.send && process.send(msg);
32
+ })
33
+ .on('disconnect', () => {
34
+ // console.log('Get disconnect');
35
+ process.disconnect && process.disconnect();
36
+ })
37
+ .on('exit', (code) => {
38
+ // console.log('Get exit', code);
39
+ process.exit && process.exit(code);
40
+ });
41
+ };
42
+
43
+ if (require.main === module) {
44
+ const cliProcess = main();
45
+ // Normal
46
+ process.on('SIGINT', () => {
47
+ cliProcess && cliProcess.kill();
48
+ });
49
+ process.on('SIGTERM', () => {
50
+ cliProcess && cliProcess.kill();
51
+ });
52
+ }
package/dist/README.md ADDED
@@ -0,0 +1,175 @@
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](./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)
@@ -0,0 +1,52 @@
1
+ #! /usr/bin/env node
2
+ const fs = require('fs');
3
+ const spawn = require('cross-spawn');
4
+ const path = require('path');
5
+
6
+ const main = () => {
7
+ let entryPath;
8
+ if (fs.existsSync(path.join(__dirname, '../dist/index.js'))) {
9
+ entryPath = path.join(__dirname, '../dist/index.js');
10
+ } else if (fs.existsSync(path.join(__dirname, '../index.js'))) {
11
+ entryPath = path.join(__dirname, '../index.js');
12
+ } else {
13
+ throw new Error('Neither dist/index.js nor index.js could be found.');
14
+ }
15
+
16
+ return spawn(
17
+ process.execPath,
18
+ ['--no-warnings', ...process.execArgv, entryPath, ...process.argv.slice(2)],
19
+ {
20
+ stdio: [0, 1, 2, 'ipc'],
21
+ env: {
22
+ ...process.env
23
+ }
24
+ }
25
+ )
26
+ .on('error', (err) => {
27
+ console.log('Get Error', err);
28
+ })
29
+ .on('message', (msg) => {
30
+ // console.log('Get Message', msg);
31
+ process.send && process.send(msg);
32
+ })
33
+ .on('disconnect', () => {
34
+ // console.log('Get disconnect');
35
+ process.disconnect && process.disconnect();
36
+ })
37
+ .on('exit', (code) => {
38
+ // console.log('Get exit', code);
39
+ process.exit && process.exit(code);
40
+ });
41
+ };
42
+
43
+ if (require.main === module) {
44
+ const cliProcess = main();
45
+ // Normal
46
+ process.on('SIGINT', () => {
47
+ cliProcess && cliProcess.kill();
48
+ });
49
+ process.on('SIGTERM', () => {
50
+ cliProcess && cliProcess.kill();
51
+ });
52
+ }
@@ -0,0 +1,6 @@
1
+ endpoint = "esa.cn-hangzhou.aliyuncs.com"
2
+ lang = "en"
3
+
4
+ [auth]
5
+ accessKeyId = ""
6
+ accessKeySecret = ""
@@ -0,0 +1,147 @@
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 { getProjectConfig, readEdgeRoutineFile } from '../../utils/fileUtils/index.js';
11
+ import { checkDirectory, checkIsLoginSuccess } from '../utils.js';
12
+ import { displaySelectSpec } from '../deploy/index.js';
13
+ import { descriptionInput } from '../../components/descriptionInput.js';
14
+ import { ApiService } from '../../libs/apiService.js';
15
+ import prodBuild from './prodBuild.js';
16
+ import logger from '../../libs/logger.js';
17
+ import t from '../../i18n/index.js';
18
+ import { exit } from 'process';
19
+ const commit = {
20
+ command: 'commit [entry]',
21
+ describe: `📥 ${t('commit_describe').d('Commit your code, save as a new version')}`,
22
+ builder: (yargs) => {
23
+ return yargs
24
+ .option('minify', {
25
+ alias: 'm',
26
+ describe: t('commit_option_minify').d('Minify code before committing'),
27
+ type: 'boolean',
28
+ default: false
29
+ })
30
+ .positional('entry', {
31
+ describe: t('dev_entry_describe').d('Entry file of the Routine'),
32
+ type: 'string',
33
+ demandOption: false
34
+ });
35
+ },
36
+ handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
37
+ handleCommit(argv);
38
+ })
39
+ };
40
+ export default commit;
41
+ export function handleCommit(argv) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ var _a, _b;
44
+ if (!checkDirectory())
45
+ return;
46
+ const projectConfig = getProjectConfig();
47
+ if (!projectConfig)
48
+ return logger.notInProject();
49
+ if (!(yield checkIsLoginSuccess()))
50
+ return;
51
+ yield prodBuild(!!argv.minify, argv === null || argv === void 0 ? void 0 : argv.entry);
52
+ try {
53
+ const server = yield ApiService.getInstance();
54
+ const req = { Name: projectConfig.name };
55
+ const response = yield server.getRoutine(req, false);
56
+ let specName = (_a = response === null || response === void 0 ? void 0 : response.data.Envs[0].SpecName) !== null && _a !== void 0 ? _a : '50ms';
57
+ let action = 'Creating';
58
+ let description;
59
+ if (!response) {
60
+ logger.log(`🙅 ${t('commit_er_not_exist').d('No routine found, creating a new one')}`);
61
+ description = yield descriptionInput(`🖊️ ${t('commit_er_description').d('Enter a description for the routine')}:`, false);
62
+ const specList = yield server.listRoutineSpecs();
63
+ specName = yield displaySelectSpec((_b = specList === null || specList === void 0 ? void 0 : specList.data.Specs) !== null && _b !== void 0 ? _b : []);
64
+ }
65
+ else {
66
+ logger.log(`🔄 ${t('commit_er_exist').d('Routine exists, updating the code')}`);
67
+ description = yield descriptionInput(`🖊️ ${t('commit_version_description').d('Enter a description for the version')}:`, false);
68
+ action = 'Updating';
69
+ }
70
+ const code = readEdgeRoutineFile() || '';
71
+ const edgeRoutine = {
72
+ name: projectConfig.name,
73
+ code,
74
+ description,
75
+ specName
76
+ };
77
+ if (action === 'Creating') {
78
+ yield createEdgeRoutine(edgeRoutine);
79
+ }
80
+ else {
81
+ if (!(yield uploadEdgeRoutineCode(edgeRoutine)))
82
+ return;
83
+ yield releaseOfficialVersion(edgeRoutine);
84
+ }
85
+ exit(0);
86
+ }
87
+ catch (error) {
88
+ logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
89
+ }
90
+ });
91
+ }
92
+ export function createEdgeRoutine(edgeRoutine) {
93
+ return __awaiter(this, void 0, void 0, function* () {
94
+ try {
95
+ const server = yield ApiService.getInstance();
96
+ const res = yield server.createRoutine(edgeRoutine);
97
+ const createResult = (res === null || res === void 0 ? void 0 : res.data.Status) === 'OK';
98
+ if (!createResult) {
99
+ logger.error(t('commit_create_er_fail').d('An error occurred while trying to create a routine'));
100
+ return false;
101
+ }
102
+ logger.success(t('commit_create_er_success').d('Routine created successfully.'));
103
+ return yield uploadEdgeRoutineCode(edgeRoutine);
104
+ }
105
+ catch (error) {
106
+ logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
107
+ return false;
108
+ }
109
+ });
110
+ }
111
+ export function uploadEdgeRoutineCode(edgeRoutine) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ try {
114
+ const server = yield ApiService.getInstance();
115
+ const uploadResult = yield server.getRoutineStagingCodeUploadInfo(edgeRoutine);
116
+ if (!uploadResult) {
117
+ logger.error(t('commit_upload_fail').d('An error occurred while trying to upload your code'));
118
+ return false;
119
+ }
120
+ logger.success(t('commit_upload_success').d('Code uploaded successfully.'));
121
+ return true;
122
+ }
123
+ catch (error) {
124
+ logger.error(`${t('common_error_occurred').d('An error occurred:')} ${error}`);
125
+ return false;
126
+ }
127
+ });
128
+ }
129
+ export function releaseOfficialVersion(edgeRoutine) {
130
+ return __awaiter(this, void 0, void 0, function* () {
131
+ var _a;
132
+ const param = {
133
+ Name: edgeRoutine.name,
134
+ CodeDescription: (_a = edgeRoutine.description) !== null && _a !== void 0 ? _a : ''
135
+ };
136
+ const server = yield ApiService.getInstance();
137
+ const commitResult = yield server.commitRoutineStagingCode(param);
138
+ if (commitResult) {
139
+ logger.success(t('commit_success').d('Code version committed successfully.'));
140
+ return true;
141
+ }
142
+ else {
143
+ logger.error(t('commit_fail').d('An error occurred while trying to commit your code.'));
144
+ return false;
145
+ }
146
+ });
147
+ }
@@ -0,0 +1,50 @@
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 esbuild from 'esbuild';
11
+ import { lessLoader } from 'esbuild-plugin-less';
12
+ import path from 'path';
13
+ import fs from 'fs';
14
+ import { getRoot } from '../../utils/fileUtils/index.js';
15
+ import { NODE_EXTERNALS } from '../common/constant.js';
16
+ const userRoot = getRoot();
17
+ const entry = path.resolve(userRoot, 'src/index.js');
18
+ const outfile = path.resolve(userRoot, '.dev/pub.js');
19
+ export default function () {
20
+ return __awaiter(this, arguments, void 0, function* (minify = false, customEntry, outputPath) {
21
+ const entryPoint = customEntry
22
+ ? path.isAbsolute(customEntry)
23
+ ? customEntry
24
+ : path.resolve(userRoot, customEntry)
25
+ : entry;
26
+ const outfile = path.resolve(outputPath !== null && outputPath !== void 0 ? outputPath : userRoot, '.dev/pub.js');
27
+ const res = yield esbuild.build({
28
+ entryPoints: [entryPoint],
29
+ outfile: outfile,
30
+ bundle: true,
31
+ // minifyWhitespace: true,
32
+ // minifyIdentifiers: true,
33
+ // minifySyntax: false,
34
+ minify,
35
+ splitting: false,
36
+ format: 'esm',
37
+ platform: 'browser',
38
+ external: NODE_EXTERNALS,
39
+ // @ts-ignore
40
+ plugins: [lessLoader()],
41
+ loader: {
42
+ '.client.js': 'text'
43
+ }
44
+ });
45
+ let contents = fs.readFileSync(outfile, 'utf-8');
46
+ contents = contents.replace(/\/\*![\s\S]*?\*\//g, '');
47
+ fs.writeFileSync(outfile, contents);
48
+ return res;
49
+ });
50
+ }