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.
- package/README.md +31 -149
- package/dist/commands/commit/index.js +7 -2
- package/dist/commands/common/constant.js +4 -4
- package/dist/commands/common/utils.js +89 -89
- package/dist/commands/config.js +1 -1
- package/dist/commands/deploy/index.js +3 -2
- package/dist/commands/deployments/delete.js +2 -2
- package/dist/commands/deployments/index.js +1 -1
- package/dist/commands/dev/ew2/devPack.js +9 -9
- package/dist/commands/dev/ew2/kvService.js +5 -1
- package/dist/commands/dev/ew2/mock/kv.js +1 -1
- package/dist/commands/dev/ew2/server.js +1 -2
- package/dist/commands/dev/index.js +3 -3
- package/dist/commands/dev/mockWorker/devPack.js +3 -3
- package/dist/commands/domain/add.js +2 -2
- package/dist/commands/domain/index.js +2 -2
- package/dist/commands/init/helper.js +7 -9
- package/dist/commands/init/template.jsonc +1 -1
- package/dist/commands/route/add.js +19 -52
- package/dist/commands/route/helper.js +9 -10
- package/dist/commands/route/index.js +2 -2
- package/dist/commands/routine/delete.js +7 -6
- package/dist/commands/routine/index.js +4 -3
- package/dist/commands/routine/list.js +40 -22
- package/dist/commands/site/index.js +1 -1
- package/dist/commands/utils.js +5 -5
- package/dist/components/filterSelector.js +1 -1
- package/dist/components/routeBuilder.js +68 -0
- package/dist/docs/Commands_en.md +110 -74
- package/dist/docs/Commands_zh_CN.md +110 -74
- package/dist/i18n/locales.json +94 -58
- package/dist/index.js +2 -2
- package/dist/libs/apiService.js +7 -6
- package/dist/libs/logger.js +7 -7
- package/dist/utils/checkDevPort.js +2 -2
- package/dist/utils/checkIsRoutineCreated.js +2 -2
- package/dist/utils/compress.js +5 -5
- package/dist/utils/download.js +3 -3
- package/dist/utils/fileUtils/index.js +69 -18
- package/dist/utils/installDeno.js +1 -1
- package/dist/utils/installEw2.js +2 -2
- package/package.json +3 -2
- package/zh_CN.md +28 -154
package/README.md
CHANGED
|
@@ -1,173 +1,55 @@
|
|
|
1
|
-
# ESA CLI
|
|
1
|
+
# Install/Update ESA CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ESA CLI is a command-line tool for building with Alibaba Cloud ESA Functions and Pages.
|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
|
|
14
|
+
## Install ESA CLI
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
- [What is EdgeRoutine?](https://help.aliyun.com/document_detail/2710021.html)
|
|
16
|
+
### Prerequisites
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
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
|
-
|
|
22
|
-
$ esa -v # Check the version
|
|
27
|
+
npm i -D esa-cli@latest
|
|
23
28
|
```
|
|
24
29
|
|
|
25
|
-
|
|
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
|
-
|
|
30
|
-
& esa init
|
|
31
|
-
```
|
|
33
|
+
## Check your ESA CLI version
|
|
32
34
|
|
|
33
|
-
|
|
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
|
-
|
|
41
|
-
|
|
38
|
+
npx esa-cli --version
|
|
39
|
+
# or
|
|
40
|
+
npx esa-cli -v
|
|
42
41
|
```
|
|
43
42
|
|
|
44
|
-
|
|
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
|
-

|
|
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
|
-
|
|
45
|
+
**To update ESA CLI to the latest version, run:**
|
|
106
46
|
|
|
107
47
|
```bash
|
|
108
|
-
|
|
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
|
-
##
|
|
51
|
+
## Related Documentation
|
|
172
52
|
|
|
173
|
-
[
|
|
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
|
|
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('
|
|
40
|
+
describe: t('commit_option_name').d('Functions& Pages name'),
|
|
41
41
|
type: 'string'
|
|
42
42
|
});
|
|
43
43
|
},
|
|
@@ -69,6 +69,11 @@ export function handleCommit(argv) {
|
|
|
69
69
|
}
|
|
70
70
|
logger.startSubStep('Generating code version');
|
|
71
71
|
const res = yield generateCodeVersion(projectName, description, argv === null || argv === void 0 ? void 0 : argv.entry, argv === null || argv === void 0 ? void 0 : argv.assets, argv === null || argv === void 0 ? void 0 : argv.minify);
|
|
72
|
+
const { isSuccess } = res || {};
|
|
73
|
+
if (!isSuccess) {
|
|
74
|
+
logger.endSubStep('Generate version failed');
|
|
75
|
+
exit(1);
|
|
76
|
+
}
|
|
72
77
|
const codeVersion = (_b = (_a = res === null || res === void 0 ? void 0 : res.res) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.CodeVersion;
|
|
73
78
|
if (!codeVersion) {
|
|
74
79
|
logger.endSubStep('Missing CodeVersion in response');
|
|
@@ -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
|
|
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
|
};
|
|
@@ -61,6 +61,9 @@ export function commitRoutineWithAssets(requestParams, zipBuffer) {
|
|
|
61
61
|
if (uploadSuccess) {
|
|
62
62
|
break;
|
|
63
63
|
}
|
|
64
|
+
if (i < 2) {
|
|
65
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
66
|
+
}
|
|
64
67
|
}
|
|
65
68
|
return {
|
|
66
69
|
isSuccess: uploadSuccess,
|
|
@@ -120,100 +123,97 @@ export function generateCodeVersion(projectName_1, description_1, entry_1, asset
|
|
|
120
123
|
return __awaiter(this, arguments, void 0, function* (projectName, description, entry, assets, minify = false, projectPath) {
|
|
121
124
|
var _a;
|
|
122
125
|
const { zip, sourceList, dynamicSources } = yield compress(entry, assets, minify, projectPath);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
node.children.set(part, { children: new Map(), isFile: false });
|
|
135
|
-
}
|
|
136
|
-
const child = node.children.get(part);
|
|
137
|
-
if (i === parts.length - 1)
|
|
138
|
-
child.isFile = true;
|
|
139
|
-
node = child;
|
|
126
|
+
// Pretty print upload directory tree
|
|
127
|
+
const buildTree = (paths, decorateTopLevel) => {
|
|
128
|
+
const root = { children: new Map(), isFile: false };
|
|
129
|
+
const sorted = [...paths].sort((a, b) => a.localeCompare(b));
|
|
130
|
+
for (const p of sorted) {
|
|
131
|
+
const parts = p.split('/').filter(Boolean);
|
|
132
|
+
let node = root;
|
|
133
|
+
for (let i = 0; i < parts.length; i++) {
|
|
134
|
+
const part = parts[i];
|
|
135
|
+
if (!node.children.has(part)) {
|
|
136
|
+
node.children.set(part, { children: new Map(), isFile: false });
|
|
140
137
|
}
|
|
138
|
+
const child = node.children.get(part);
|
|
139
|
+
if (i === parts.length - 1)
|
|
140
|
+
child.isFile = true;
|
|
141
|
+
node = child;
|
|
141
142
|
}
|
|
142
|
-
const lines = [];
|
|
143
|
-
const render = (node, prefix, depth) => {
|
|
144
|
-
const entries = [...node.children.entries()];
|
|
145
|
-
entries.forEach(([_name, _child], idx) => {
|
|
146
|
-
const isLast = idx === entries.length - 1;
|
|
147
|
-
const connector = isLast ? '└ ' : '├ ';
|
|
148
|
-
const nextPrefix = prefix + (isLast ? ' ' : '│ ');
|
|
149
|
-
const displayName = depth === 0 ? decorateTopLevel(_name) : _name;
|
|
150
|
-
lines.push(prefix + connector + displayName);
|
|
151
|
-
render(_child, nextPrefix, depth + 1);
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
render(root, '', 0);
|
|
155
|
-
return lines.length ? lines : ['-'];
|
|
156
|
-
};
|
|
157
|
-
const header = chalk.hex('#22c55e')('UPLOAD') + ' Files to be uploaded (source paths)';
|
|
158
|
-
logger.block();
|
|
159
|
-
logger.log(header);
|
|
160
|
-
const dynamicSet = new Set(dynamicSources);
|
|
161
|
-
const LIMIT = 300;
|
|
162
|
-
const staticPaths = sourceList
|
|
163
|
-
.filter((p) => !dynamicSet.has(p))
|
|
164
|
-
.sort((a, b) => a.localeCompare(b));
|
|
165
|
-
const dynamicPaths = sourceList
|
|
166
|
-
.filter((p) => dynamicSet.has(p))
|
|
167
|
-
.sort((a, b) => a.localeCompare(b));
|
|
168
|
-
let omitted = 0;
|
|
169
|
-
let shownStatic = staticPaths;
|
|
170
|
-
if (staticPaths.length > LIMIT) {
|
|
171
|
-
shownStatic = staticPaths.slice(0, LIMIT);
|
|
172
|
-
omitted = staticPaths.length - LIMIT;
|
|
173
143
|
}
|
|
174
|
-
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
stat.hasStatic = true;
|
|
186
|
-
topLevelStats.set(top, stat);
|
|
144
|
+
const lines = [];
|
|
145
|
+
const render = (node, prefix, depth) => {
|
|
146
|
+
const entries = [...node.children.entries()];
|
|
147
|
+
entries.forEach(([_name, _child], idx) => {
|
|
148
|
+
const isLast = idx === entries.length - 1;
|
|
149
|
+
const connector = isLast ? '└ ' : '├ ';
|
|
150
|
+
const nextPrefix = prefix + (isLast ? ' ' : '│ ');
|
|
151
|
+
const displayName = depth === 0 ? decorateTopLevel(_name) : _name;
|
|
152
|
+
lines.push(prefix + connector + displayName);
|
|
153
|
+
render(_child, nextPrefix, depth + 1);
|
|
154
|
+
});
|
|
187
155
|
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
156
|
+
render(root, '', 0);
|
|
157
|
+
return lines.length ? lines : ['-'];
|
|
158
|
+
};
|
|
159
|
+
const header = chalk.hex('#22c55e')('UPLOAD') + ' Files to be uploaded (source paths)';
|
|
160
|
+
logger.block();
|
|
161
|
+
logger.log(header);
|
|
162
|
+
const dynamicSet = new Set(dynamicSources);
|
|
163
|
+
const LIMIT = 300;
|
|
164
|
+
const staticPaths = sourceList
|
|
165
|
+
.filter((p) => !dynamicSet.has(p))
|
|
166
|
+
.sort((a, b) => a.localeCompare(b));
|
|
167
|
+
const dynamicPaths = sourceList
|
|
168
|
+
.filter((p) => dynamicSet.has(p))
|
|
169
|
+
.sort((a, b) => a.localeCompare(b));
|
|
170
|
+
let omitted = 0;
|
|
171
|
+
let shownStatic = staticPaths;
|
|
172
|
+
if (staticPaths.length > LIMIT) {
|
|
173
|
+
shownStatic = staticPaths.slice(0, LIMIT);
|
|
174
|
+
omitted = staticPaths.length - LIMIT;
|
|
175
|
+
}
|
|
176
|
+
// Compute top-level markers based on whether a top-level bucket contains dynamic/static files
|
|
177
|
+
const topLevelStats = new Map();
|
|
178
|
+
const addStat = (p, isDynamic) => {
|
|
179
|
+
const top = p.split('/')[0] || p;
|
|
180
|
+
const stat = topLevelStats.get(top) || {
|
|
181
|
+
hasDynamic: false,
|
|
182
|
+
hasStatic: false
|
|
204
183
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
184
|
+
if (isDynamic)
|
|
185
|
+
stat.hasDynamic = true;
|
|
186
|
+
else
|
|
187
|
+
stat.hasStatic = true;
|
|
188
|
+
topLevelStats.set(top, stat);
|
|
189
|
+
};
|
|
190
|
+
dynamicPaths.forEach((p) => addStat(p, true));
|
|
191
|
+
shownStatic.forEach((p) => addStat(p, false));
|
|
192
|
+
const dynamicMarker = chalk.bold.yellowBright(' (dynamic)');
|
|
193
|
+
const staticMarker = chalk.bold.greenBright(' (static)');
|
|
194
|
+
const decorateTopLevel = (name) => {
|
|
195
|
+
const stat = topLevelStats.get(name);
|
|
196
|
+
if (!stat)
|
|
197
|
+
return name;
|
|
198
|
+
if (stat.hasDynamic && stat.hasStatic) {
|
|
199
|
+
return `${name}${dynamicMarker}${staticMarker}`;
|
|
213
200
|
}
|
|
214
|
-
|
|
201
|
+
if (stat.hasDynamic)
|
|
202
|
+
return `${name}${dynamicMarker}`;
|
|
203
|
+
if (stat.hasStatic)
|
|
204
|
+
return `${name}${staticMarker}`;
|
|
205
|
+
return name;
|
|
206
|
+
};
|
|
207
|
+
const combined = [...dynamicPaths, ...shownStatic];
|
|
208
|
+
const treeLines = buildTree(combined, decorateTopLevel);
|
|
209
|
+
for (const line of treeLines) {
|
|
210
|
+
logger.log(line);
|
|
215
211
|
}
|
|
216
|
-
|
|
212
|
+
if (omitted > 0) {
|
|
213
|
+
const note = chalk.gray(`Only show the first ${LIMIT} static files, omitted ${omitted} files`);
|
|
214
|
+
logger.log(note);
|
|
215
|
+
}
|
|
216
|
+
logger.block();
|
|
217
217
|
const projectConfig = getProjectConfig(projectPath);
|
|
218
218
|
const notFoundStrategy = normalizeNotFoundStrategy((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.assets) === null || _a === void 0 ? void 0 : _a.notFoundStrategy);
|
|
219
219
|
logger.startSubStep('Generating code version');
|
|
@@ -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 = [
|
package/dist/commands/config.js
CHANGED
|
@@ -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
|
|
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
|
|
38
|
+
describe: t('deploy_option_name').d('Name of Functions& Pages'),
|
|
39
39
|
type: 'string'
|
|
40
40
|
})
|
|
41
41
|
.option('assets', {
|
|
@@ -75,6 +75,7 @@ export function handleDeploy(argv) {
|
|
|
75
75
|
getRoot().split(/[\\/]/).pop() ||
|
|
76
76
|
'', true, true);
|
|
77
77
|
}
|
|
78
|
+
exit(success ? 0 : 1);
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
export default deploy;
|
|
@@ -52,7 +52,7 @@ export function handleDeleteDeployments(argv) {
|
|
|
52
52
|
const isInteractive = argv.i;
|
|
53
53
|
if (isInteractive) {
|
|
54
54
|
const { allVersions, stagingVersions, productionVersions } = yield getRoutineCodeVersions(projectConfig.name);
|
|
55
|
-
//
|
|
55
|
+
// Show information about versions being deployed
|
|
56
56
|
if (stagingVersions.length > 0 || productionVersions.length > 0) {
|
|
57
57
|
logger.log(chalk.yellow('⚠️ Currently deploying versions:'));
|
|
58
58
|
if (stagingVersions.length > 0) {
|
|
@@ -64,7 +64,7 @@ export function handleDeleteDeployments(argv) {
|
|
|
64
64
|
logger.log('');
|
|
65
65
|
}
|
|
66
66
|
logger.log(t('delete_deployments_table_title').d(' Version ID Description'));
|
|
67
|
-
//
|
|
67
|
+
// Filter out versions being deployed
|
|
68
68
|
const selectList = allVersions
|
|
69
69
|
.filter((item) => {
|
|
70
70
|
var _a, _b;
|
|
@@ -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)) {
|
|
@@ -16,7 +16,7 @@ import { getRoot, getDirName } from '../../../utils/fileUtils/base.js';
|
|
|
16
16
|
import { getDevConf } from '../../../utils/fileUtils/index.js';
|
|
17
17
|
import { EW2Path } from '../../../utils/installEw2.js';
|
|
18
18
|
import devBuild from '../build.js';
|
|
19
|
-
//
|
|
19
|
+
// Generate available Ew2 port
|
|
20
20
|
const generateEw2Port = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
let ew2port = 3322;
|
|
22
22
|
let portAvailable = yield checkPort(ew2port);
|
|
@@ -60,7 +60,7 @@ conf_path = "${erConfPath}"
|
|
|
60
60
|
fs.promises.writeFile(erConfPath, erConf)
|
|
61
61
|
]);
|
|
62
62
|
};
|
|
63
|
-
//
|
|
63
|
+
// Generate entry file
|
|
64
64
|
const generateEntry = (id, projectEntry, userRoot, port) => __awaiter(void 0, void 0, void 0, function* () {
|
|
65
65
|
const __dirname = getDirName(import.meta.url);
|
|
66
66
|
const devDir = path.resolve(userRoot, '.dev');
|
|
@@ -85,20 +85,20 @@ const generateEntry = (id, projectEntry, userRoot, port) => __awaiter(void 0, vo
|
|
|
85
85
|
.replace(/'\$userPath'/g, `'${projectEntry.replace(/\\/g, '/')}'`)
|
|
86
86
|
.replace(/\$userPort/g, `${port}`));
|
|
87
87
|
});
|
|
88
|
-
//
|
|
88
|
+
// Preliminary preparation
|
|
89
89
|
const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(void 0, void 0, void 0, function* () {
|
|
90
90
|
const options = {};
|
|
91
91
|
const currentOptions = { entry, port, localUpstream };
|
|
92
|
-
//
|
|
92
|
+
// Support running multiple workers simultaneously
|
|
93
93
|
const id = new Date().getTime().toString();
|
|
94
94
|
// @ts-ignore
|
|
95
95
|
global.id = id;
|
|
96
|
-
//
|
|
96
|
+
// Generate entry file
|
|
97
97
|
yield generateEntry(id, entry, userRoot, port);
|
|
98
|
-
//
|
|
98
|
+
// Generate Ew2 configuration
|
|
99
99
|
const ew2port = yield generateEw2Port();
|
|
100
100
|
yield writeEw2config(id, ew2port, userRoot);
|
|
101
|
-
//
|
|
101
|
+
// Configuration items for each dev session, distinguished by id in one file
|
|
102
102
|
if (fs.existsSync(configPath)) {
|
|
103
103
|
const currentConfig = fs
|
|
104
104
|
.readFileSync(configPath, 'utf-8')
|
|
@@ -106,7 +106,7 @@ const prepare = (configPath, entry, port, localUpstream, userRoot) => __awaiter(
|
|
|
106
106
|
const currentConfigObj = JSON.parse(currentConfig);
|
|
107
107
|
const currentIds = Object.keys(currentConfigObj);
|
|
108
108
|
if (currentIds[0] && /^\d+$/.test(currentIds[0])) {
|
|
109
|
-
//
|
|
109
|
+
// Remove unused entries
|
|
110
110
|
for (let currentId of currentIds) {
|
|
111
111
|
const unused = yield checkPort(currentConfigObj[currentId].port);
|
|
112
112
|
if (unused) {
|
|
@@ -155,7 +155,7 @@ const devPack = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
155
155
|
}
|
|
156
156
|
else {
|
|
157
157
|
logger.notInProject();
|
|
158
|
-
process.exit(
|
|
158
|
+
process.exit(1);
|
|
159
159
|
}
|
|
160
160
|
return prepare(path.resolve(userRoot, '.dev/devConfig.js'), projectEntry, port, localUpstream, userRoot)
|
|
161
161
|
.then(() => {
|
|
@@ -11,7 +11,11 @@ class EdgeKV {
|
|
|
11
11
|
const kvJson = fs.readFileSync(kvPath, 'utf8');
|
|
12
12
|
const kvJsonObj = JSON.parse(kvJson);
|
|
13
13
|
Object.keys(kvJsonObj).forEach((namespace) => {
|
|
14
|
-
|
|
14
|
+
const childMap = new Map();
|
|
15
|
+
Object.keys(kvJsonObj[namespace]).forEach((key) => {
|
|
16
|
+
childMap.set(key, JSON.stringify(kvJsonObj[namespace][key]));
|
|
17
|
+
});
|
|
18
|
+
EdgeKV.store.set(namespace, childMap);
|
|
15
19
|
});
|
|
16
20
|
}
|
|
17
21
|
catch (err) {
|
|
@@ -187,7 +187,7 @@ class Ew2Server {
|
|
|
187
187
|
agent: new HttpProxyAgent(`http://127.0.0.1:${ew2Port}`)
|
|
188
188
|
});
|
|
189
189
|
const workerHeaders = Object.fromEntries(workerRes.headers.entries());
|
|
190
|
-
//
|
|
190
|
+
// Solve gzip compatibility issue, prevent net::ERR_CONTENT_DECODING_FAILED
|
|
191
191
|
workerHeaders['content-encoding'] = 'identity';
|
|
192
192
|
if (workerRes.body) {
|
|
193
193
|
res.writeHead(workerRes.status, workerHeaders);
|
|
@@ -236,7 +236,6 @@ class Ew2Server {
|
|
|
236
236
|
const key = url.searchParams.get('key');
|
|
237
237
|
const namespace = url.searchParams.get('namespace');
|
|
238
238
|
const body = yield this.parseKVBody(req);
|
|
239
|
-
console.log(body);
|
|
240
239
|
if (!key || !namespace) {
|
|
241
240
|
return {
|
|
242
241
|
success: false
|