@tooee/config 0.7.2 → 0.8.0
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/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +87 -52
- package/dist/load.js.map +1 -1
- package/dist/types.d.ts +4 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/load.ts +113 -61
- package/src/types.ts +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { ColorMode, TooeeConfig } from "./types.js";
|
|
2
|
+
export type { Mode } from "./types.js";
|
|
2
3
|
export { loadConfig, writeGlobalConfig } from "./load.js";
|
|
3
4
|
export { ConfigProvider, useConfig, useThemeConfig, useKeymapConfig } from "./context.js";
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzD,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/load.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AA+K9C,eAAO,MAAM,UAAU,eAAmC,OAAO,CAAC,WAAW,CAAC,KAAG,WAQhF,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAAuC,OAAO,CAAC,WAAW,CAAC,KAAG,IAW3F,CAAC"}
|
package/dist/load.js
CHANGED
|
@@ -6,76 +6,111 @@ const DEFAULTS = {
|
|
|
6
6
|
name: "tokyonight",
|
|
7
7
|
},
|
|
8
8
|
};
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const parseJsonDocument = function parseJsonDocument(text) {
|
|
10
|
+
// SAFETY: `JSON.parse` without a reviver produces only the JSON grammar: strings,
|
|
11
|
+
// finite numbers, booleans, null, arrays, and plain objects. `JsonValue` is that
|
|
12
|
+
// grammar, so the assertion restates the parser's own contract and narrows nothing.
|
|
13
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- JSON.parse is typed `any`; the SAFETY note above states the invariant
|
|
14
|
+
return JSON.parse(text);
|
|
11
15
|
};
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
const isJsonObject = function isJsonObject(value) {
|
|
17
|
+
return value instanceof Object && !Array.isArray(value);
|
|
18
|
+
};
|
|
19
|
+
const isJsonString = function isJsonString(value) {
|
|
20
|
+
// The config decoder is the one place that inspects a JSON value's representation;
|
|
21
|
+
// every caller branches on the decoded domain value instead.
|
|
22
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- primitive check inside the boundary decoder
|
|
23
|
+
return typeof value === "string";
|
|
24
|
+
};
|
|
25
|
+
const decodeTheme = function decodeTheme(json) {
|
|
26
|
+
const theme = {};
|
|
27
|
+
const { mode, name } = json;
|
|
28
|
+
if (isJsonString(name)) {
|
|
29
|
+
theme.name = name;
|
|
30
|
+
}
|
|
31
|
+
if (mode === "dark" || mode === "light") {
|
|
32
|
+
theme.mode = mode;
|
|
33
|
+
}
|
|
34
|
+
return theme;
|
|
35
|
+
};
|
|
36
|
+
/** Every value must be a string; one wrong value rejects the whole map. */
|
|
37
|
+
const decodeKeys = function decodeKeys(json) {
|
|
38
|
+
const entries = [];
|
|
39
|
+
for (const [key, value] of Object.entries(json)) {
|
|
40
|
+
if (!isJsonString(value)) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
entries.push([key, value]);
|
|
44
|
+
}
|
|
45
|
+
return Object.fromEntries(entries);
|
|
46
|
+
};
|
|
47
|
+
const decodeView = function decodeView(json) {
|
|
48
|
+
const view = {};
|
|
49
|
+
const { copyOnSelect, diffLayout, gutter, wrap } = json;
|
|
50
|
+
if (wrap === true || wrap === false) {
|
|
51
|
+
view.wrap = wrap;
|
|
52
|
+
}
|
|
53
|
+
if (gutter === true || gutter === false) {
|
|
54
|
+
view.gutter = gutter;
|
|
55
|
+
}
|
|
56
|
+
if (diffLayout === "split" || diffLayout === "stack") {
|
|
57
|
+
view.diffLayout = diffLayout;
|
|
58
|
+
}
|
|
59
|
+
if (copyOnSelect === true ||
|
|
60
|
+
copyOnSelect === false ||
|
|
61
|
+
copyOnSelect === "primary" ||
|
|
62
|
+
copyOnSelect === "clipboard") {
|
|
63
|
+
view.copyOnSelect = copyOnSelect;
|
|
15
64
|
}
|
|
16
|
-
return
|
|
65
|
+
return view;
|
|
17
66
|
};
|
|
18
|
-
|
|
19
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Decode one config document. A section that is present as an object is kept
|
|
69
|
+
* even when none of its fields decode, so `{ "view": {} }` yields `view: {}`;
|
|
70
|
+
* a section with the wrong representation is dropped as if it were absent.
|
|
71
|
+
*/
|
|
72
|
+
const decodeConfig = function decodeConfig(json) {
|
|
73
|
+
if (!isJsonObject(json)) {
|
|
20
74
|
return {};
|
|
21
75
|
}
|
|
22
76
|
const config = {};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
theme.name = value.theme.name;
|
|
27
|
-
}
|
|
28
|
-
if (value.theme.mode === "dark" || value.theme.mode === "light") {
|
|
29
|
-
theme.mode = value.theme.mode;
|
|
30
|
-
}
|
|
31
|
-
config.theme = theme;
|
|
32
|
-
}
|
|
33
|
-
const keys = readStringRecord(value.keys);
|
|
34
|
-
if (keys !== undefined) {
|
|
35
|
-
config.keys = keys;
|
|
77
|
+
const { keys, theme, view } = json;
|
|
78
|
+
if (isJsonObject(theme)) {
|
|
79
|
+
config.theme = decodeTheme(theme);
|
|
36
80
|
}
|
|
37
|
-
if (
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (typeof value.view.gutter === "boolean") {
|
|
43
|
-
view.gutter = value.view.gutter;
|
|
44
|
-
}
|
|
45
|
-
if (value.view.diffLayout === "split" || value.view.diffLayout === "stack") {
|
|
46
|
-
view.diffLayout = value.view.diffLayout;
|
|
81
|
+
if (isJsonObject(keys)) {
|
|
82
|
+
const decodedKeys = decodeKeys(keys);
|
|
83
|
+
if (decodedKeys !== undefined) {
|
|
84
|
+
config.keys = decodedKeys;
|
|
47
85
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
view.copyOnSelect = value.view.copyOnSelect;
|
|
52
|
-
}
|
|
53
|
-
config.view = view;
|
|
86
|
+
}
|
|
87
|
+
if (isJsonObject(view)) {
|
|
88
|
+
config.view = decodeView(view);
|
|
54
89
|
}
|
|
55
90
|
return config;
|
|
56
91
|
};
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// Layering
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
57
95
|
const mergeConfig = function mergeConfig(target, source) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
...source
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
: { view: { ...target.view, ...source.view } }),
|
|
70
|
-
};
|
|
96
|
+
const merged = { ...target, ...source };
|
|
97
|
+
if (target.theme !== undefined || source.theme !== undefined) {
|
|
98
|
+
merged.theme = { ...target.theme, ...source.theme };
|
|
99
|
+
}
|
|
100
|
+
if (target.keys !== undefined || source.keys !== undefined) {
|
|
101
|
+
merged.keys = { ...target.keys, ...source.keys };
|
|
102
|
+
}
|
|
103
|
+
if (target.view !== undefined || source.view !== undefined) {
|
|
104
|
+
merged.view = { ...target.view, ...source.view };
|
|
105
|
+
}
|
|
106
|
+
return merged;
|
|
71
107
|
};
|
|
72
108
|
const readJsonFile = function readJsonFile(configPath) {
|
|
73
109
|
try {
|
|
74
110
|
if (!existsSync(configPath)) {
|
|
75
111
|
return {};
|
|
76
112
|
}
|
|
77
|
-
|
|
78
|
-
return validateConfig(parsed);
|
|
113
|
+
return decodeConfig(parseJsonDocument(readFileSync(configPath, "utf-8")));
|
|
79
114
|
}
|
|
80
115
|
catch {
|
|
81
116
|
return {};
|
package/dist/load.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC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C;QAC9C,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpC,aAAa,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,sBAAsB;IACxB,CAAC;AACH,CAAC,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ColorMode = "dark" | "light";
|
|
2
|
+
/** @deprecated Use `ColorMode` instead. */
|
|
3
|
+
export type Mode = ColorMode;
|
|
2
4
|
export interface TooeeConfig {
|
|
3
5
|
theme?: {
|
|
4
6
|
name?: string;
|
|
5
|
-
mode?:
|
|
7
|
+
mode?: ColorMode;
|
|
6
8
|
};
|
|
7
9
|
keys?: Record<string, string>;
|
|
8
10
|
view?: {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;AAEzC,2CAA2C;AAC3C,MAAM,MAAM,IAAI,GAAG,SAAS,CAAC;AAE7B,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,SAAS,CAAC;KAClB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE;QACL,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,YAAY,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,CAAC;QACjD,sEAAsE;QACtE,UAAU,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;KAChC,CAAC;CACH"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { ColorMode, TooeeConfig } from "./types.js";
|
|
2
|
+
// oxlint-disable-next-line typescript/no-deprecated -- public compatibility alias
|
|
3
|
+
export type { Mode } from "./types.js";
|
|
2
4
|
export { loadConfig, writeGlobalConfig } from "./load.js";
|
|
3
5
|
export { ConfigProvider, useConfig, useThemeConfig, useKeymapConfig } from "./context.js";
|
package/src/load.ts
CHANGED
|
@@ -9,83 +9,136 @@ const DEFAULTS: TooeeConfig = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// JSON boundary
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/** The JSON grammar, exactly as `JSON.parse` produces it without a reviver. */
|
|
17
|
+
type JsonValue = string | number | boolean | null | readonly JsonValue[] | JsonObject;
|
|
18
|
+
|
|
19
|
+
/** A JSON object. A key that is absent from the document reads as `undefined`. */
|
|
20
|
+
interface JsonObject {
|
|
21
|
+
readonly [key: string]: JsonValue | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const parseJsonDocument = function parseJsonDocument(text: string): JsonValue {
|
|
25
|
+
// SAFETY: `JSON.parse` without a reviver produces only the JSON grammar: strings,
|
|
26
|
+
// finite numbers, booleans, null, arrays, and plain objects. `JsonValue` is that
|
|
27
|
+
// grammar, so the assertion restates the parser's own contract and narrows nothing.
|
|
28
|
+
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- JSON.parse is typed `any`; the SAFETY note above states the invariant
|
|
29
|
+
return JSON.parse(text) as JsonValue;
|
|
14
30
|
};
|
|
15
31
|
|
|
16
|
-
const
|
|
17
|
-
value
|
|
18
|
-
): Record<string, string> | undefined {
|
|
19
|
-
if (!isRecord(value) || Object.values(value).some((entry) => typeof entry !== "string")) {
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
return Object.fromEntries(
|
|
23
|
-
Object.entries(value).filter(
|
|
24
|
-
(entry): entry is [string, string] => typeof entry[1] === "string",
|
|
25
|
-
),
|
|
26
|
-
);
|
|
32
|
+
const isJsonObject = function isJsonObject(value: JsonValue | undefined): value is JsonObject {
|
|
33
|
+
return value instanceof Object && !Array.isArray(value);
|
|
27
34
|
};
|
|
28
35
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
const isJsonString = function isJsonString(value: JsonValue | undefined): value is string {
|
|
37
|
+
// The config decoder is the one place that inspects a JSON value's representation;
|
|
38
|
+
// every caller branches on the decoded domain value instead.
|
|
39
|
+
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- primitive check inside the boundary decoder
|
|
40
|
+
return typeof value === "string";
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// Config decoding
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
|
|
47
|
+
type ThemeSettings = NonNullable<TooeeConfig["theme"]>;
|
|
48
|
+
type ViewSettings = NonNullable<TooeeConfig["view"]>;
|
|
49
|
+
|
|
50
|
+
const decodeTheme = function decodeTheme(json: JsonObject): ThemeSettings {
|
|
51
|
+
const theme: ThemeSettings = {};
|
|
52
|
+
const { mode, name } = json;
|
|
53
|
+
if (isJsonString(name)) {
|
|
54
|
+
theme.name = name;
|
|
32
55
|
}
|
|
56
|
+
if (mode === "dark" || mode === "light") {
|
|
57
|
+
theme.mode = mode;
|
|
58
|
+
}
|
|
59
|
+
return theme;
|
|
60
|
+
};
|
|
33
61
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (value.theme.mode === "dark" || value.theme.mode === "light") {
|
|
41
|
-
theme.mode = value.theme.mode;
|
|
62
|
+
/** Every value must be a string; one wrong value rejects the whole map. */
|
|
63
|
+
const decodeKeys = function decodeKeys(json: JsonObject): TooeeConfig["keys"] {
|
|
64
|
+
const entries: [string, string][] = [];
|
|
65
|
+
for (const [key, value] of Object.entries(json)) {
|
|
66
|
+
if (!isJsonString(value)) {
|
|
67
|
+
return undefined;
|
|
42
68
|
}
|
|
43
|
-
|
|
69
|
+
entries.push([key, value]);
|
|
44
70
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
71
|
+
return Object.fromEntries(entries);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const decodeView = function decodeView(json: JsonObject): ViewSettings {
|
|
75
|
+
const view: ViewSettings = {};
|
|
76
|
+
const { copyOnSelect, diffLayout, gutter, wrap } = json;
|
|
77
|
+
if (wrap === true || wrap === false) {
|
|
78
|
+
view.wrap = wrap;
|
|
48
79
|
}
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
80
|
+
if (gutter === true || gutter === false) {
|
|
81
|
+
view.gutter = gutter;
|
|
82
|
+
}
|
|
83
|
+
if (diffLayout === "split" || diffLayout === "stack") {
|
|
84
|
+
view.diffLayout = diffLayout;
|
|
85
|
+
}
|
|
86
|
+
if (
|
|
87
|
+
copyOnSelect === true ||
|
|
88
|
+
copyOnSelect === false ||
|
|
89
|
+
copyOnSelect === "primary" ||
|
|
90
|
+
copyOnSelect === "clipboard"
|
|
91
|
+
) {
|
|
92
|
+
view.copyOnSelect = copyOnSelect;
|
|
93
|
+
}
|
|
94
|
+
return view;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Decode one config document. A section that is present as an object is kept
|
|
99
|
+
* even when none of its fields decode, so `{ "view": {} }` yields `view: {}`;
|
|
100
|
+
* a section with the wrong representation is dropped as if it were absent.
|
|
101
|
+
*/
|
|
102
|
+
const decodeConfig = function decodeConfig(json: JsonValue): Partial<TooeeConfig> {
|
|
103
|
+
if (!isJsonObject(json)) {
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
const config: Partial<TooeeConfig> = {};
|
|
107
|
+
const { keys, theme, view } = json;
|
|
108
|
+
if (isJsonObject(theme)) {
|
|
109
|
+
config.theme = decodeTheme(theme);
|
|
110
|
+
}
|
|
111
|
+
if (isJsonObject(keys)) {
|
|
112
|
+
const decodedKeys = decodeKeys(keys);
|
|
113
|
+
if (decodedKeys !== undefined) {
|
|
114
|
+
config.keys = decodedKeys;
|
|
66
115
|
}
|
|
67
|
-
|
|
116
|
+
}
|
|
117
|
+
if (isJsonObject(view)) {
|
|
118
|
+
config.view = decodeView(view);
|
|
68
119
|
}
|
|
69
120
|
return config;
|
|
70
121
|
};
|
|
71
122
|
|
|
123
|
+
// ---------------------------------------------------------------------------
|
|
124
|
+
// Layering
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
|
|
72
127
|
const mergeConfig = function mergeConfig(
|
|
73
128
|
target: Partial<TooeeConfig>,
|
|
74
129
|
source: Partial<TooeeConfig>,
|
|
75
130
|
): TooeeConfig {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
...source
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
: { view: { ...target.view, ...source.view } }),
|
|
88
|
-
};
|
|
131
|
+
const merged: TooeeConfig = { ...target, ...source };
|
|
132
|
+
if (target.theme !== undefined || source.theme !== undefined) {
|
|
133
|
+
merged.theme = { ...target.theme, ...source.theme };
|
|
134
|
+
}
|
|
135
|
+
if (target.keys !== undefined || source.keys !== undefined) {
|
|
136
|
+
merged.keys = { ...target.keys, ...source.keys };
|
|
137
|
+
}
|
|
138
|
+
if (target.view !== undefined || source.view !== undefined) {
|
|
139
|
+
merged.view = { ...target.view, ...source.view };
|
|
140
|
+
}
|
|
141
|
+
return merged;
|
|
89
142
|
};
|
|
90
143
|
|
|
91
144
|
const readJsonFile = function readJsonFile(configPath: string): Partial<TooeeConfig> {
|
|
@@ -93,8 +146,7 @@ const readJsonFile = function readJsonFile(configPath: string): Partial<TooeeCon
|
|
|
93
146
|
if (!existsSync(configPath)) {
|
|
94
147
|
return {};
|
|
95
148
|
}
|
|
96
|
-
|
|
97
|
-
return validateConfig(parsed);
|
|
149
|
+
return decodeConfig(parseJsonDocument(readFileSync(configPath, "utf-8")));
|
|
98
150
|
} catch {
|
|
99
151
|
return {};
|
|
100
152
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type ColorMode = "dark" | "light";
|
|
2
|
+
|
|
3
|
+
/** @deprecated Use `ColorMode` instead. */
|
|
4
|
+
export type Mode = ColorMode;
|
|
2
5
|
|
|
3
6
|
export interface TooeeConfig {
|
|
4
7
|
theme?: {
|
|
5
8
|
name?: string;
|
|
6
|
-
mode?:
|
|
9
|
+
mode?: ColorMode;
|
|
7
10
|
};
|
|
8
11
|
keys?: Record<string, string>;
|
|
9
12
|
view?: {
|