@arc-js/config-manager 0.0.91 → 0.0.94
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/core/ConfigService.js +0 -2
- package/hooks/useConfig.tsx +1 -0
- package/package.json +1 -1
- package/providers/ConfigProvider.jsx +15 -10
- package/providers/ConfigProvider.tsx +65 -60
- package/index.d.ts +0 -3
- package/index.js +0 -3
- package/index.min.js +0 -2
package/core/ConfigService.js
CHANGED
|
@@ -109,9 +109,7 @@ class ConfigService {
|
|
|
109
109
|
loadAllConfigs() {
|
|
110
110
|
return __awaiter(this, void 0, void 0, function* () {
|
|
111
111
|
const base = yield loadBaseConfig();
|
|
112
|
-
console.log('Base config loaded:', base);
|
|
113
112
|
const modules = yield loadModulesConfigs();
|
|
114
|
-
console.log('Modules configs loaded:', modules);
|
|
115
113
|
this.resources = modules.reduce((acc, { moduleName, config }) => {
|
|
116
114
|
return mergeDeep(acc, { [moduleName]: config });
|
|
117
115
|
}, { base });
|
package/hooks/useConfig.tsx
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.94",
|
|
7
7
|
"description": "CONFIG-MANAGER est un système de gestion de configuration modulaire pour les applications React avec TypeScript/JavaScript. Il fournit une gestion centralisée des configurations, un chargement dynamique des modules, et une intégration transparente avec les variables d'environnement.",
|
|
8
8
|
"main": "index.js",
|
|
9
9
|
"keywords": [],
|
|
@@ -3,13 +3,14 @@ import { createContext, useContext, useState, useEffect, useCallback } from 'rea
|
|
|
3
3
|
import { ConfigService } from '../core/ConfigService';
|
|
4
4
|
import { setConfigManagerConfig } from '../config';
|
|
5
5
|
const ConfigManagerContext = createContext(null);
|
|
6
|
-
|
|
7
|
-
configs,
|
|
8
|
-
children
|
|
9
|
-
}) => {
|
|
10
|
-
setConfigManagerConfig(configs);
|
|
6
|
+
const useConfigManagerValue = configManagerConfig => {
|
|
11
7
|
const [service] = useState(() => new ConfigService());
|
|
12
|
-
const [isLoading, setIsLoading] = useState(true)
|
|
8
|
+
const [isLoading, setIsLoading] = useState(true)
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
setConfigManagerConfig(configManagerConfig);
|
|
12
|
+
}, [configManagerConfig])
|
|
13
|
+
|
|
13
14
|
useEffect(() => {
|
|
14
15
|
const initialize = async () => {
|
|
15
16
|
setIsLoading(true);
|
|
@@ -49,21 +50,25 @@ export const ConfigManagerProvider = ({
|
|
|
49
50
|
const getConfig = useCallback(moduleName => {
|
|
50
51
|
return service.getConfig(moduleName);
|
|
51
52
|
}, [service]);
|
|
52
|
-
|
|
53
|
+
return {
|
|
53
54
|
get,
|
|
54
55
|
getConfig,
|
|
55
56
|
reloadConfig,
|
|
56
57
|
isLoading,
|
|
57
58
|
loadModuleConfig
|
|
58
59
|
};
|
|
60
|
+
};
|
|
61
|
+
export const ConfigManagerProvider = ({
|
|
62
|
+
configs,
|
|
63
|
+
children
|
|
64
|
+
}) => {
|
|
65
|
+
const value = useConfigManagerValue(configs);
|
|
59
66
|
return React.createElement(ConfigManagerContext.Provider, {
|
|
60
67
|
value: value
|
|
61
68
|
}, children);
|
|
62
69
|
};
|
|
63
70
|
export const useConfigManager = () => {
|
|
64
71
|
const context = useContext(ConfigManagerContext);
|
|
65
|
-
if (!context)
|
|
66
|
-
throw new Error('useConfigManager must be used within a ConfigManagerProvider');
|
|
67
|
-
}
|
|
72
|
+
if (!context) throw new Error('useConfigManager must be used within a ConfigManagerProvider');
|
|
68
73
|
return context;
|
|
69
74
|
};
|
|
@@ -1,85 +1,90 @@
|
|
|
1
|
+
// @arc-js/config-manager/providers/ConfigProvider.tsx
|
|
1
2
|
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
|
|
2
3
|
import { ConfigService } from '../core/ConfigService';
|
|
3
4
|
import { setConfigManagerConfig } from '../config';
|
|
4
5
|
import type { ConfigManagerConfig } from '../config';
|
|
5
6
|
|
|
6
|
-
const ConfigManagerContext = createContext<
|
|
7
|
+
const ConfigManagerContext = createContext<ReturnType<typeof useConfigManagerValue> | null>(null);
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
children,
|
|
14
|
-
}) => {
|
|
15
|
-
setConfigManagerConfig(configs);
|
|
16
|
-
|
|
17
|
-
const [service] = useState(() => new ConfigService());
|
|
18
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
9
|
+
const useConfigManagerValue = (
|
|
10
|
+
configManagerConfig: ConfigManagerConfig
|
|
11
|
+
) => {
|
|
12
|
+
const [service] = useState(() => new ConfigService());
|
|
13
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
19
14
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await service.initialize();
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error('Failed to initialize config manager:', error);
|
|
27
|
-
} finally {
|
|
28
|
-
setIsLoading(false);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
initialize();
|
|
32
|
-
}, [service]);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
setConfigManagerConfig(configManagerConfig);
|
|
18
|
+
}, [configManagerConfig]);
|
|
33
19
|
|
|
34
|
-
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
const initialize = async () => {
|
|
35
23
|
setIsLoading(true);
|
|
36
24
|
try {
|
|
37
|
-
await service.
|
|
25
|
+
await service.initialize();
|
|
38
26
|
} catch (error) {
|
|
39
|
-
console.error('Failed to
|
|
27
|
+
console.error('Failed to initialize config manager:', error);
|
|
40
28
|
} finally {
|
|
41
29
|
setIsLoading(false);
|
|
42
30
|
}
|
|
43
|
-
}
|
|
31
|
+
};
|
|
32
|
+
initialize();
|
|
33
|
+
}, [service]);
|
|
44
34
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
const reloadConfig = useCallback(async () => {
|
|
36
|
+
setIsLoading(true);
|
|
37
|
+
try {
|
|
38
|
+
await service.reload();
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Failed to reload config:', error);
|
|
41
|
+
} finally {
|
|
42
|
+
setIsLoading(false);
|
|
43
|
+
}
|
|
44
|
+
}, [service]);
|
|
55
45
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
const loadModuleConfig = useCallback(async (moduleName: string) => {
|
|
47
|
+
setIsLoading(true);
|
|
48
|
+
try {
|
|
49
|
+
await service.loadModule(moduleName);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(`Failed to load module config ${moduleName}:`, error);
|
|
52
|
+
} finally {
|
|
53
|
+
setIsLoading(false);
|
|
54
|
+
}
|
|
55
|
+
}, [service]);
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
const get = useCallback((key: string, options?: any) => {
|
|
58
|
+
return service.get(key, options);
|
|
59
|
+
}, [service]);
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
reloadConfig,
|
|
68
|
-
isLoading,
|
|
69
|
-
loadModuleConfig,
|
|
70
|
-
};
|
|
61
|
+
const getConfig = useCallback((moduleName?: string) => {
|
|
62
|
+
return service.getConfig(moduleName);
|
|
63
|
+
}, [service]);
|
|
71
64
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
65
|
+
return {
|
|
66
|
+
get,
|
|
67
|
+
getConfig,
|
|
68
|
+
reloadConfig,
|
|
69
|
+
isLoading,
|
|
70
|
+
loadModuleConfig,
|
|
77
71
|
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const ConfigManagerProvider: React.FC<{
|
|
75
|
+
children: React.ReactNode
|
|
76
|
+
configs: ConfigManagerConfig
|
|
77
|
+
}> = ({
|
|
78
|
+
configs,
|
|
79
|
+
children,
|
|
80
|
+
}) => {
|
|
81
|
+
const value = useConfigManagerValue(configs);
|
|
82
|
+
|
|
83
|
+
return <ConfigManagerContext.Provider value={value}>{children}</ConfigManagerContext.Provider>;
|
|
84
|
+
};
|
|
78
85
|
|
|
79
86
|
export const useConfigManager = () => {
|
|
80
87
|
const context = useContext(ConfigManagerContext);
|
|
81
|
-
if (!context)
|
|
82
|
-
throw new Error('useConfigManager must be used within a ConfigManagerProvider');
|
|
83
|
-
}
|
|
88
|
+
if (!context) throw new Error('useConfigManager must be used within a ConfigManagerProvider');
|
|
84
89
|
return context;
|
|
85
90
|
};
|
package/index.d.ts
DELETED
package/index.js
DELETED
package/index.min.js
DELETED