@dsmrt/axiom-config 0.1.0 → 0.2.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/CHANGELOG.md +12 -0
- package/README.md +1 -1
- package/package.json +3 -3
- package/lib/index.js +0 -74
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<picture>
|
|
2
2
|
<source media="(prefers-color-scheme: dark)" srcset="../images/axiom-dark-mode.svg">
|
|
3
3
|
<source media="(prefers-color-scheme: light)" srcset="../images/axiom-light-mode.svg">
|
|
4
|
-
<img alt="Axiom logo" src="
|
|
4
|
+
<img alt="Axiom logo" src="../images/axiom-light-mode.svg">
|
|
5
5
|
</picture>
|
|
6
6
|
|
|
7
7
|
# Axiom - Config
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsmrt/axiom-config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Config library for axiom cli",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"@types/yargs": "^17.0.31",
|
|
30
30
|
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
31
31
|
"@typescript-eslint/parser": "^6.12.0",
|
|
32
|
-
"@vitest/coverage-v8": "^0.34.6",
|
|
33
32
|
"eslint": "^8.54.0",
|
|
34
33
|
"prettier": "^3.1.0",
|
|
35
34
|
"ts-node": "^10.9.1",
|
|
36
35
|
"tsup": "^8.0.1",
|
|
37
36
|
"typescript": "^5.2.2",
|
|
38
|
-
"vitest": "^
|
|
37
|
+
"@vitest/coverage-v8": "^1.2.1",
|
|
38
|
+
"vitest": "^1.2.1"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"find-up": "^5.0.0",
|
package/lib/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configPath = exports.mergeDeep = exports.isObject = exports.loadConfig = exports.importConfigFromPath = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const find_up_1 = require("find-up");
|
|
6
|
-
// TODO - Add validation here
|
|
7
|
-
const importConfigFromPath = (path) => {
|
|
8
|
-
if (/\.json$/.test(path)) {
|
|
9
|
-
return JSON.parse((0, fs_1.readFileSync)(path).toString());
|
|
10
|
-
}
|
|
11
|
-
if (/\.(m)?[j|t]s$/.test(path)) {
|
|
12
|
-
/* eslint-disable */
|
|
13
|
-
return require(path);
|
|
14
|
-
}
|
|
15
|
-
throw new Error(`Path not found: {path}`);
|
|
16
|
-
};
|
|
17
|
-
exports.importConfigFromPath = importConfigFromPath;
|
|
18
|
-
const loadConfig = (input) => {
|
|
19
|
-
// get the base file
|
|
20
|
-
const baseConfigFile = (0, exports.configPath)(input);
|
|
21
|
-
const baseConfig = (0, exports.importConfigFromPath)(baseConfigFile);
|
|
22
|
-
let overrides = input?.overrides || {};
|
|
23
|
-
// get the environment file
|
|
24
|
-
if (input?.env) {
|
|
25
|
-
const devConfig = (0, exports.importConfigFromPath)((0, exports.configPath)(input));
|
|
26
|
-
overrides = mergeDeep(devConfig, overrides);
|
|
27
|
-
}
|
|
28
|
-
// merge env file
|
|
29
|
-
return mergeDeep(baseConfig, overrides);
|
|
30
|
-
};
|
|
31
|
-
exports.loadConfig = loadConfig;
|
|
32
|
-
/**
|
|
33
|
-
* Simple object check.
|
|
34
|
-
*/
|
|
35
|
-
function isObject(item) {
|
|
36
|
-
return item && typeof item === "object" && !Array.isArray(item);
|
|
37
|
-
}
|
|
38
|
-
exports.isObject = isObject;
|
|
39
|
-
/**
|
|
40
|
-
* Deep merge two objects.
|
|
41
|
-
*/
|
|
42
|
-
function mergeDeep(target, ...sources) {
|
|
43
|
-
if (!sources.length)
|
|
44
|
-
return target;
|
|
45
|
-
const source = sources.shift();
|
|
46
|
-
if (isObject(target) && isObject(source)) {
|
|
47
|
-
for (const key in source) {
|
|
48
|
-
if (isObject(source[key])) {
|
|
49
|
-
if (!target[key])
|
|
50
|
-
Object.assign(target, { [key]: {} });
|
|
51
|
-
mergeDeep(target[key], source[key]);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
Object.assign(target, { [key]: source[key] });
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return mergeDeep(target, ...sources);
|
|
59
|
-
}
|
|
60
|
-
exports.mergeDeep = mergeDeep;
|
|
61
|
-
const configPath = (input) => {
|
|
62
|
-
const envIndicator = input?.env ? `.${input.env}` : "";
|
|
63
|
-
const p = (0, find_up_1.sync)([
|
|
64
|
-
`.axiom${envIndicator}.json`,
|
|
65
|
-
`.axiom${envIndicator}.js`,
|
|
66
|
-
`.axiom${envIndicator}.mjs`,
|
|
67
|
-
`.axiom${envIndicator}.ts`,
|
|
68
|
-
`.axiom${envIndicator}.mts`,
|
|
69
|
-
], { cwd: input?.cwd });
|
|
70
|
-
if (p === undefined)
|
|
71
|
-
throw new Error(`Axiom config files not found: .axiom${envIndicator}.json, .axiom${envIndicator}.js .axiom${envIndicator}.ts`);
|
|
72
|
-
return p;
|
|
73
|
-
};
|
|
74
|
-
exports.configPath = configPath;
|