@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 +3 -3
- package/README.zh-CN.md +1 -1
- package/package.json +1 -1
- package/src/util/settings.js +9 -2
- package/test/profileDefault.test.js +12 -0
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
62
|
+
`.evt/config.json`。需要 profile 的命令在未传 `--profile` 时会使用这个默认值。
|
|
63
63
|
临时传入 `--profile <name>` 仍然可以覆盖本次命令。
|
|
64
64
|
|
|
65
65
|
## 数据目录
|
package/package.json
CHANGED
package/src/util/settings.js
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
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
|
+
});
|