@hg-ts/config-loader 0.0.15
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/.eslintcache +1 -0
- package/.eslintrc.json +3 -0
- package/.mocharc.cjs +1 -0
- package/README.md +106 -0
- package/dist/config-loader.d.ts +18 -0
- package/dist/config-loader.d.ts.map +1 -0
- package/dist/config-loader.js +75 -0
- package/dist/config-loader.js.map +1 -0
- package/dist/decorators/enforce-env.decorator.d.ts +2 -0
- package/dist/decorators/enforce-env.decorator.d.ts.map +1 -0
- package/dist/decorators/enforce-env.decorator.js +9 -0
- package/dist/decorators/enforce-env.decorator.js.map +1 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/decorators/index.d.ts.map +1 -0
- package/dist/decorators/index.js +5 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/exceptions/index.d.ts +2 -0
- package/dist/exceptions/index.d.ts.map +1 -0
- package/dist/exceptions/index.js +5 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/exceptions/no-base-config.exception.d.ts +5 -0
- package/dist/exceptions/no-base-config.exception.d.ts.map +1 -0
- package/dist/exceptions/no-base-config.exception.js +11 -0
- package/dist/exceptions/no-base-config.exception.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/path-builder.d.ts +22 -0
- package/dist/path-builder.d.ts.map +1 -0
- package/dist/path-builder.js +79 -0
- package/dist/path-builder.js.map +1 -0
- package/dist/tests/config-loader.test-suite.d.ts +7 -0
- package/dist/tests/config-loader.test-suite.d.ts.map +1 -0
- package/dist/tests/config-loader.test-suite.js +94 -0
- package/dist/tests/config-loader.test-suite.js.map +1 -0
- package/dist/tests/path-builder.test-suite.d.ts +15 -0
- package/dist/tests/path-builder.test-suite.d.ts.map +1 -0
- package/dist/tests/path-builder.test-suite.js +155 -0
- package/dist/tests/path-builder.test-suite.js.map +1 -0
- package/dist-esm/config-loader.d.ts +18 -0
- package/dist-esm/config-loader.d.ts.map +1 -0
- package/dist-esm/config-loader.js +70 -0
- package/dist-esm/config-loader.js.map +1 -0
- package/dist-esm/decorators/enforce-env.decorator.d.ts +2 -0
- package/dist-esm/decorators/enforce-env.decorator.d.ts.map +1 -0
- package/dist-esm/decorators/enforce-env.decorator.js +5 -0
- package/dist-esm/decorators/enforce-env.decorator.js.map +1 -0
- package/dist-esm/decorators/index.d.ts +2 -0
- package/dist-esm/decorators/index.d.ts.map +1 -0
- package/dist-esm/decorators/index.js +2 -0
- package/dist-esm/decorators/index.js.map +1 -0
- package/dist-esm/exceptions/index.d.ts +2 -0
- package/dist-esm/exceptions/index.d.ts.map +1 -0
- package/dist-esm/exceptions/index.js +2 -0
- package/dist-esm/exceptions/index.js.map +1 -0
- package/dist-esm/exceptions/no-base-config.exception.d.ts +5 -0
- package/dist-esm/exceptions/no-base-config.exception.d.ts.map +1 -0
- package/dist-esm/exceptions/no-base-config.exception.js +7 -0
- package/dist-esm/exceptions/no-base-config.exception.js.map +1 -0
- package/dist-esm/index.d.ts +4 -0
- package/dist-esm/index.d.ts.map +1 -0
- package/dist-esm/index.js +4 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/path-builder.d.ts +22 -0
- package/dist-esm/path-builder.d.ts.map +1 -0
- package/dist-esm/path-builder.js +75 -0
- package/dist-esm/path-builder.js.map +1 -0
- package/dist-esm/tests/config-loader.test-suite.d.ts +7 -0
- package/dist-esm/tests/config-loader.test-suite.d.ts.map +1 -0
- package/dist-esm/tests/config-loader.test-suite.js +91 -0
- package/dist-esm/tests/config-loader.test-suite.js.map +1 -0
- package/dist-esm/tests/path-builder.test-suite.d.ts +15 -0
- package/dist-esm/tests/path-builder.test-suite.d.ts.map +1 -0
- package/dist-esm/tests/path-builder.test-suite.js +152 -0
- package/dist-esm/tests/path-builder.test-suite.js.map +1 -0
- package/package.json +45 -0
- package/src/config-loader.ts +103 -0
- package/src/decorators/enforce-env.decorator.ts +5 -0
- package/src/decorators/index.ts +1 -0
- package/src/exceptions/index.ts +1 -0
- package/src/exceptions/no-base-config.exception.ts +7 -0
- package/src/index.ts +4 -0
- package/src/path-builder.ts +158 -0
- package/src/tests/config-loader.test-suite.ts +87 -0
- package/src/tests/path-builder.test-suite.ts +133 -0
- package/tsconfig.esm.json +10 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Describe,
|
|
3
|
+
expect,
|
|
4
|
+
Test,
|
|
5
|
+
TestSuite,
|
|
6
|
+
} from '@hg-ts/tests';
|
|
7
|
+
import {
|
|
8
|
+
ExecutionModeVariants,
|
|
9
|
+
MockExecutionMode,
|
|
10
|
+
} from '@hg-ts/execution-mode';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
PathBuilder,
|
|
14
|
+
PathBuilderOptions,
|
|
15
|
+
} from '../path-builder';
|
|
16
|
+
|
|
17
|
+
@Describe()
|
|
18
|
+
export class PathBuilderTestSuite extends TestSuite {
|
|
19
|
+
@Test()
|
|
20
|
+
public async simple(): Promise<void> {
|
|
21
|
+
const paths = this.getPaths();
|
|
22
|
+
|
|
23
|
+
expect(paths).toHaveLength(1);
|
|
24
|
+
expect(paths[0]).toBe('/tmp/example.json');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Test()
|
|
28
|
+
public async recursive(): Promise<void> {
|
|
29
|
+
const paths = this.getPaths({ recursive: true });
|
|
30
|
+
|
|
31
|
+
expect(paths).toHaveLength(2);
|
|
32
|
+
expect(paths[0]).toBe('/tmp/example.json');
|
|
33
|
+
expect(paths[1]).toBe('/example.json');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Test()
|
|
37
|
+
public async full(): Promise<void> {
|
|
38
|
+
const paths = this.getPaths({
|
|
39
|
+
recursive: true,
|
|
40
|
+
overridePostfix: 'override',
|
|
41
|
+
basePostfix: 'config',
|
|
42
|
+
envBuilder: true,
|
|
43
|
+
overrideEnv: new MockExecutionMode(ExecutionModeVariants.DEMO),
|
|
44
|
+
configDir: 'config',
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
let index = 0;
|
|
48
|
+
|
|
49
|
+
expect(paths).toHaveLength(12);
|
|
50
|
+
expect(paths[index++]).toBe('/tmp/config/base/example.config.json');
|
|
51
|
+
expect(paths[index++]).toBe('/tmp/config/base/example.override.json');
|
|
52
|
+
expect(paths[index++]).toBe('/tmp/config/demo/example.config.json');
|
|
53
|
+
expect(paths[index++]).toBe('/tmp/config/demo/example.override.json');
|
|
54
|
+
expect(paths[index++]).toBe('/tmp/config/local/example.config.json');
|
|
55
|
+
expect(paths[index++]).toBe('/tmp/config/local/example.override.json');
|
|
56
|
+
|
|
57
|
+
expect(paths[index++]).toBe('/config/base/example.config.json');
|
|
58
|
+
expect(paths[index++]).toBe('/config/base/example.override.json');
|
|
59
|
+
expect(paths[index++]).toBe('/config/demo/example.config.json');
|
|
60
|
+
expect(paths[index++]).toBe('/config/demo/example.override.json');
|
|
61
|
+
expect(paths[index++]).toBe('/config/local/example.config.json');
|
|
62
|
+
expect(paths[index++]).toBe('/config/local/example.override.json');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Test()
|
|
66
|
+
public async configDir(): Promise<void> {
|
|
67
|
+
const paths = this.getPaths({ configDir: 'config' });
|
|
68
|
+
|
|
69
|
+
expect(paths).toHaveLength(1);
|
|
70
|
+
expect(paths[0]).toBe('/tmp/config/example.json');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test()
|
|
74
|
+
public async envBuilder(): Promise<void> {
|
|
75
|
+
const paths = this.getPaths({ envBuilder: true });
|
|
76
|
+
|
|
77
|
+
expect(paths).toHaveLength(2);
|
|
78
|
+
expect(paths[0]).toBe('/tmp/base/example.json');
|
|
79
|
+
expect(paths[1]).toBe('/tmp/local/example.json');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Test()
|
|
83
|
+
public async envBuilderWithOverrideProd(): Promise<void> {
|
|
84
|
+
const paths = this.getPaths({ envBuilder: true, overrideEnv: new MockExecutionMode(ExecutionModeVariants.PROD) });
|
|
85
|
+
|
|
86
|
+
expect(paths).toHaveLength(3);
|
|
87
|
+
expect(paths[0]).toBe('/tmp/base/example.json');
|
|
88
|
+
expect(paths[1]).toBe('/tmp/prod/example.json');
|
|
89
|
+
expect(paths[2]).toBe('/tmp/local/example.json');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Test()
|
|
93
|
+
public async envBuilderWithOverrideDev(): Promise<void> {
|
|
94
|
+
const paths = this.getPaths({ envBuilder: true, overrideEnv: new MockExecutionMode(ExecutionModeVariants.DEV) });
|
|
95
|
+
|
|
96
|
+
expect(paths).toHaveLength(3);
|
|
97
|
+
expect(paths[0]).toBe('/tmp/base/example.json');
|
|
98
|
+
expect(paths[1]).toBe('/tmp/dev/example.json');
|
|
99
|
+
expect(paths[2]).toBe('/tmp/local/example.json');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Test()
|
|
103
|
+
public async basePostfix(): Promise<void> {
|
|
104
|
+
const paths = this.getPaths({ basePostfix: 'config' });
|
|
105
|
+
|
|
106
|
+
expect(paths).toHaveLength(1);
|
|
107
|
+
expect(paths[0]).toBe('/tmp/example.config.json');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Test()
|
|
111
|
+
public async basePostfixWithOverridePostfix(): Promise<void> {
|
|
112
|
+
const paths = this.getPaths({ basePostfix: 'config', overridePostfix: 'override' });
|
|
113
|
+
|
|
114
|
+
expect(paths).toHaveLength(2);
|
|
115
|
+
expect(paths[0]).toBe('/tmp/example.config.json');
|
|
116
|
+
expect(paths[1]).toBe('/tmp/example.override.json');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
@Test()
|
|
120
|
+
public async overridePostfix(): Promise<void> {
|
|
121
|
+
const paths = this.getPaths({ overridePostfix: 'override' });
|
|
122
|
+
|
|
123
|
+
expect(paths).toHaveLength(2);
|
|
124
|
+
expect(paths[0]).toBe('/tmp/example.json');
|
|
125
|
+
expect(paths[1]).toBe('/tmp/example.override.json');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private getPaths(options: Omit<PathBuilderOptions, 'appPath'> = {}): string[] {
|
|
129
|
+
const builder = new PathBuilder({ appPath: '/tmp', ...options });
|
|
130
|
+
|
|
131
|
+
return builder.build('example');
|
|
132
|
+
}
|
|
133
|
+
}
|