@arc-js/config-manager 0.0.6 → 0.0.8

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.
@@ -109,7 +109,9 @@ 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);
112
113
  const modules = yield loadModulesConfigs();
114
+ console.log('Modules configs loaded:', modules);
113
115
  this.resources = modules.reduce((acc, { moduleName, config }) => {
114
116
  return mergeDeep(acc, { [moduleName]: config });
115
117
  }, { base });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.6",
6
+ "version": "0.0.8",
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,14 +3,15 @@ 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
- const useConfigManagerValue = configManagerConfig => {
6
+ export const ConfigManagerProvider = ({
7
+ configs,
8
+ children
9
+ }) => {
7
10
  const [service] = useState(() => new ConfigService());
8
- const [isLoading, setIsLoading] = useState(true)
9
-
11
+ const [isLoading, setIsLoading] = useState(true);
10
12
  useEffect(() => {
11
- setConfigManagerConfig(configManagerConfig);
12
- }, [configManagerConfig])
13
-
13
+ setConfigManagerConfig(configs);
14
+ }, [configs]);
14
15
  useEffect(() => {
15
16
  const initialize = async () => {
16
17
  setIsLoading(true);
@@ -50,25 +51,21 @@ const useConfigManagerValue = configManagerConfig => {
50
51
  const getConfig = useCallback(moduleName => {
51
52
  return service.getConfig(moduleName);
52
53
  }, [service]);
53
- return {
54
+ const value = {
54
55
  get,
55
56
  getConfig,
56
57
  reloadConfig,
57
58
  isLoading,
58
59
  loadModuleConfig
59
60
  };
60
- };
61
- export const ConfigManagerProvider = ({
62
- configs,
63
- children
64
- }) => {
65
- const value = useConfigManagerValue(configs);
66
61
  return React.createElement(ConfigManagerContext.Provider, {
67
62
  value: value
68
63
  }, children);
69
64
  };
70
65
  export const useConfigManager = () => {
71
66
  const context = useContext(ConfigManagerContext);
72
- if (!context) throw new Error('useConfigManager must be used within a ConfigManagerProvider');
67
+ if (!context) {
68
+ throw new Error('useConfigManager must be used within a ConfigManagerProvider');
69
+ }
73
70
  return context;
74
71
  };
@@ -3,87 +3,85 @@ import { ConfigService } from '../core/ConfigService';
3
3
  import { setConfigManagerConfig } from '../config';
4
4
  import type { ConfigManagerConfig } from '../config';
5
5
 
6
- const ConfigManagerContext = createContext<ReturnType<typeof useConfigManagerValue> | null>(null);
6
+ const ConfigManagerContext = createContext<any>(null);
7
7
 
8
- const useConfigManagerValue = (
9
- configManagerConfig: ConfigManagerConfig
10
- ) => {
11
- const [service] = useState(() => new ConfigService());
12
- const [isLoading, setIsLoading] = useState(true);
8
+ export const ConfigManagerProvider: React.FC<{
9
+ children: React.ReactNode
10
+ configs: ConfigManagerConfig
11
+ }> = ({
12
+ configs,
13
+ children,
14
+ }) => {
15
+ const [service] = useState(() => new ConfigService());
16
+ const [isLoading, setIsLoading] = useState(true);
17
+
18
+ useEffect(() => {
19
+ setConfigManagerConfig(configs);
20
+ }, [configs]);
13
21
 
14
-
15
- useEffect(() => {
16
- setConfigManagerConfig(configManagerConfig);
17
- }, [configManagerConfig]);
22
+ useEffect(() => {
23
+ const initialize = async () => {
24
+ setIsLoading(true);
25
+ try {
26
+ await service.initialize();
27
+ } catch (error) {
28
+ console.error('Failed to initialize config manager:', error);
29
+ } finally {
30
+ setIsLoading(false);
31
+ }
32
+ };
33
+ initialize();
34
+ }, [service]);
18
35
 
19
-
20
- useEffect(() => {
21
- const initialize = async () => {
36
+ const reloadConfig = useCallback(async () => {
22
37
  setIsLoading(true);
23
38
  try {
24
- await service.initialize();
39
+ await service.reload();
25
40
  } catch (error) {
26
- console.error('Failed to initialize config manager:', error);
41
+ console.error('Failed to reload config:', error);
27
42
  } finally {
28
43
  setIsLoading(false);
29
44
  }
30
- };
31
- initialize();
32
- }, [service]);
45
+ }, [service]);
33
46
 
34
- const reloadConfig = useCallback(async () => {
35
- setIsLoading(true);
36
- try {
37
- await service.reload();
38
- } catch (error) {
39
- console.error('Failed to reload config:', error);
40
- } finally {
41
- setIsLoading(false);
42
- }
43
- }, [service]);
47
+ const loadModuleConfig = useCallback(async (moduleName: string) => {
48
+ setIsLoading(true);
49
+ try {
50
+ await service.loadModule(moduleName);
51
+ } catch (error) {
52
+ console.error(`Failed to load module config ${moduleName}:`, error);
53
+ } finally {
54
+ setIsLoading(false);
55
+ }
56
+ }, [service]);
44
57
 
45
- const loadModuleConfig = useCallback(async (moduleName: string) => {
46
- setIsLoading(true);
47
- try {
48
- await service.loadModule(moduleName);
49
- } catch (error) {
50
- console.error(`Failed to load module config ${moduleName}:`, error);
51
- } finally {
52
- setIsLoading(false);
53
- }
54
- }, [service]);
58
+ const get = useCallback((key: string, options?: any) => {
59
+ return service.get(key, options);
60
+ }, [service]);
55
61
 
56
- const get = useCallback((key: string, options?: any) => {
57
- return service.get(key, options);
58
- }, [service]);
62
+ const getConfig = useCallback((moduleName?: string) => {
63
+ return service.getConfig(moduleName);
64
+ }, [service]);
59
65
 
60
- const getConfig = useCallback((moduleName?: string) => {
61
- return service.getConfig(moduleName);
62
- }, [service]);
66
+ const value = {
67
+ get,
68
+ getConfig,
69
+ reloadConfig,
70
+ isLoading,
71
+ loadModuleConfig,
72
+ };
63
73
 
64
- return {
65
- get,
66
- getConfig,
67
- reloadConfig,
68
- isLoading,
69
- loadModuleConfig,
74
+ return (
75
+ <ConfigManagerContext.Provider value={value}>
76
+ {children}
77
+ </ConfigManagerContext.Provider>
78
+ );
70
79
  };
71
- };
72
-
73
- export const ConfigManagerProvider: React.FC<{
74
- children: React.ReactNode
75
- configs: ConfigManagerConfig
76
- }> = ({
77
- configs,
78
- children,
79
- }) => {
80
- const value = useConfigManagerValue(configs);
81
-
82
- return <ConfigManagerContext.Provider value={value}>{children}</ConfigManagerContext.Provider>;
83
- };
84
80
 
85
81
  export const useConfigManager = () => {
86
82
  const context = useContext(ConfigManagerContext);
87
- if (!context) throw new Error('useConfigManager must be used within a ConfigManagerProvider');
83
+ if (!context) {
84
+ throw new Error('useConfigManager must be used within a ConfigManagerProvider');
85
+ }
88
86
  return context;
89
87
  };