@icyouo/evt-cli 0.1.4 → 0.1.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
@@ -59,9 +59,9 @@ evt validate
59
59
  ```
60
60
 
61
61
  `evt profile set <name>` stores the default profile in
62
- `data/.evt/config.json` under the active config root. Commands that need a
63
- profile use that value when `--profile` is omitted. Passing `--profile <name>`
64
- still overrides the default for one command.
62
+ `.evt/config.json` under the active config root. Commands that need a profile
63
+ use that value when `--profile` is omitted. Passing `--profile <name>` still
64
+ overrides the default for one command.
65
65
 
66
66
  ## Data Layout
67
67
 
package/README.zh-CN.md CHANGED
@@ -59,7 +59,7 @@ evt validate
59
59
  ```
60
60
 
61
61
  `evt profile set <name>` 会把默认 profile 写到当前 config root 下的
62
- `data/.evt/config.json`。需要 profile 的命令在未传 `--profile` 时会使用这个默认值。
62
+ `.evt/config.json`。需要 profile 的命令在未传 `--profile` 时会使用这个默认值。
63
63
  临时传入 `--profile <name>` 仍然可以覆盖本次命令。
64
64
 
65
65
  ## 数据目录
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icyouo/evt-cli",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Run YAML-defined HTTP APIs and interactive workflows from your terminal.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -3,13 +3,19 @@ const path = require("node:path");
3
3
  const { resolveCliPath } = require("./paths");
4
4
 
5
5
  function settingsPath() {
6
+ return resolveCliPath(".evt", "config.json");
7
+ }
8
+
9
+ function legacySettingsPath() {
6
10
  return resolveCliPath("data", ".evt", "config.json");
7
11
  }
8
12
 
9
13
  function readSettings() {
10
14
  const file = settingsPath();
11
- if (!fs.existsSync(file)) return {};
12
- return JSON.parse(fs.readFileSync(file, "utf8"));
15
+ const legacyFile = legacySettingsPath();
16
+ const readableFile = fs.existsSync(file) ? file : legacyFile;
17
+ if (!fs.existsSync(readableFile)) return {};
18
+ return JSON.parse(fs.readFileSync(readableFile, "utf8"));
13
19
  }
14
20
 
15
21
  function writeSettings(settings) {
@@ -38,6 +44,7 @@ function resolveProfileName(profile) {
38
44
 
39
45
  module.exports = {
40
46
  getDefaultProfile,
47
+ legacySettingsPath,
41
48
  readSettings,
42
49
  resolveProfileName,
43
50
  setDefaultProfile,
@@ -51,6 +51,8 @@ test("profile set stores a project default profile used by api calls", async ()
51
51
  const root = createConfigRoot();
52
52
 
53
53
  await capture(() => run(["profile", "set", "dev", "--config-root", root]));
54
+ assert.equal(fs.existsSync(path.join(root, ".evt", "config.json")), true);
55
+ assert.equal(fs.existsSync(path.join(root, "data", ".evt", "config.json")), false);
54
56
 
55
57
  const current = await capture(() => run(["profile", "current", "--config-root", root]));
56
58
  assert.equal(current[0], "dev");
@@ -68,3 +70,13 @@ test("profile set stores a project default profile used by api calls", async ()
68
70
  assert.equal(payload.request.url, "https://dev.example.test/api/todos");
69
71
  assert.equal(payload.request.headers["X-Profile"], "dev");
70
72
  });
73
+
74
+ test("profile default still reads legacy data .evt settings", async () => {
75
+ const root = createConfigRoot();
76
+ write(path.join(root, "data", ".evt", "config.json"), JSON.stringify({
77
+ defaultProfile: "dev"
78
+ }, null, 2));
79
+
80
+ const current = await capture(() => run(["profile", "current", "--config-root", root]));
81
+ assert.equal(current[0], "dev");
82
+ });