alemonjs 2.1.23 → 2.1.24
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/lib/core/config.d.ts +8 -8
- package/lib/core/config.js +4 -6
- package/package.json +1 -1
package/lib/core/config.d.ts
CHANGED
|
@@ -2,20 +2,20 @@ import type { Package } from '../types';
|
|
|
2
2
|
type ConfigValue = {
|
|
3
3
|
[key: string]: any;
|
|
4
4
|
};
|
|
5
|
-
type ConfigListener = (value:
|
|
6
|
-
declare class ConfigCore {
|
|
5
|
+
type ConfigListener<T extends ConfigValue = ConfigValue> = (value: T) => void;
|
|
6
|
+
declare class ConfigCore<T extends ConfigValue = ConfigValue> {
|
|
7
7
|
#private;
|
|
8
8
|
constructor(dir: string);
|
|
9
|
-
get value():
|
|
10
|
-
saveValue(value:
|
|
11
|
-
onWatch(listener: ConfigListener): () => void;
|
|
9
|
+
get value(): T | null;
|
|
10
|
+
saveValue(value: T): void;
|
|
11
|
+
onWatch(listener: ConfigListener<T>): () => void;
|
|
12
12
|
dispose(): void;
|
|
13
13
|
get package(): Package | null;
|
|
14
14
|
get argv(): {
|
|
15
15
|
[key: string]: string;
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
-
export declare const getConfig: () =>
|
|
19
|
-
export declare const getConfigValue: () =>
|
|
20
|
-
export declare const onWatchConfigValue: (callback: ConfigListener) => (() => void);
|
|
18
|
+
export declare const getConfig: <T extends ConfigValue = ConfigValue>() => ConfigCore<T>;
|
|
19
|
+
export declare const getConfigValue: <T extends ConfigValue = ConfigValue>() => T;
|
|
20
|
+
export declare const onWatchConfigValue: <T extends ConfigValue = ConfigValue>(callback: ConfigListener<T>) => (() => void);
|
|
21
21
|
export {};
|
package/lib/core/config.js
CHANGED
|
@@ -12,11 +12,7 @@ class ConfigCore {
|
|
|
12
12
|
#debounceDelay = 100;
|
|
13
13
|
#argvProxy = null;
|
|
14
14
|
#resolvedDir = null;
|
|
15
|
-
#initValue = {
|
|
16
|
-
gui: {
|
|
17
|
-
port: 17127
|
|
18
|
-
}
|
|
19
|
-
};
|
|
15
|
+
#initValue = {};
|
|
20
16
|
constructor(dir) {
|
|
21
17
|
this.#resolvedDir = join(process.cwd(), dir);
|
|
22
18
|
}
|
|
@@ -205,7 +201,9 @@ const getConfig = () => {
|
|
|
205
201
|
global.__config = new ConfigCore(configDir);
|
|
206
202
|
return global.__config;
|
|
207
203
|
};
|
|
208
|
-
const getConfigValue = () =>
|
|
204
|
+
const getConfigValue = () => {
|
|
205
|
+
return (getConfig()?.value || {});
|
|
206
|
+
};
|
|
209
207
|
const onWatchConfigValue = (callback) => {
|
|
210
208
|
return getConfig().onWatch(callback);
|
|
211
209
|
};
|