@incanta/config 0.1.6 → 0.1.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.
package/lib/config-env.js CHANGED
@@ -7,10 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const child_process_1 = require("child_process");
8
8
  const lodash_merge_1 = __importDefault(require("lodash.merge"));
9
9
  const index_1 = __importDefault(require("./index"));
10
- const command = process.argv
11
- .slice(2)
12
- .map((arg) => `"${arg}"`)
13
- .join(" ");
10
+ const command = process.argv.slice(2).join(" ");
14
11
  const env = {};
15
12
  (0, lodash_merge_1.default)(env, process.env, index_1.default.getConfiguredEnv());
16
13
  (0, child_process_1.execSync)(command, {
@@ -1 +1 @@
1
- {"version":3,"file":"config-env.js","sourceRoot":"","sources":["../src/config-env.ts"],"names":[],"mappings":";;;;;;AAEA,iDAAyC;AACzC,gEAAiC;AACjC,oDAA6B;AAE7B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI;KACzB,KAAK,CAAC,CAAC,CAAC;KACR,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,GAAG,GAAG,CAAC;KACxB,IAAI,CAAC,GAAG,CAAC,CAAC;AAEb,MAAM,GAAG,GAAQ,EAAE,CAAC;AAEpB,IAAA,sBAAK,EAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,eAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;AAEnD,IAAA,wBAAQ,EAAC,OAAO,EAAE;IAChB,GAAG;IACH,KAAK,EAAE,SAAS;CACjB,CAAC,CAAC"}
1
+ {"version":3,"file":"config-env.js","sourceRoot":"","sources":["../src/config-env.ts"],"names":[],"mappings":";;;;;;AAEA,iDAAyC;AACzC,gEAAiC;AACjC,oDAA6B;AAE7B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEhD,MAAM,GAAG,GAAQ,EAAE,CAAC;AAEpB,IAAA,sBAAK,EAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,eAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC;AAEnD,IAAA,wBAAQ,EAAC,OAAO,EAAE;IAChB,GAAG;IACH,KAAK,EAAE,SAAS;CACjB,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@incanta/config",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "main": "lib/index.js",
5
5
  "exports": {
6
6
  ".": "./lib/index.js",
package/src/config-env.ts CHANGED
@@ -4,10 +4,7 @@ import { execSync } from "child_process";
4
4
  import merge from "lodash.merge";
5
5
  import config from "./index";
6
6
 
7
- const command = process.argv
8
- .slice(2)
9
- .map((arg) => `"${arg}"`)
10
- .join(" ");
7
+ const command = process.argv.slice(2).join(" ");
11
8
 
12
9
  const env: any = {};
13
10
 
package/src/config.ts CHANGED
@@ -127,17 +127,48 @@ export class Config {
127
127
  obj = obj[part];
128
128
  }
129
129
 
130
+ const variableRegex = /\$\{[a-zA-Z\-_0-9.]+\}/g;
131
+
132
+ const replaceValue = (value: string): void => {
133
+ const regexResult = value.matchAll(variableRegex);
134
+ for (const match of regexResult) {
135
+ const keyToReplace = match[0].slice(2, match[0].length - 1);
136
+ const value = this.tryGet<string | number | boolean>(keyToReplace);
137
+ if (value !== null) {
138
+ obj = obj.replace(match[0], `${value}`);
139
+ }
140
+ }
141
+ };
142
+
143
+ // replace all ${value} with the value from the config
144
+ if (typeof obj === "string") {
145
+ replaceValue(obj);
146
+ } else if (typeof obj === "object") {
147
+ // walk the object and replace all strings with the value from the config
148
+ const walkObject = (curObj: any): void => {
149
+ for (const property of Object.keys(curObj)) {
150
+ const value = curObj[property];
151
+ if (typeof value === "string") {
152
+ replaceValue(value);
153
+ } else if (typeof value === "object") {
154
+ walkObject(value);
155
+ }
156
+ }
157
+ };
158
+
159
+ walkObject(obj);
160
+ }
161
+
130
162
  return obj as T;
131
163
  }
132
164
 
133
- public has(key: string): boolean {
165
+ public tryGet<T>(key: string): T | null {
134
166
  try {
135
- this.get(key);
167
+ const value = this.get<T>(key);
168
+ return value;
136
169
  } catch {
137
- return false;
170
+ return null;
138
171
  }
139
-
140
- return true;
141
172
  }
142
173
 
143
174
  public set<T>(key: string, value: T): void {