ability-cli 0.3.1 → 0.3.2

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 (3) hide show
  1. package/README.md +5 -5
  2. package/dist/index.js +34 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -79,7 +79,7 @@ ability-cli doctor
79
79
 
80
80
  | 选项 | 说明 |
81
81
  |------|------|
82
- | `--env <env>` | 环境:`test` / `prod`,选用配置文件中哪一套 `profiles`(主要影响 `baseUrl`) |
82
+ | `--env <env>` | 环境:`test` / `stg` / `prod`,选用配置文件中哪一套 `profiles`(主要影响 `baseUrl`) |
83
83
  | `--auth-token <token>` | 授权密钥 `sk-…`,写入请求头 `Authorization` |
84
84
  | `--base-url <url>` | 网关根地址(真实路径为 `{baseUrl}/ability-service/api/agent/v1/...`) |
85
85
  | `--device-id <id>` | 设备 ID,写入请求头 `zy-device-id`,并参与部分接口 query |
@@ -213,7 +213,7 @@ GET `/ability-service/api/agent/v1/ability/category`。
213
213
 
214
214
  #### `doctor`
215
215
 
216
- 检查配置文件路径、当前环境、解析后的 **`Authorization(sk)`** / **`zy-device-id`** / **`baseUrl`**,并请求 `{baseUrl}/time` 做网关连通性探测。
216
+ 检查配置文件路径、当前环境、解析后的 **`Authorization(sk)`** / **`zy-device-id`** / **`baseUrl`**。
217
217
 
218
218
  ---
219
219
 
@@ -223,7 +223,7 @@ GET `/ability-service/api/agent/v1/ability/category`。
223
223
 
224
224
  默认路径:**`~/.ability-cli/config.json`**。
225
225
 
226
- 首次运行若文件不存在,会使用内置默认:当前环境 **`prod`**,`test` / `prod` 各有一套 `baseUrl`;`profiles.*.authToken`(sk)、`defaults.deviceId` 等为空字符串。
226
+ 首次运行若文件不存在,会使用内置默认:当前环境 **`prod`**,`test` / `stg` / `prod` 各有一套 `baseUrl`;`profiles.*.authToken`(sk)、`defaults.deviceId` 等为空字符串。
227
227
 
228
228
  通过 `ability-cli config set` 写入后,会按 `env` 更新对应 `profiles[env]` 下的 `baseUrl`、`authToken`(sk)等;`defaults` 下可保存默认设备 ID 等。
229
229
 
@@ -231,7 +231,7 @@ GET `/ability-service/api/agent/v1/ability/category`。
231
231
 
232
232
  | 变量 | 作用 |
233
233
  |------|------|
234
- | `ABILITY_CLI_ENV` | 选用 `profiles` 的环境键(如 `test` / `prod`) |
234
+ | `ABILITY_CLI_ENV` | 选用 `profiles` 的环境键(如 `test` / `stg` / `prod`) |
235
235
  | `ABILITY_CLI_AUTH_TOKEN` | 授权密钥 `sk-…`,对应请求头 `Authorization` |
236
236
  | `ABILITY_CLI_DEVICE_ID` | 设备 ID,对应请求头 `zy-device-id`,并参与部分 query |
237
237
  | `ABILITY_CLI_BASE_URL` | 网关根地址 |
@@ -242,7 +242,7 @@ GET `/ability-service/api/agent/v1/ability/category`。
242
242
 
243
243
  对 **`authToken` / `deviceId` / `baseUrl`**:**子命令参数 > 全局参数 > 对应环境变量 > 配置文件**(子命令与全局选项先做对象合并,后者覆盖前者)。
244
244
 
245
- 当前激活的 **profile(test prod)** 由 **`ABILITY_CLI_ENV`(若设置)** 与配置文件中的 **`env`** 字段共同决定(环境变量优先)。
245
+ 当前激活的 **profile(test / stg / prod)** 由 **`ABILITY_CLI_ENV`(若设置)** 与配置文件中的 **`env`** 字段共同决定(环境变量优先)。
246
246
 
247
247
  ---
248
248
 
package/dist/index.js CHANGED
@@ -17,6 +17,10 @@ var DEFAULT_CONFIG = {
17
17
  baseUrl: "https://biz-gw.zyqltest.com",
18
18
  authToken: ""
19
19
  },
20
+ stg: {
21
+ baseUrl: "https://biz-gw-in.zyql.com",
22
+ authToken: ""
23
+ },
20
24
  prod: {
21
25
  baseUrl: "https://biz-gw.zyql.com",
22
26
  authToken: ""
@@ -34,7 +38,33 @@ function loadConfig(configPath) {
34
38
  const p = configPath ?? getDefaultConfigPath();
35
39
  if (!fs.existsSync(p)) return structuredClone(DEFAULT_CONFIG);
36
40
  const raw = fs.readFileSync(p, "utf-8");
37
- return { ...structuredClone(DEFAULT_CONFIG), ...JSON.parse(raw) };
41
+ const parsed = JSON.parse(raw);
42
+ const defaults = parsed.defaults ?? {};
43
+ const profiles = parsed.profiles ?? {};
44
+ const mergedProfiles = {
45
+ ...structuredClone(DEFAULT_CONFIG).profiles
46
+ };
47
+ for (const [name, profile] of Object.entries(profiles)) {
48
+ const prev = mergedProfiles[name] ?? { baseUrl: "", authToken: "" };
49
+ const incoming = profile ?? {};
50
+ const normalized = { ...incoming };
51
+ if (typeof incoming.baseUrl === "undefined" || incoming.baseUrl.trim() === "") {
52
+ normalized.baseUrl = prev.baseUrl;
53
+ }
54
+ mergedProfiles[name] = {
55
+ ...prev,
56
+ ...normalized
57
+ };
58
+ }
59
+ return {
60
+ ...structuredClone(DEFAULT_CONFIG),
61
+ ...parsed,
62
+ defaults: {
63
+ ...structuredClone(DEFAULT_CONFIG).defaults,
64
+ ...defaults
65
+ },
66
+ profiles: mergedProfiles
67
+ };
38
68
  }
39
69
  function saveConfig(configPath, config) {
40
70
  const dir = path.dirname(configPath);
@@ -135,7 +165,7 @@ function mergeConfigSetOpts(program2, opts) {
135
165
  }
136
166
  function registerConfigCommand(program2) {
137
167
  const cfg = program2.command("config").description("\u7BA1\u7406 CLI \u914D\u7F6E");
138
- cfg.command("set").description("\u8BBE\u7F6E\u914D\u7F6E\u9879").option("--env <env>", "\u73AF\u5883 (test/prod)").option("--auth-token <token>", "Authorization token\uFF08sk\uFF09").option("--base-url <url>", "\u7F51\u5173\u5730\u5740").option("--device-id <id>", "\u9ED8\u8BA4\u8BBE\u5907ID").option("--timeout <ms>", "\u9ED8\u8BA4\u8C03\u7528\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09\uFF0C\u5199\u5165 defaults.timeout").action((opts) => {
168
+ cfg.command("set").description("\u8BBE\u7F6E\u914D\u7F6E\u9879").option("--env <env>", "\u73AF\u5883 (test/stg/prod)").option("--auth-token <token>", "Authorization token\uFF08sk\uFF09").option("--base-url <url>", "\u7F51\u5173\u5730\u5740").option("--device-id <id>", "\u9ED8\u8BA4\u8BBE\u5907ID").option("--timeout <ms>", "\u9ED8\u8BA4\u8C03\u7528\u8D85\u65F6\uFF08\u6BEB\u79D2\uFF09\uFF0C\u5199\u5165 defaults.timeout").action((opts) => {
139
169
  const m = mergeConfigSetOpts(program2, opts);
140
170
  const configPath = getDefaultConfigPath();
141
171
  const config = loadConfig(configPath);
@@ -493,7 +523,7 @@ function registerSignCommand(program2) {
493
523
  // src/commands/doctor.ts
494
524
  import chalk3 from "chalk";
495
525
  function registerDoctorCommand(program2) {
496
- program2.command("doctor").description("\u68C0\u67E5\u914D\u7F6E\u5B8C\u6574\u6027\u548C\u7F51\u5173\u8FDE\u901A\u6027").action(async () => {
526
+ program2.command("doctor").description("\u68C0\u67E5\u914D\u7F6E\u5B8C\u6574\u6027").action(async () => {
497
527
  const merged = program2.opts();
498
528
  const ctx = buildAgentRequestContext(merged);
499
529
  let ok = true;
@@ -513,19 +543,6 @@ function registerDoctorCommand(program2) {
513
543
  console.log(` ${icon} ${chalk3.gray(label + ":")} ${val}`);
514
544
  if (!pass) ok = false;
515
545
  }
516
- try {
517
- const res = await fetch(`${ctx.baseUrl}/time`);
518
- const body = await res.json();
519
- if (body.code === 200) {
520
- console.log(` ${chalk3.green("\u2714")} ${chalk3.gray("\u7F51\u5173\u8FDE\u901A(/time):")} ${body.data}`);
521
- } else {
522
- console.log(` ${chalk3.red("\u2716")} ${chalk3.gray("\u7F51\u5173\u8FDE\u901A(/time):")} \u8FD4\u56DE code=${body.code}`);
523
- ok = false;
524
- }
525
- } catch (e) {
526
- console.log(` ${chalk3.red("\u2716")} ${chalk3.gray("\u7F51\u5173\u8FDE\u901A(/time):")} ${e.message}`);
527
- ok = false;
528
- }
529
546
  console.log();
530
547
  if (ok) {
531
548
  console.log(chalk3.green(" \u4E00\u5207\u6B63\u5E38\uFF0C\u53EF\u4EE5\u5F00\u59CB\u4F7F\u7528\uFF01"));
@@ -543,7 +560,7 @@ function readPackageVersion() {
543
560
  const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
544
561
  return pkg.version ?? "0.0.0";
545
562
  }
546
- program.name("ability-cli").description("\u539F\u5B50\u80FD\u529B\u5E73\u53F0 CLI \u5DE5\u5177").version(readPackageVersion()).option("--env <env>", "\u73AF\u5883 (test/prod)\uFF0C\u9009\u62E9 profiles \u4E2D\u54EA\u5957 baseUrl").option("--auth-token <token>", "Authorization\uFF08sk-\u2026\uFF09\uFF0C\u8986\u76D6\u73AF\u5883\u53D8\u91CF\u4E0E\u914D\u7F6E").option("--base-url <url>", "\u7F51\u5173\u6839\u5730\u5740\uFF0C\u8986\u76D6\u73AF\u5883\u53D8\u91CF\u4E0E\u914D\u7F6E").option("--device-id <id>", "\u8BBE\u5907 ID\uFF08zy-device-id \u8BF7\u6C42\u5934 / \u90E8\u5206 query\uFF09\uFF0C\u8986\u76D6\u73AF\u5883\u53D8\u91CF\u4E0E\u914D\u7F6E").option("-v, --verbose", "\u8BE6\u7EC6\u8F93\u51FA");
563
+ program.name("ability-cli").description("\u539F\u5B50\u80FD\u529B\u5E73\u53F0 CLI \u5DE5\u5177").version(readPackageVersion()).option("--env <env>", "\u73AF\u5883 (test/stg/prod)\uFF0C\u9009\u62E9 profiles \u4E2D\u54EA\u5957 baseUrl").option("--auth-token <token>", "Authorization\uFF08sk-\u2026\uFF09\uFF0C\u8986\u76D6\u73AF\u5883\u53D8\u91CF\u4E0E\u914D\u7F6E").option("--base-url <url>", "\u7F51\u5173\u6839\u5730\u5740\uFF0C\u8986\u76D6\u73AF\u5883\u53D8\u91CF\u4E0E\u914D\u7F6E").option("--device-id <id>", "\u8BBE\u5907 ID\uFF08zy-device-id \u8BF7\u6C42\u5934 / \u90E8\u5206 query\uFF09\uFF0C\u8986\u76D6\u73AF\u5883\u53D8\u91CF\u4E0E\u914D\u7F6E").option("-v, --verbose", "\u8BE6\u7EC6\u8F93\u51FA");
547
564
  registerConfigCommand(program);
548
565
  registerRawCommand(program);
549
566
  registerSearchCommand(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ability-cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "原子能力平台 CLI 工具",
5
5
  "repository": {
6
6
  "type": "git",