@yumerijs/loader 2.1.0 → 2.1.1
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.js +21 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,11 +69,22 @@ class PluginLoader {
|
|
|
69
69
|
async reloadConfigFile() {
|
|
70
70
|
this.logger.info('Reloading config file...');
|
|
71
71
|
try {
|
|
72
|
-
const
|
|
72
|
+
const ext = path.extname(this.configPath).toLowerCase();
|
|
73
|
+
const fileContent = fs.readFileSync(this.configPath, 'utf8');
|
|
74
|
+
let doc;
|
|
75
|
+
if (ext === '.yaml' || ext === '.yml') {
|
|
76
|
+
doc = yaml.load(fileContent);
|
|
77
|
+
}
|
|
78
|
+
else if (ext === '.json') {
|
|
79
|
+
doc = JSON.parse(fileContent);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
throw new Error(`Unsupported config file extension: ${ext}`);
|
|
83
|
+
}
|
|
73
84
|
this.config = doc;
|
|
74
85
|
this.core.coreConfig = this.config.core || {};
|
|
75
86
|
this.core.emit('config-reloaded', this.config);
|
|
76
|
-
this.logger.info('Config file reloaded.');
|
|
87
|
+
this.logger.info('Config file reloaded successfully.');
|
|
77
88
|
}
|
|
78
89
|
catch (e) {
|
|
79
90
|
this.logger.error('Failed to reload config file:', e);
|
|
@@ -98,7 +109,14 @@ class PluginLoader {
|
|
|
98
109
|
async loadConfig(configPath) {
|
|
99
110
|
try {
|
|
100
111
|
this.configPath = configPath;
|
|
101
|
-
const
|
|
112
|
+
const fileContents = fs.readFileSync(configPath, 'utf8');
|
|
113
|
+
let doc;
|
|
114
|
+
if (path.extname(configPath) === '.json') {
|
|
115
|
+
doc = JSON.parse(fileContents);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
doc = yaml.load(fileContents);
|
|
119
|
+
}
|
|
102
120
|
this.config = doc;
|
|
103
121
|
this.logger.info('Config loaded.');
|
|
104
122
|
this.core.coreConfig = this.config.core || {};
|