esa-cli 1.0.4-beta.2 → 1.0.4-beta.4
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 +1 -1
- package/dist/commands/config.js +13 -1
- package/dist/commands/dev/build.js +1 -6
- package/dist/commands/init/helper.js +12 -12
- package/dist/commands/routine/index.js +2 -2
- package/dist/commands/utils.js +7 -0
- package/dist/docs/Commands_en.md +0 -4
- package/dist/docs/Commands_zh_CN.md +74 -59
- package/dist/i18n/locales.json +1 -1
- package/dist/index.js +9 -0
- package/dist/libs/api.js +3 -1
- package/dist/libs/apiService.js +5 -2
- package/dist/libs/constants.js +13 -0
- package/dist/utils/command.js +21 -2
- package/dist/utils/compress.js +2 -2
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ ESA CLI is a command-line tool for building with Alibaba Cloud ESA Functions and
|
|
|
15
15
|
|
|
16
16
|
### Prerequisites
|
|
17
17
|
|
|
18
|
-
- Node.js:
|
|
18
|
+
- Node.js: 20.x or higher (supports 20.x, 22.x)
|
|
19
19
|
- OS: macOS (x86, Apple Silicon), Linux
|
|
20
20
|
- Recommended to use a Node version manager like Volta or nvm to avoid permission issues and easily switch Node.js versions.
|
|
21
21
|
|
package/dist/commands/config.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
+
import os from 'os';
|
|
2
3
|
import spawn from 'cross-spawn';
|
|
3
4
|
import t from '../i18n/index.js';
|
|
4
5
|
import logger from '../libs/logger.js';
|
|
5
6
|
import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
|
|
7
|
+
const getDefaultEditor = () => {
|
|
8
|
+
// Use environment variable if set
|
|
9
|
+
if (process.env.EDITOR) {
|
|
10
|
+
return process.env.EDITOR;
|
|
11
|
+
}
|
|
12
|
+
// Platform-specific default editors
|
|
13
|
+
if (os.platform() === 'win32') {
|
|
14
|
+
return 'notepad';
|
|
15
|
+
}
|
|
16
|
+
return 'vi';
|
|
17
|
+
};
|
|
6
18
|
const editConfigFile = (configPath) => {
|
|
7
|
-
const editor =
|
|
19
|
+
const editor = getDefaultEditor();
|
|
8
20
|
spawn(editor, [configPath], {
|
|
9
21
|
stdio: 'inherit'
|
|
10
22
|
});
|
|
@@ -21,13 +21,8 @@ const renameMock = {
|
|
|
21
21
|
});
|
|
22
22
|
traverse(ast, {
|
|
23
23
|
Identifier(path) {
|
|
24
|
-
var _a;
|
|
25
24
|
const name = path.node.name;
|
|
26
|
-
if (
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (((_a = path.parentPath) === null || _a === void 0 ? void 0 : _a.type) === 'MemberExpression' &&
|
|
30
|
-
path.key === 'object') {
|
|
25
|
+
if (replacements.hasOwnProperty(name)) {
|
|
31
26
|
path.node.name = replacements[name];
|
|
32
27
|
}
|
|
33
28
|
}
|
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { execSync } from 'child_process';
|
|
11
|
+
import os from 'os';
|
|
11
12
|
import path from 'path';
|
|
12
13
|
import { exit } from 'process';
|
|
13
14
|
import { confirm as clackConfirm, isCancel, log, outro } from '@clack/prompts';
|
|
@@ -17,7 +18,7 @@ import Haikunator from 'haikunator';
|
|
|
17
18
|
import t from '../../i18n/index.js';
|
|
18
19
|
import logger from '../../libs/logger.js';
|
|
19
20
|
import Template from '../../libs/templates/index.js';
|
|
20
|
-
import { execCommand } from '../../utils/command.js';
|
|
21
|
+
import { execCommand, execWithLoginShell } from '../../utils/command.js';
|
|
21
22
|
import { getDirName } from '../../utils/fileUtils/base.js';
|
|
22
23
|
import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
|
|
23
24
|
import promptParameter from '../../utils/prompt.js';
|
|
@@ -111,9 +112,8 @@ export function checkAndUpdatePackage(packageName) {
|
|
|
111
112
|
}
|
|
112
113
|
catch (e) {
|
|
113
114
|
spinner.text = t('template_updating').d('Updating templates to latest...');
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
115
|
+
// Cross-platform: use fs-extra.removeSync instead of rm -rf
|
|
116
|
+
fs.removeSync(path.join(packageJsonPath, 'node_modules', packageName));
|
|
117
117
|
execSync(`npm install ${packageName}@latest`, {
|
|
118
118
|
cwd: packageJsonPath,
|
|
119
119
|
stdio: 'inherit'
|
|
@@ -143,12 +143,9 @@ export function checkAndUpdatePackage(packageName) {
|
|
|
143
143
|
});
|
|
144
144
|
if (!isCancel(isUpdate) && isUpdate) {
|
|
145
145
|
spinner.start(t('template_updating').d('Updating templates to latest...'));
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
execSync(`rm -rf package-lock.json`, {
|
|
150
|
-
cwd: packageJsonPath
|
|
151
|
-
});
|
|
146
|
+
// Cross-platform: use fs-extra.removeSync instead of rm -rf
|
|
147
|
+
fs.removeSync(path.join(packageJsonPath, 'node_modules', packageName));
|
|
148
|
+
fs.removeSync(path.join(packageJsonPath, 'package-lock.json'));
|
|
152
149
|
execSync(`npm install ${packageName}@latest`, {
|
|
153
150
|
cwd: packageJsonPath,
|
|
154
151
|
stdio: 'inherit'
|
|
@@ -382,7 +379,7 @@ export const createProject = (initParams) => __awaiter(void 0, void 0, void 0, f
|
|
|
382
379
|
const templateFlag = ((_a = frameworkConfig.language) === null || _a === void 0 ? void 0 : _a[initParams.language || 'typescript']) || '';
|
|
383
380
|
const extraParams = frameworkConfig.params || '';
|
|
384
381
|
const full = `${command} ${initParams.name} ${templateFlag} ${extraParams}`.trim();
|
|
385
|
-
const res = yield
|
|
382
|
+
const res = yield execWithLoginShell(full, {
|
|
386
383
|
interactive: true,
|
|
387
384
|
startText: `Starting to execute framework command ${chalk.gray(full)}`,
|
|
388
385
|
doneText: `Framework command executed ${chalk.gray(full)}`
|
|
@@ -729,6 +726,9 @@ export function initializeProject(selectedTemplatePath, name) {
|
|
|
729
726
|
}
|
|
730
727
|
const targetPath = path.join(process.cwd(), name);
|
|
731
728
|
if (fs.existsSync(targetPath)) {
|
|
729
|
+
// Cross-platform delete command hint
|
|
730
|
+
const isWindows = os.platform() === 'win32';
|
|
731
|
+
const deleteCmd = isWindows ? `rmdir /s /q "${name}"` : `rm -rf "${name}"`;
|
|
732
732
|
logger.block();
|
|
733
733
|
logger.tree([
|
|
734
734
|
`${chalk.bgRed(' ERROR ')} ${chalk.bold.red(t('init_abort').d('Initialization aborted'))}`,
|
|
@@ -736,7 +736,7 @@ export function initializeProject(selectedTemplatePath, name) {
|
|
|
736
736
|
`${chalk.gray(t('path').d('Path:'))} ${chalk.cyan(targetPath)}`,
|
|
737
737
|
chalk.gray(t('try').d('Try one of the following:')),
|
|
738
738
|
`- ${chalk.white(t('try_diff_name').d('Choose a different project name'))}`,
|
|
739
|
-
`- ${chalk.white(t('try_remove').d('Remove the directory:'))} ${chalk.yellow(
|
|
739
|
+
`- ${chalk.white(t('try_remove').d('Remove the directory:'))} ${chalk.yellow(deleteCmd)}`,
|
|
740
740
|
`- ${chalk.white(t('try_another_dir').d('Run the command in another directory'))}`
|
|
741
741
|
]);
|
|
742
742
|
logger.block();
|
|
@@ -4,8 +4,8 @@ import routineList from './list.js';
|
|
|
4
4
|
let yargsIns;
|
|
5
5
|
const routineCommand = {
|
|
6
6
|
command: 'project [script]',
|
|
7
|
-
aliases: ['
|
|
8
|
-
describe: `🧭 ${t('routine_describe').d('Manage your project')}`,
|
|
7
|
+
aliases: ['Functions & Pages'],
|
|
8
|
+
describe: `🧭 ${t('routine_describe').d('Manage your Functions & Pages project')}`,
|
|
9
9
|
builder: (yargs) => {
|
|
10
10
|
yargsIns = yargs;
|
|
11
11
|
return yargs
|
package/dist/commands/utils.js
CHANGED
package/dist/docs/Commands_en.md
CHANGED
|
@@ -345,15 +345,11 @@ AccessKey ID (AK)
|
|
|
345
345
|
**--access-key-secret, --sk** _optional_
|
|
346
346
|
AccessKey Secret (SK)
|
|
347
347
|
|
|
348
|
-
**--endpoint, -e** _optional_
|
|
349
|
-
API endpoint URL Example: esa.cn-hangzhou.aliyuncs.com
|
|
350
|
-
|
|
351
348
|
**Environment Variables**
|
|
352
349
|
Read from environment variables:
|
|
353
350
|
|
|
354
351
|
- **ESA_ACCESS_KEY_ID**
|
|
355
352
|
- **ESA_ACCESS_KEY_SECRET**
|
|
356
|
-
- **ESA_ENDPOINT**
|
|
357
353
|
|
|
358
354
|
---
|
|
359
355
|
|
|
@@ -2,13 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
**ESA CLI 提供多种命令来管理您的阿里云 ESA Functions & Pages。**
|
|
4
4
|
|
|
5
|
-
**init** - 从各种 Web
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
**init** - 从各种 Web 框架和模板创建新项目。
|
|
6
|
+
|
|
7
|
+
**dev** - 启动本地开发服务器。
|
|
8
|
+
|
|
9
|
+
**commit** - 提交代码并保存为新版本。
|
|
10
|
+
|
|
11
|
+
**deploy** - 将您的 Functions & Pages 部署到阿里云。
|
|
12
|
+
|
|
13
|
+
**deployments** - 管理您的部署和版本。
|
|
14
|
+
|
|
15
|
+
**project** - 管理您的 Functions & Pages 项目。
|
|
16
|
+
|
|
17
|
+
**site** - 列出您已激活的站点。
|
|
18
|
+
|
|
19
|
+
**domain** - 管理您的 Functions & Pages 的域名绑定。
|
|
20
|
+
|
|
21
|
+
**route** - 管理您的 Functions & Pages 的路由绑定。
|
|
22
|
+
|
|
23
|
+
**login** - 使用您的阿里云账户授权 ESA CLI。
|
|
24
|
+
|
|
25
|
+
**logout** - 移除 ESA CLI 访问您账户的授权。
|
|
26
|
+
|
|
27
|
+
**config** - 修改您的本地或全局配置。
|
|
28
|
+
|
|
29
|
+
**lang** - 设置 CLI 的语言。
|
|
12
30
|
|
|
13
31
|
### 如何运行 ESA CLI 命令
|
|
14
32
|
|
|
@@ -38,12 +56,12 @@ npx esa-cli <COMMAND> <SUBCOMMAND> [PARAMETERS] [OPTIONS]
|
|
|
38
56
|
|
|
39
57
|
```
|
|
40
58
|
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
59
|
+
...
|
|
60
|
+
"scripts": {
|
|
61
|
+
"deploy": "esa-cli deploy",
|
|
62
|
+
"dev": "esa-cli dev"
|
|
45
63
|
}
|
|
46
|
-
|
|
64
|
+
...
|
|
47
65
|
}
|
|
48
66
|
```
|
|
49
67
|
|
|
@@ -63,25 +81,25 @@ npm run deploy
|
|
|
63
81
|
esa-cli init [<NAME>] [OPTIONS]
|
|
64
82
|
```
|
|
65
83
|
|
|
66
|
-
**NAME
|
|
84
|
+
**NAME** _可选(默认:工作目录名称)_
|
|
67
85
|
**Functions & Pages 项目的名称。这既是目录名称,也是生成的 ESA CLI 配置中的 name 属性。**
|
|
68
86
|
|
|
69
|
-
**--framework, -f
|
|
87
|
+
**--framework, -f** _可选_
|
|
70
88
|
**选择前端框架(react/vue/nextjs...)**
|
|
71
89
|
|
|
72
|
-
**--language, -l
|
|
90
|
+
**--language, -l** _可选_
|
|
73
91
|
**选择编程语言(typescript/javascript)。可选:typescript | javascript**
|
|
74
92
|
|
|
75
|
-
**--template, -t
|
|
93
|
+
**--template, -t** _可选_
|
|
76
94
|
**指定模板名称**
|
|
77
95
|
|
|
78
|
-
**--yes, -y
|
|
96
|
+
**--yes, -y** _可选_
|
|
79
97
|
**对所有交互询问选择"是"(默认 false),模版采用helloworld**
|
|
80
98
|
|
|
81
|
-
**--git
|
|
99
|
+
**--git** _可选_
|
|
82
100
|
**在项目中初始化 git**
|
|
83
101
|
|
|
84
|
-
**--deploy
|
|
102
|
+
**--deploy** _可选_
|
|
85
103
|
**初始化完成后自动部署**
|
|
86
104
|
|
|
87
105
|
---
|
|
@@ -94,22 +112,22 @@ esa-cli init [<NAME>] [OPTIONS]
|
|
|
94
112
|
esa-cli dev [<ENTRY>] [OPTIONS]
|
|
95
113
|
```
|
|
96
114
|
|
|
97
|
-
**ENTRY
|
|
115
|
+
**ENTRY** _可选_
|
|
98
116
|
**函数和Pages入口文件**
|
|
99
117
|
|
|
100
|
-
**--port, -p
|
|
118
|
+
**--port, -p** _可选_
|
|
101
119
|
**监听端口**
|
|
102
120
|
|
|
103
|
-
**--minify, -m
|
|
121
|
+
**--minify, -m** _可选_
|
|
104
122
|
**开发模式下压缩代码(默认 false)**
|
|
105
123
|
|
|
106
|
-
**--refresh-command
|
|
124
|
+
**--refresh-command** _可选_
|
|
107
125
|
**保存自动刷新前执行的命令**
|
|
108
126
|
|
|
109
|
-
**--local-upstream
|
|
127
|
+
**--local-upstream** _可选_
|
|
110
128
|
**在本地开发中作为源站的主机**
|
|
111
129
|
|
|
112
|
-
**--debug
|
|
130
|
+
**--debug** _可选_
|
|
113
131
|
**输出调试日志(默认 false)**
|
|
114
132
|
|
|
115
133
|
---
|
|
@@ -122,19 +140,19 @@ esa-cli dev [<ENTRY>] [OPTIONS]
|
|
|
122
140
|
esa-cli commit [<ENTRY>] [OPTIONS]
|
|
123
141
|
```
|
|
124
142
|
|
|
125
|
-
**ENTRY
|
|
143
|
+
**ENTRY** _可选_
|
|
126
144
|
**函数和Pages入口文件**
|
|
127
145
|
|
|
128
|
-
**--minify, -m
|
|
146
|
+
**--minify, -m** _可选_
|
|
129
147
|
**提交前压缩代码(默认 false)**
|
|
130
148
|
|
|
131
|
-
**--assets, -a
|
|
149
|
+
**--assets, -a** _可选_
|
|
132
150
|
**静态资源目录**
|
|
133
151
|
|
|
134
|
-
**--description, -d
|
|
152
|
+
**--description, -d** _可选_
|
|
135
153
|
**版本/例程描述(跳过交互输入)**
|
|
136
154
|
|
|
137
|
-
**--name, -n
|
|
155
|
+
**--name, -n** _可选_
|
|
138
156
|
**函数和Pages名称**
|
|
139
157
|
|
|
140
158
|
---
|
|
@@ -147,25 +165,25 @@ esa-cli commit [<ENTRY>] [OPTIONS]
|
|
|
147
165
|
esa-cli deploy [<ENTRY>] [OPTIONS]
|
|
148
166
|
```
|
|
149
167
|
|
|
150
|
-
**ENTRY
|
|
151
|
-
**函数和Pages入口文件,默认以
|
|
168
|
+
**ENTRY** _可选_
|
|
169
|
+
**函数和Pages入口文件,默认以 `esa.jsonc`中entry配置为准**
|
|
152
170
|
|
|
153
|
-
**--version, -v
|
|
171
|
+
**--version, -v** _可选_
|
|
154
172
|
**指定要部署的版本(跳过交互选择)**
|
|
155
173
|
|
|
156
|
-
**--environment, -e
|
|
174
|
+
**--environment, -e** _可选_
|
|
157
175
|
**部署环境。可选:staging | production**
|
|
158
176
|
|
|
159
|
-
**--name, -n
|
|
177
|
+
**--name, -n** _可选_
|
|
160
178
|
**函数和Pages名称**
|
|
161
179
|
|
|
162
|
-
**--assets, -a
|
|
180
|
+
**--assets, -a** _可选_
|
|
163
181
|
**静态资源目录(例如:./dist)**
|
|
164
182
|
|
|
165
|
-
**--description, -d
|
|
183
|
+
**--description, -d** _可选_
|
|
166
184
|
**版本描述**
|
|
167
185
|
|
|
168
|
-
**--minify, -m
|
|
186
|
+
**--minify, -m** _可选_
|
|
169
187
|
**是否压缩代码**
|
|
170
188
|
|
|
171
189
|
---
|
|
@@ -190,7 +208,7 @@ esa-cli deployments list
|
|
|
190
208
|
esa-cli deployments delete [<DEPLOYMENT_ID>...] [OPTIONS]
|
|
191
209
|
```
|
|
192
210
|
|
|
193
|
-
**DEPLOYMENT_ID
|
|
211
|
+
**DEPLOYMENT_ID** _必需_
|
|
194
212
|
**要删除的部署版本ID(可一次传多个)**
|
|
195
213
|
|
|
196
214
|
---
|
|
@@ -215,7 +233,7 @@ esa-cli project list
|
|
|
215
233
|
esa-cli project delete <PROJECT_NAME> [OPTIONS]
|
|
216
234
|
```
|
|
217
235
|
|
|
218
|
-
**PROJECT_NAME
|
|
236
|
+
**PROJECT_NAME** _必需_
|
|
219
237
|
**要删除的函数或Pages名称**
|
|
220
238
|
|
|
221
239
|
---
|
|
@@ -248,7 +266,7 @@ esa-cli domain add <DOMAIN> [OPTIONS]
|
|
|
248
266
|
|
|
249
267
|
**只有在该账号下激活的站点才能绑定**
|
|
250
268
|
|
|
251
|
-
**DOMAIN
|
|
269
|
+
**DOMAIN** _必需_
|
|
252
270
|
**要绑定的域名(在该账号站点下已激活)**
|
|
253
271
|
|
|
254
272
|
### domain list
|
|
@@ -267,7 +285,7 @@ esa-cli domain list
|
|
|
267
285
|
esa-cli domain delete <DOMAIN> [OPTIONS]
|
|
268
286
|
```
|
|
269
287
|
|
|
270
|
-
**DOMAIN
|
|
288
|
+
**DOMAIN** _必需_
|
|
271
289
|
**要删除绑定的域名**
|
|
272
290
|
|
|
273
291
|
---
|
|
@@ -284,23 +302,24 @@ esa-cli domain delete <DOMAIN> [OPTIONS]
|
|
|
284
302
|
esa-cli route add [<ROUTE>] [<SITE>] [OPTIONS]
|
|
285
303
|
```
|
|
286
304
|
|
|
287
|
-
**ROUTE
|
|
305
|
+
**ROUTE** _可选_
|
|
288
306
|
**路由值,例如:example.com/_ 或 _.example.com/\***
|
|
289
307
|
|
|
290
|
-
**SITE
|
|
308
|
+
**SITE** _可选_
|
|
291
309
|
**站点名称,例如:example.com**
|
|
292
310
|
|
|
293
311
|
**只有在该账号下激活的站点才能绑定**
|
|
294
312
|
|
|
295
|
-
**--route, -r
|
|
313
|
+
**--route, -r** _可选_
|
|
314
|
+
**路由值,例如:example.com/\***
|
|
296
315
|
|
|
297
|
-
- **主机名支持以
|
|
298
|
-
- **路径支持以
|
|
316
|
+
- **主机名支持以 `*` 开头表示后缀匹配(如:`*.example.com`)**
|
|
317
|
+
- **路径支持以 `*` 结尾表示前缀匹配(如:`/api/*`)**
|
|
299
318
|
|
|
300
|
-
**--site, -s
|
|
319
|
+
**--site, -s** _可选_
|
|
301
320
|
**站点名称(需为账户下已激活站点)**
|
|
302
321
|
|
|
303
|
-
**--alias, -a
|
|
322
|
+
**--alias, -a** _可选_
|
|
304
323
|
**路由名称(别名)例如:apple、orange等**
|
|
305
324
|
|
|
306
325
|
### route list
|
|
@@ -319,7 +338,7 @@ esa-cli route list
|
|
|
319
338
|
esa-cli route delete <ROUTE_NAME> [OPTIONS]
|
|
320
339
|
```
|
|
321
340
|
|
|
322
|
-
**ROUTE_NAME
|
|
341
|
+
**ROUTE_NAME** _必需_
|
|
323
342
|
**要删除的路由名称**
|
|
324
343
|
|
|
325
344
|
---
|
|
@@ -332,20 +351,16 @@ esa-cli route delete <ROUTE_NAME> [OPTIONS]
|
|
|
332
351
|
esa-cli login [OPTIONS]
|
|
333
352
|
```
|
|
334
353
|
|
|
335
|
-
**--access-key-id, --ak
|
|
354
|
+
**--access-key-id, --ak** _可选_
|
|
336
355
|
**AccessKey ID (AK)**
|
|
337
356
|
|
|
338
|
-
**--access-key-secret, --sk
|
|
357
|
+
**--access-key-secret, --sk** _可选_
|
|
339
358
|
**AccessKey Secret (SK)**
|
|
340
359
|
|
|
341
|
-
|
|
342
|
-
**API 端点 URL 例子: esa.cn-hangzhou.aliyuncs.com**
|
|
343
|
-
|
|
344
|
-
**环境变量**从环境变量中读取:
|
|
360
|
+
**环境变量** _从环境变量中读取:_
|
|
345
361
|
|
|
346
362
|
- **ESA_ACCESS_KEY_ID**
|
|
347
363
|
- **ESA_ACCESS_KEY_SECRET**
|
|
348
|
-
- **ESA_ENDPOINT**
|
|
349
364
|
|
|
350
365
|
---
|
|
351
366
|
|
|
@@ -367,10 +382,10 @@ esa-cli logout
|
|
|
367
382
|
esa-cli config [OPTIONS]
|
|
368
383
|
```
|
|
369
384
|
|
|
370
|
-
**--local, -l
|
|
385
|
+
**--local, -l** _可选_
|
|
371
386
|
**编辑本地配置文件(默认 false)**
|
|
372
387
|
|
|
373
|
-
**--global, -g
|
|
388
|
+
**--global, -g** _可选_
|
|
374
389
|
**编辑全局配置文件(默认 false)**
|
|
375
390
|
|
|
376
391
|
---
|
package/dist/i18n/locales.json
CHANGED
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import routeCommand from './commands/route/index.js';
|
|
|
24
24
|
import routine from './commands/routine/index.js';
|
|
25
25
|
import site from './commands/site/index.js';
|
|
26
26
|
import t from './i18n/index.js';
|
|
27
|
+
import logger from './libs/logger.js';
|
|
27
28
|
import { handleCheckVersion, checkCLIVersion } from './utils/checkVersion.js';
|
|
28
29
|
import { getCliConfig } from './utils/fileUtils/index.js';
|
|
29
30
|
const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -40,6 +41,9 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
40
41
|
.wrap(null)
|
|
41
42
|
.help()
|
|
42
43
|
.middleware((argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
+
if (argv.debug) {
|
|
45
|
+
logger.setLogLevel('debug');
|
|
46
|
+
}
|
|
43
47
|
try {
|
|
44
48
|
// Pass current command (first positional) so version check can decide prompting behavior
|
|
45
49
|
yield checkCLIVersion((argv._ && argv._[0] ? String(argv._[0]) : ''));
|
|
@@ -57,6 +61,11 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
57
61
|
.options('help', {
|
|
58
62
|
describe: t('main_help_describe').d('Show help'),
|
|
59
63
|
alias: 'h'
|
|
64
|
+
})
|
|
65
|
+
.options('debug', {
|
|
66
|
+
describe: t('dev_option_debugger').d('Output debug logs'),
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
default: false
|
|
60
69
|
});
|
|
61
70
|
esa.command('*', false, () => { }, (args) => {
|
|
62
71
|
if (args._.length > 0) {
|
package/dist/libs/api.js
CHANGED
|
@@ -11,6 +11,7 @@ import ESA, * as $ESA from '@alicloud/esa20240910';
|
|
|
11
11
|
import * as $OpenApi from '@alicloud/openapi-client';
|
|
12
12
|
import * as $Util from '@alicloud/tea-util';
|
|
13
13
|
import { getApiConfig } from '../utils/fileUtils/index.js';
|
|
14
|
+
import { CLI_USER_AGENT } from './constants.js';
|
|
14
15
|
import logger from './logger.js';
|
|
15
16
|
class Client {
|
|
16
17
|
constructor() {
|
|
@@ -77,7 +78,8 @@ class Client {
|
|
|
77
78
|
const apiConfig = new $OpenApi.Config({
|
|
78
79
|
accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
79
80
|
accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
80
|
-
endpoint: config.endpoint
|
|
81
|
+
endpoint: config.endpoint,
|
|
82
|
+
userAgent: CLI_USER_AGENT
|
|
81
83
|
});
|
|
82
84
|
return new ESA.default(apiConfig);
|
|
83
85
|
}
|
package/dist/libs/apiService.js
CHANGED
|
@@ -12,6 +12,7 @@ import FormData from 'form-data';
|
|
|
12
12
|
import fetch from 'node-fetch';
|
|
13
13
|
import t from '../i18n/index.js';
|
|
14
14
|
import { getApiConfig } from '../utils/fileUtils/index.js';
|
|
15
|
+
import { CLI_USER_AGENT } from './constants.js';
|
|
15
16
|
import { Environment } from './interface.js';
|
|
16
17
|
export class ApiService {
|
|
17
18
|
constructor(cliConfig) {
|
|
@@ -19,7 +20,8 @@ export class ApiService {
|
|
|
19
20
|
let apiConfig = new $OpenApi.Config({
|
|
20
21
|
accessKeyId: (_a = cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
21
22
|
accessKeySecret: (_b = cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
22
|
-
endpoint: cliConfig.endpoint
|
|
23
|
+
endpoint: cliConfig.endpoint,
|
|
24
|
+
userAgent: CLI_USER_AGENT
|
|
23
25
|
});
|
|
24
26
|
this.client = new $OpenApi.default.default(apiConfig);
|
|
25
27
|
}
|
|
@@ -37,7 +39,8 @@ export class ApiService {
|
|
|
37
39
|
let apiConfig = new $OpenApi.Config({
|
|
38
40
|
accessKeyId: (_a = newConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
39
41
|
accessKeySecret: (_b = newConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
40
|
-
endpoint: newConfig.endpoint
|
|
42
|
+
endpoint: newConfig.endpoint,
|
|
43
|
+
userAgent: CLI_USER_AGENT
|
|
41
44
|
});
|
|
42
45
|
this.client = new $OpenApi.default.default(apiConfig);
|
|
43
46
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
const packageJson = require('../../package.json');
|
|
4
|
+
/**
|
|
5
|
+
* CLI User-Agent string for API requests
|
|
6
|
+
* Format: esa-cli/{version}
|
|
7
|
+
* This helps identify requests originating from the CLI
|
|
8
|
+
*/
|
|
9
|
+
export const CLI_USER_AGENT = `esa-cli/${packageJson.version}`;
|
|
10
|
+
/**
|
|
11
|
+
* CLI version from package.json
|
|
12
|
+
*/
|
|
13
|
+
export const CLI_VERSION = packageJson.version;
|
package/dist/utils/command.js
CHANGED
|
@@ -8,13 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { spawn } from 'child_process';
|
|
11
|
+
import { platform } from 'os';
|
|
11
12
|
import { cancel, spinner } from '@clack/prompts';
|
|
12
13
|
import chalk from 'chalk';
|
|
14
|
+
export const isWindows = platform() === 'win32';
|
|
13
15
|
/**
|
|
14
16
|
* Execute a shell command with rich options (spinner, capture, env, cwd).
|
|
15
17
|
*/
|
|
16
18
|
export const execCommand = (command_1, ...args_1) => __awaiter(void 0, [command_1, ...args_1], void 0, function* (command, options = {}) {
|
|
17
|
-
const { startText, doneText, silent = false, captureOutput = false, useSpinner = true, realtimeOutput = false, interactive = false, env, cwd, transformOutput, fallbackOutput, errorMessage } = options;
|
|
19
|
+
const { startText, doneText, silent = false, captureOutput = false, useSpinner = true, realtimeOutput = false, interactive = false, env, cwd, transformOutput, fallbackOutput, errorMessage, shell = false } = options;
|
|
18
20
|
// Determine stdio mode based on options
|
|
19
21
|
// If realtimeOutput is true, we need to pipe to capture and display output in real-time
|
|
20
22
|
// If spinner is used without realtimeOutput, pipe to avoid TTY contention
|
|
@@ -55,7 +57,7 @@ export const execCommand = (command_1, ...args_1) => __awaiter(void 0, [command_
|
|
|
55
57
|
stdio,
|
|
56
58
|
cwd,
|
|
57
59
|
env: Object.assign(Object.assign({}, process.env), env),
|
|
58
|
-
shell
|
|
60
|
+
shell
|
|
59
61
|
});
|
|
60
62
|
if (stdio === 'pipe') {
|
|
61
63
|
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.on('data', (chunk) => {
|
|
@@ -146,4 +148,21 @@ export const execCommand = (command_1, ...args_1) => __awaiter(void 0, [command_
|
|
|
146
148
|
return { success: false, stdout, stderr };
|
|
147
149
|
}
|
|
148
150
|
});
|
|
151
|
+
/**
|
|
152
|
+
* Execute a command with login shell on Unix (to load ~/.profile, ~/.zshrc etc.)
|
|
153
|
+
* On Windows, directly execute the command since login shell is not typically needed.
|
|
154
|
+
*
|
|
155
|
+
* @param commandStr - The full command string to execute
|
|
156
|
+
* @param options - ExecCommandOptions
|
|
157
|
+
*/
|
|
158
|
+
export const execWithLoginShell = (commandStr_1, ...args_1) => __awaiter(void 0, [commandStr_1, ...args_1], void 0, function* (commandStr, options = {}) {
|
|
159
|
+
if (isWindows) {
|
|
160
|
+
// Windows: use cmd /c to execute the command
|
|
161
|
+
return execCommand(['cmd', '/c', commandStr], options);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Unix: use login shell to ensure PATH is properly set (nvm, fnm, etc.)
|
|
165
|
+
return execCommand(['sh', '-lc', commandStr], options);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
149
168
|
export default execCommand;
|
package/dist/utils/compress.js
CHANGED
|
@@ -47,8 +47,8 @@ const compress = (scriptEntry_1, assetsDir_1, ...args_1) => __awaiter(void 0, [s
|
|
|
47
47
|
'esa.jsonc (recommended) or esa.toml is not found and script entry or assets directory is not provided by command line',
|
|
48
48
|
'',
|
|
49
49
|
'See configuration guide:',
|
|
50
|
-
`- English: ${chalk.underline('https://github.com/aliyun/alibabacloud-esa-cli/blob/
|
|
51
|
-
`- 中文: ${chalk.underline('https://github.com/aliyun/alibabacloud-esa-cli/blob/
|
|
50
|
+
`- English: ${chalk.underline('https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/Config_en.md')}`,
|
|
51
|
+
`- 中文: ${chalk.underline('https://github.com/aliyun/alibabacloud-esa-cli/blob/master/docs/Config_zh_CN.md')}`
|
|
52
52
|
].join('\n'));
|
|
53
53
|
exit(1);
|
|
54
54
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "esa-cli",
|
|
3
|
-
"version": "1.0.4-beta.
|
|
3
|
+
"version": "1.0.4-beta.4",
|
|
4
4
|
"description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
|
|
5
5
|
"main": "bin/enter.cjs",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"README.md"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "
|
|
18
|
+
"build": "rimraf ./dist ./build && node ./genLocale.cjs && tsc && node ./copy.cjs",
|
|
19
19
|
"dev": "tsc --watch",
|
|
20
20
|
"eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
|
|
21
21
|
"prepare": "husky install",
|
|
@@ -63,9 +63,6 @@
|
|
|
63
63
|
"jsdom": "^25.0.1",
|
|
64
64
|
"lint-staged": "^15.0.2",
|
|
65
65
|
"prettier": "^3.0.3",
|
|
66
|
-
"react": "^18.2.0",
|
|
67
|
-
"react-dom": "^18.2.0",
|
|
68
|
-
"rimraf": "^6.0.1",
|
|
69
66
|
"tsc-files": "^1.1.4",
|
|
70
67
|
"typescript": "^5.2.2",
|
|
71
68
|
"vitest": "^2.0.4"
|
|
@@ -85,7 +82,7 @@
|
|
|
85
82
|
"chokidar": "^3.5.3",
|
|
86
83
|
"cli-table3": "^0.6.5",
|
|
87
84
|
"cross-spawn": "^7.0.3",
|
|
88
|
-
"esa-template": "
|
|
85
|
+
"esa-template": "0.0.10",
|
|
89
86
|
"esbuild": "^0.21.1",
|
|
90
87
|
"esbuild-plugin-less": "^1.3.8",
|
|
91
88
|
"form-data": "^4.0.0",
|
|
@@ -105,7 +102,10 @@
|
|
|
105
102
|
"portscanner": "^2.2.0",
|
|
106
103
|
"winston": "^3.11.0",
|
|
107
104
|
"winston-daily-rotate-file": "^5.0.0",
|
|
108
|
-
"yargs": "^17.7.2"
|
|
105
|
+
"yargs": "^17.7.2",
|
|
106
|
+
"react": "^18.2.0",
|
|
107
|
+
"react-dom": "^18.2.0",
|
|
108
|
+
"rimraf": "^6.0.1"
|
|
109
109
|
},
|
|
110
110
|
"lint-staged": {
|
|
111
111
|
"src/**/*.{ts,tsx,js,jsx}": [
|