configre 1.2.0 → 1.2.2

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.
Files changed (2) hide show
  1. package/index.js +20 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,20 +1,27 @@
1
1
  const fs = require("fs");
2
+ const path = require("path");
2
3
  const os = require("os");
3
4
  const obj = require("lodash/object");
4
5
  const log = require("lemonlog")("Configre");
5
6
 
6
7
  class ConfigreClass {
7
- constructor(path = __dirname + "/../../config") {
8
+ constructor(pathOrDir = __dirname + "/../../config") {
9
+ const dir = path.join(pathOrDir);
10
+ const isNested = (ConfigreClass._nesting || 0) > 0;
11
+ ConfigreClass._nesting = (ConfigreClass._nesting || 0) + 1;
12
+
8
13
  this.defaultSettings = this.tryRequire([
9
- path,
10
- path + '/index.cjs',
11
- path + '.cjs'
14
+ dir,
15
+ path.join(dir, "index.cjs"),
16
+ pathOrDir + ".cjs"
12
17
  ]);
13
-
14
- this.dirname = path;
18
+
19
+ this.dirname = dir;
20
+ this._isNested = isNested;
15
21
  const configArg = process.argv.find(arg => arg.startsWith('--config='));
16
22
  this.profile = configArg ? configArg.slice('--config='.length) : os.hostname();
17
23
  this.profileSettings = this.loadProfileSettings();
24
+ ConfigreClass._nesting -= 1;
18
25
  }
19
26
 
20
27
  // Helper method to try requiring files with different extensions or paths
@@ -32,7 +39,7 @@ class ConfigreClass {
32
39
  // Helper method to try loading a file with .cjs extension only
33
40
  tryRequireWithExtensions(basePath) {
34
41
  const ext = '.cjs';
35
- const fullPath = basePath + ext;
42
+ const fullPath = path.join(basePath + ext);
36
43
  if (fs.existsSync(fullPath)) {
37
44
  return { path: fullPath, module: require(fullPath) };
38
45
  }
@@ -41,19 +48,21 @@ class ConfigreClass {
41
48
 
42
49
  loadProfileSettings() {
43
50
  const basePaths = [
44
- { base: `${this.dirname}/${this.profile}.dev`, type: "DEV CONFIG" },
45
- { base: `${this.dirname}/${this.profile}`, type: "PRO CONFIG" }
51
+ { base: path.join(this.dirname, `${this.profile}.dev`), type: "DEV CONFIG" },
52
+ { base: path.join(this.dirname, this.profile), type: "PRO CONFIG" }
46
53
  ];
47
54
 
48
55
  for (const { base, type } of basePaths) {
49
56
  const result = this.tryRequireWithExtensions(base);
50
57
  if (result) {
51
- log.warn(result.path, type);
58
+ if (!this._isNested) log.warn(result.path, type);
52
59
  return result.module;
53
60
  }
54
61
  }
55
62
 
56
- log.warn(`${this.dirname}/${this.profile}.cjs`, "NOT FOUND, USING DEFAULTS");
63
+ if (!this._isNested) {
64
+ log.warn(path.join(this.dirname, `${this.profile}.cjs`), "NOT FOUND, USING DEFAULTS");
65
+ }
57
66
  return {};
58
67
  }
59
68
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configre",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "🔧 Effortlessly Tailor Your Settings",
5
5
  "dependencies": {
6
6
  "lemonlog": "^1.0.2",