configre 1.0.8 → 1.1.0
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/demo/module/config/hostname.js +1 -1
- package/demo/module/config/index.js +1 -1
- package/demo/module/demo.js +1 -1
- package/index.mjs +3 -44
- package/package.json +1 -1
package/demo/module/demo.js
CHANGED
package/index.mjs
CHANGED
|
@@ -1,53 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createRequire } from "module";
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import { dirname } from "path";
|
|
4
|
-
import { pathToFileURL } from "url";
|
|
5
|
-
import { createRequire } from "module";
|
|
6
4
|
|
|
7
5
|
const require = createRequire(import.meta.url);
|
|
8
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
7
|
const __dirname = dirname(__filename);
|
|
10
|
-
const log = lemonlog("Configre");
|
|
11
|
-
const ConfigreCore = require("./core.js");
|
|
12
|
-
|
|
13
|
-
class ConfigreClass {
|
|
14
|
-
constructor(path = __dirname + "/../../config") {
|
|
15
|
-
this.core = new ConfigreCore(path, log);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async loadDefaultSettings() {
|
|
19
|
-
const { indexFile } = this.core.getFiles();
|
|
20
|
-
const module = await import(pathToFileURL(indexFile).href);
|
|
21
|
-
return module.default;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async loadProfileSettings() {
|
|
25
|
-
const { devFile, localFile } = this.core.getFiles();
|
|
26
|
-
|
|
27
|
-
if (this.core.checkFileExists(devFile)) {
|
|
28
|
-
this.core.logConfig(devFile, "DEV CONFIG");
|
|
29
|
-
const module = await import(pathToFileURL(devFile).href);
|
|
30
|
-
return module.default;
|
|
31
|
-
} else if (this.core.checkFileExists(localFile)) {
|
|
32
|
-
this.core.logConfig(localFile, "PRO CONFIG");
|
|
33
|
-
const module = await import(pathToFileURL(localFile).href);
|
|
34
|
-
return module.default;
|
|
35
|
-
} else {
|
|
36
|
-
this.core.logConfig(localFile, "NOT FOUND, USING DEFAULTS");
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async get() {
|
|
42
|
-
const defaultSettings = await this.loadDefaultSettings();
|
|
43
|
-
const profileSettings = await this.loadProfileSettings();
|
|
44
|
-
return this.core.merge(defaultSettings, profileSettings);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
8
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
return await new ConfigreClass(path).get();
|
|
51
|
-
}
|
|
9
|
+
// Simplemente re-exportar la versión CommonJS que ya funciona síncronamente
|
|
10
|
+
const Configre = require("./index.js");
|
|
52
11
|
|
|
53
12
|
export default Configre;
|