generated from canisminor1990/canisminor-template
-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathconfStore.ts
41 lines (34 loc) · 968 Bytes
/
confStore.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import Conf from 'conf';
export interface Config {
githubToken: string;
}
export type ConfigKeys = keyof Config;
export interface ConfigSchemaItem {
default: string | number | boolean;
type: 'string' | 'number' | 'boolean';
}
export type ConfigSchema = {
[key in ConfigKeys]: ConfigSchemaItem;
};
export const schema: ConfigSchema = {
githubToken: {
default: '',
type: 'string',
},
};
export const config = new Conf({
projectName: 'lobe-i18n',
schema,
});
export const getConfig = <K extends ConfigKeys>(key: K): Config[K] => config.get(key) as Config[K];
export const getDefulatConfig = <K extends ConfigKeys>(key: K) => schema[key].default as Config[K];
export const setConfig = <K extends ConfigKeys>(key: K, value: Config[K]) => config.set(key, value);
export const useConfStore = () => {
const store = config.store as Config;
return {
get: getConfig,
getDefault: getDefulatConfig,
set: setConfig,
store,
};
};