esa-cli 1.0.4 → 1.0.5

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
@@ -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.x or higher (supports 18.x, 20.x, 22.x)
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
 
@@ -17,7 +17,7 @@ import Haikunator from 'haikunator';
17
17
  import t from '../../i18n/index.js';
18
18
  import logger from '../../libs/logger.js';
19
19
  import Template from '../../libs/templates/index.js';
20
- import { execCommand } from '../../utils/command.js';
20
+ import { execCommand, execWithLoginShell } from '../../utils/command.js';
21
21
  import { getDirName } from '../../utils/fileUtils/base.js';
22
22
  import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
23
23
  import promptParameter from '../../utils/prompt.js';
@@ -382,7 +382,7 @@ export const createProject = (initParams) => __awaiter(void 0, void 0, void 0, f
382
382
  const templateFlag = ((_a = frameworkConfig.language) === null || _a === void 0 ? void 0 : _a[initParams.language || 'typescript']) || '';
383
383
  const extraParams = frameworkConfig.params || '';
384
384
  const full = `${command} ${initParams.name} ${templateFlag} ${extraParams}`.trim();
385
- const res = yield execCommand(['sh', '-lc', full], {
385
+ const res = yield execWithLoginShell(full, {
386
386
  interactive: true,
387
387
  startText: `Starting to execute framework command ${chalk.gray(full)}`,
388
388
  doneText: `Framework command executed ${chalk.gray(full)}`
@@ -93,6 +93,13 @@ export function checkIsLoginSuccess() {
93
93
  },
94
94
  endpoint: result.endpoint
95
95
  });
96
+ api.updateConfig({
97
+ auth: {
98
+ accessKeyId,
99
+ accessKeySecret
100
+ },
101
+ endpoint: result.endpoint
102
+ });
96
103
  return true;
97
104
  }
98
105
  }
@@ -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
- \*\***dev** - 启动本地开发服务器。** \***\*commit** - 提交代码并保存为新版本。**
7
- \*\***deploy** - 将您的 Functions & Pages 部署到阿里云。** \***\*deployments** - 管理您的部署和版本。**
8
- \*\***project** - 管理您的 Functions & Pages 项目。** \***\*site** - 列出您已激活的站点。**
9
- \*\***domain** - 管理您的 Functions & Pages 的域名绑定。** \***\*route** - 管理您的 Functions & Pages 的路由绑定。**
10
- \*\***login** - 使用您的阿里云账户授权 ESA CLI。** \***\*logout** - 移除 ESA CLI 访问您账户的授权。**
11
- \*\***config** - 修改您的本地或全局配置。** \***\*lang** - 设置 CLI 的语言。
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
-  "scripts": {
43
-    "deploy": "esa-cli deploy",
44
-    "dev": "esa-cli dev"
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入口文件,默认以 **`esa.jsonc`中entry配置为准
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\***可选*路由值,例如:example.com/*
313
+ **--route, -r** _可选_
314
+ **路由值,例如:example.com/\***
296
315
 
297
- - **主机名支持以 **`*` 开头表示后缀匹配(如:`*.example.com`)
298
- - **路径支持以 **`*` 结尾表示前缀匹配(如:`/api/*`)
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
- **--endpoint, -e\***可选\*
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/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
  }
@@ -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;
@@ -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: false
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esa-cli",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
5
5
  "main": "bin/enter.cjs",
6
6
  "type": "module",