@kibibit/configit 1.0.0-beta.2 → 1.0.0-beta.20
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/README.md +89 -19
- package/lib/config.model.d.ts +14 -3
- package/lib/config.model.d.ts.map +1 -1
- package/lib/config.model.js +70 -22
- package/lib/config.model.js.map +1 -1
- package/lib/config.service.d.ts +37 -7
- package/lib/config.service.d.ts.map +1 -1
- package/lib/config.service.js +271 -41
- package/lib/config.service.js.map +1 -1
- package/lib/environment.service.d.ts +3 -0
- package/lib/environment.service.d.ts.map +1 -0
- package/lib/environment.service.js +15 -0
- package/lib/environment.service.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -1
- package/lib/index.js.map +1 -1
- package/lib/json-schema.validator.d.ts +4 -4
- package/lib/json-schema.validator.d.ts.map +1 -1
- package/lib/json-schema.validator.js +19 -2
- package/lib/json-schema.validator.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +48 -33
- package/src/__snapshots__/config.errors.spec.ts.snap +12 -0
- package/src/__snapshots__/config.model.spec.ts.snap +22 -0
- package/src/__snapshots__/config.service.spec.ts.snap +314 -0
- package/src/config.errors.spec.ts +26 -0
- package/src/config.model.spec.ts +52 -0
- package/src/config.model.ts +85 -23
- package/src/config.service.spec.ts +319 -0
- package/src/config.service.ts +381 -55
- package/src/environment.service.ts +13 -0
- package/src/index.ts +1 -0
- package/src/json-schema.validator.ts +29 -1
- package/src/pizza.config.model.mock.ts +33 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Config Service Service can SAVE the config files with saveToFile or init param 1`] = `
|
|
4
|
+
Array [
|
|
5
|
+
"/.schemas/pizza.env.schema.json",
|
|
6
|
+
Object {
|
|
7
|
+
"properties": Object {
|
|
8
|
+
"toppings": Object {
|
|
9
|
+
"description": "optional toppings for the pizza",
|
|
10
|
+
"items": Object {
|
|
11
|
+
"enum": Array [
|
|
12
|
+
"cheese",
|
|
13
|
+
"pepperoni",
|
|
14
|
+
"sausage",
|
|
15
|
+
],
|
|
16
|
+
"type": "string",
|
|
17
|
+
},
|
|
18
|
+
"type": "array",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
"required": Array [],
|
|
22
|
+
"type": "object",
|
|
23
|
+
},
|
|
24
|
+
Object {
|
|
25
|
+
"spaces": 2,
|
|
26
|
+
},
|
|
27
|
+
]
|
|
28
|
+
`;
|
|
29
|
+
|
|
30
|
+
exports[`Config Service Service can SAVE the config files with saveToFile or init param 2`] = `
|
|
31
|
+
Array [
|
|
32
|
+
"/.env.test.pizza.json",
|
|
33
|
+
Object {
|
|
34
|
+
"$schema": ".schemas/pizza.env.schema.json",
|
|
35
|
+
"toppings": Array [
|
|
36
|
+
"cheese",
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
Object {
|
|
40
|
+
"spaces": 2,
|
|
41
|
+
},
|
|
42
|
+
]
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
exports[`Config Service Service can Save and CONVERT the config files with saveToFile or init param 1`] = `"/.env.test.pizza.yaml"`;
|
|
46
|
+
|
|
47
|
+
exports[`Config Service Service can Save and CONVERT the config files with saveToFile or init param 2`] = `
|
|
48
|
+
"
|
|
49
|
+
# yaml-language-server: $schema=.schemas/pizza.env.schema.json
|
|
50
|
+
toppings:
|
|
51
|
+
- cheese
|
|
52
|
+
|
|
53
|
+
"
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
exports[`Config Service Service can be forced to be created again 1`] = `
|
|
57
|
+
PizzaConfig {
|
|
58
|
+
"NODE_ENV": "test",
|
|
59
|
+
"name": "Pizza",
|
|
60
|
+
"saveToFile": false,
|
|
61
|
+
"toppings": Array [
|
|
62
|
+
"cheese",
|
|
63
|
+
],
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
exports[`Config Service Service can initialize the config files with saveToFile or init param 1`] = `
|
|
68
|
+
Array [
|
|
69
|
+
"/.env.test.pizza.json",
|
|
70
|
+
Object {
|
|
71
|
+
"$schema": ".schemas/pizza.env.schema.json",
|
|
72
|
+
"toppings": undefined,
|
|
73
|
+
},
|
|
74
|
+
Object {
|
|
75
|
+
"spaces": 2,
|
|
76
|
+
},
|
|
77
|
+
]
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
exports[`Config Service Service can initialize the config files with saveToFile or init param 2`] = `
|
|
81
|
+
Array [
|
|
82
|
+
"/.schemas/pizza.env.schema.json",
|
|
83
|
+
Object {
|
|
84
|
+
"properties": Object {
|
|
85
|
+
"toppings": Object {
|
|
86
|
+
"description": "optional toppings for the pizza",
|
|
87
|
+
"items": Object {
|
|
88
|
+
"enum": Array [
|
|
89
|
+
"cheese",
|
|
90
|
+
"pepperoni",
|
|
91
|
+
"sausage",
|
|
92
|
+
],
|
|
93
|
+
"type": "string",
|
|
94
|
+
},
|
|
95
|
+
"type": "array",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
"required": Array [],
|
|
99
|
+
"type": "object",
|
|
100
|
+
},
|
|
101
|
+
Object {
|
|
102
|
+
"spaces": 2,
|
|
103
|
+
},
|
|
104
|
+
]
|
|
105
|
+
`;
|
|
106
|
+
|
|
107
|
+
exports[`Config Service Service can return a plain object 1`] = `
|
|
108
|
+
Object {
|
|
109
|
+
"toppings": Array [
|
|
110
|
+
"cheese",
|
|
111
|
+
],
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
exports[`Config Service Service can save yaml without schema 1`] = `"/.env.test.pizza.yaml"`;
|
|
116
|
+
|
|
117
|
+
exports[`Config Service Service can save yaml without schema 2`] = `
|
|
118
|
+
"toppings:
|
|
119
|
+
- cheese
|
|
120
|
+
"
|
|
121
|
+
`;
|
|
122
|
+
|
|
123
|
+
exports[`Config Service Service returns correct empty yaml when config is empty 1`] = `"/.env.test.pizza.yaml"`;
|
|
124
|
+
|
|
125
|
+
exports[`Config Service Service returns correct empty yaml when config is empty 2`] = `"# yaml-language-server: $schema=.schemas/pizza.env.schema.json"`;
|
|
126
|
+
|
|
127
|
+
exports[`Config Service Shared Configurations Can define shared config 1`] = `"/.schemas/toppings.env.schema.json"`;
|
|
128
|
+
|
|
129
|
+
exports[`Config Service Shared Configurations Can define shared config 2`] = `
|
|
130
|
+
Object {
|
|
131
|
+
"properties": Object {
|
|
132
|
+
"INCLUDE_MEAT": Object {
|
|
133
|
+
"description": "(OVERRIDE SHARED CONFIG)
|
|
134
|
+
Should meat be included in the toppings options",
|
|
135
|
+
"type": "boolean",
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
"required": Array [],
|
|
139
|
+
"type": "object",
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
|
|
143
|
+
exports[`Config Service Shared Configurations Can define shared config 3`] = `"/.schemas/pizza.env.schema.json"`;
|
|
144
|
+
|
|
145
|
+
exports[`Config Service Shared Configurations Can define shared config 4`] = `
|
|
146
|
+
Object {
|
|
147
|
+
"properties": Object {
|
|
148
|
+
"toppings": Object {
|
|
149
|
+
"description": "optional toppings for the pizza",
|
|
150
|
+
"items": Object {
|
|
151
|
+
"enum": Array [
|
|
152
|
+
"cheese",
|
|
153
|
+
"pepperoni",
|
|
154
|
+
"sausage",
|
|
155
|
+
],
|
|
156
|
+
"type": "string",
|
|
157
|
+
},
|
|
158
|
+
"type": "array",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
"required": Array [],
|
|
162
|
+
"type": "object",
|
|
163
|
+
}
|
|
164
|
+
`;
|
|
165
|
+
|
|
166
|
+
exports[`Config Service Shared Configurations Can define shared config 5`] = `"/.env.test.pizza.json"`;
|
|
167
|
+
|
|
168
|
+
exports[`Config Service Shared Configurations Can define shared config 6`] = `
|
|
169
|
+
Object {
|
|
170
|
+
"$schema": ".schemas/pizza.env.schema.json",
|
|
171
|
+
"toppings": Array [
|
|
172
|
+
"cheese",
|
|
173
|
+
],
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
exports[`Config Service Shared Configurations Can define shared config 7`] = `"/.env.test._shared_.toppings.json"`;
|
|
178
|
+
|
|
179
|
+
exports[`Config Service Shared Configurations Can define shared config 8`] = `
|
|
180
|
+
Object {
|
|
181
|
+
"$schema": ".schemas/toppings.env.schema.json",
|
|
182
|
+
"INCLUDE_MEAT": true,
|
|
183
|
+
}
|
|
184
|
+
`;
|
|
185
|
+
|
|
186
|
+
exports[`Config Service wrap variables in attribute JSON 1`] = `"/.schemas/pizza.env.schema.json"`;
|
|
187
|
+
|
|
188
|
+
exports[`Config Service wrap variables in attribute JSON 2`] = `
|
|
189
|
+
Object {
|
|
190
|
+
"properties": Object {
|
|
191
|
+
"toppings": Object {
|
|
192
|
+
"description": "optional toppings for the pizza",
|
|
193
|
+
"items": Object {
|
|
194
|
+
"enum": Array [
|
|
195
|
+
"cheese",
|
|
196
|
+
"pepperoni",
|
|
197
|
+
"sausage",
|
|
198
|
+
],
|
|
199
|
+
"type": "string",
|
|
200
|
+
},
|
|
201
|
+
"type": "array",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
"required": Array [],
|
|
205
|
+
"type": "object",
|
|
206
|
+
}
|
|
207
|
+
`;
|
|
208
|
+
|
|
209
|
+
exports[`Config Service wrap variables in attribute JSON 3`] = `"/.env.test.pizza.json"`;
|
|
210
|
+
|
|
211
|
+
exports[`Config Service wrap variables in attribute JSON 4`] = `
|
|
212
|
+
Object {
|
|
213
|
+
"env_variables": Object {
|
|
214
|
+
"$schema": ".schemas/pizza.env.schema.json",
|
|
215
|
+
"toppings": Array [
|
|
216
|
+
"cheese",
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
}
|
|
220
|
+
`;
|
|
221
|
+
|
|
222
|
+
exports[`Config Service wrap variables in attribute JSONC 1`] = `"/.schemas/pizza.env.schema.json"`;
|
|
223
|
+
|
|
224
|
+
exports[`Config Service wrap variables in attribute JSONC 2`] = `
|
|
225
|
+
Object {
|
|
226
|
+
"properties": Object {
|
|
227
|
+
"toppings": Object {
|
|
228
|
+
"description": "optional toppings for the pizza",
|
|
229
|
+
"items": Object {
|
|
230
|
+
"enum": Array [
|
|
231
|
+
"cheese",
|
|
232
|
+
"pepperoni",
|
|
233
|
+
"sausage",
|
|
234
|
+
],
|
|
235
|
+
"type": "string",
|
|
236
|
+
},
|
|
237
|
+
"type": "array",
|
|
238
|
+
},
|
|
239
|
+
},
|
|
240
|
+
"required": Array [],
|
|
241
|
+
"type": "object",
|
|
242
|
+
}
|
|
243
|
+
`;
|
|
244
|
+
|
|
245
|
+
exports[`Config Service wrap variables in attribute JSONC 3`] = `"/.env.test.pizza.jsonc"`;
|
|
246
|
+
|
|
247
|
+
exports[`Config Service wrap variables in attribute JSONC 4`] = `
|
|
248
|
+
Object {
|
|
249
|
+
"env_variables": Object {
|
|
250
|
+
"$schema": ".schemas/pizza.env.schema.json",
|
|
251
|
+
"toppings": Array [
|
|
252
|
+
"cheese",
|
|
253
|
+
],
|
|
254
|
+
},
|
|
255
|
+
}
|
|
256
|
+
`;
|
|
257
|
+
|
|
258
|
+
exports[`Config Service wrap variables in attribute YAML 1`] = `"/.env.test.pizza.yaml"`;
|
|
259
|
+
|
|
260
|
+
exports[`Config Service wrap variables in attribute YAML 2`] = `
|
|
261
|
+
"
|
|
262
|
+
# yaml-language-server: $schema=.schemas/pizza.env.schema.json
|
|
263
|
+
env_variables:
|
|
264
|
+
toppings:
|
|
265
|
+
- cheese
|
|
266
|
+
|
|
267
|
+
"
|
|
268
|
+
`;
|
|
269
|
+
|
|
270
|
+
exports[`Config Service writeConfigToFile HJSON 1`] = `"/.env.test.pizza.hjson"`;
|
|
271
|
+
|
|
272
|
+
exports[`Config Service writeConfigToFile HJSON 2`] = `
|
|
273
|
+
"{
|
|
274
|
+
env_variables:
|
|
275
|
+
{
|
|
276
|
+
toppings:
|
|
277
|
+
[
|
|
278
|
+
cheese
|
|
279
|
+
]
|
|
280
|
+
}
|
|
281
|
+
}"
|
|
282
|
+
`;
|
|
283
|
+
|
|
284
|
+
exports[`Config Service writeConfigToFile JSON 1`] = `"/.env.test.pizza.json"`;
|
|
285
|
+
|
|
286
|
+
exports[`Config Service writeConfigToFile JSON 2`] = `
|
|
287
|
+
Object {
|
|
288
|
+
"env_variables": Object {
|
|
289
|
+
"toppings": Array [
|
|
290
|
+
"cheese",
|
|
291
|
+
],
|
|
292
|
+
},
|
|
293
|
+
}
|
|
294
|
+
`;
|
|
295
|
+
|
|
296
|
+
exports[`Config Service writeConfigToFile JSONC 1`] = `"/.env.test.pizza.jsonc"`;
|
|
297
|
+
|
|
298
|
+
exports[`Config Service writeConfigToFile JSONC 2`] = `
|
|
299
|
+
Object {
|
|
300
|
+
"env_variables": Object {
|
|
301
|
+
"toppings": Array [
|
|
302
|
+
"cheese",
|
|
303
|
+
],
|
|
304
|
+
},
|
|
305
|
+
}
|
|
306
|
+
`;
|
|
307
|
+
|
|
308
|
+
exports[`Config Service writeConfigToFile YAML 1`] = `"/.env.test.pizza.yaml"`;
|
|
309
|
+
|
|
310
|
+
exports[`Config Service writeConfigToFile YAML 2`] = `
|
|
311
|
+
"env_variables:
|
|
312
|
+
toppings:
|
|
313
|
+
- cheese"
|
|
314
|
+
`;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { validateSync } from 'class-validator';
|
|
2
|
+
import strip from 'strip-color';
|
|
3
|
+
|
|
4
|
+
import { ConfigValidationError } from './config.errors';
|
|
5
|
+
import { PizzaConfig, ToppingEnum } from './pizza.config.model.mock';
|
|
6
|
+
|
|
7
|
+
describe('Config Model', () => {
|
|
8
|
+
let validationError: ConfigValidationError;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
validationError = new ConfigValidationError([]);
|
|
11
|
+
});
|
|
12
|
+
test('validationError creation', () => {
|
|
13
|
+
expect(validationError).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('ConfigValidationError beautify class-validator errors', () => {
|
|
17
|
+
const config = new PizzaConfig({
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
toppings: [ ToppingEnum.Cheese, ToppingEnum.Pepperoni, 5 as any ]
|
|
20
|
+
});
|
|
21
|
+
const validationErrors = validateSync(config);
|
|
22
|
+
validationError = new ConfigValidationError(validationErrors);
|
|
23
|
+
|
|
24
|
+
expect(strip(validationError.message).replace(/(?:\r\n|\r|\n)/g, '\n')).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
import { BaseConfig } from './config.model';
|
|
3
|
+
import { setEnvironment } from './environment.service';
|
|
4
|
+
import { PizzaConfig } from './pizza.config.model.mock';
|
|
5
|
+
|
|
6
|
+
setEnvironment('test');
|
|
7
|
+
|
|
8
|
+
describe('Config Model', () => {
|
|
9
|
+
let config: BaseConfig;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
process.env.NODE_ENV = 'test';
|
|
12
|
+
config = new BaseConfig({
|
|
13
|
+
NODE_ENV: 'test'
|
|
14
|
+
});
|
|
15
|
+
config.setName(BaseConfig);
|
|
16
|
+
});
|
|
17
|
+
test('Base config creation', () => {
|
|
18
|
+
expect(config).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('config.getFileName', () => {
|
|
22
|
+
expect(config.getFileName('json'))
|
|
23
|
+
.toEqual('.env.test.base.json');
|
|
24
|
+
expect(config.getFileName('yaml'))
|
|
25
|
+
.toEqual('.env.test.base.yaml');
|
|
26
|
+
expect(config.getFileName('json', true))
|
|
27
|
+
.toEqual('.env.test._shared_.base.json');
|
|
28
|
+
|
|
29
|
+
config.setName(PizzaConfig);
|
|
30
|
+
|
|
31
|
+
expect(config.getFileName('json'))
|
|
32
|
+
.toEqual('.env.test.pizza.json');
|
|
33
|
+
expect(config.getFileName('yaml'))
|
|
34
|
+
.toEqual('.env.test.pizza.yaml');
|
|
35
|
+
expect(config.getFileName('json', true))
|
|
36
|
+
.toEqual('.env.test._shared_.pizza.json');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('config.getSchemaFileName', () => {
|
|
40
|
+
expect(config.getSchemaFileName())
|
|
41
|
+
.toEqual('base.env.schema.json');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('config.toJsonSchema', () => {
|
|
45
|
+
const pizzaConfig = new PizzaConfig({
|
|
46
|
+
NODE_ENV: 'test'
|
|
47
|
+
});
|
|
48
|
+
pizzaConfig.setName(PizzaConfig);
|
|
49
|
+
expect(pizzaConfig.toJsonSchema())
|
|
50
|
+
.toMatchSnapshot();
|
|
51
|
+
});
|
|
52
|
+
});
|
package/src/config.model.ts
CHANGED
|
@@ -1,41 +1,65 @@
|
|
|
1
|
-
import { Exclude, Expose } from 'class-transformer';
|
|
2
1
|
import {
|
|
3
2
|
IsBoolean,
|
|
3
|
+
IsEnum,
|
|
4
4
|
IsIn,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
IsOptional,
|
|
6
|
+
IsString
|
|
7
7
|
} from 'class-validator';
|
|
8
8
|
import { validationMetadatasToSchemas } from 'class-validator-jsonschema';
|
|
9
|
-
import { chain } from 'lodash';
|
|
9
|
+
import { chain, kebabCase } from 'lodash';
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { EFileFormats } from './config.service';
|
|
12
|
+
import { getEnvironment } from './environment.service';
|
|
13
|
+
import { Configuration, ConfigVariable } from './json-schema.validator';
|
|
12
14
|
|
|
13
15
|
export const NODE_ENVIRONMENT_OPTIONS = [
|
|
14
16
|
'google',
|
|
15
17
|
'development',
|
|
16
18
|
'production',
|
|
17
19
|
'test',
|
|
18
|
-
'devcontainer'
|
|
20
|
+
'devcontainer',
|
|
21
|
+
'staging',
|
|
22
|
+
'e2e'
|
|
19
23
|
];
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
type TClass<T> = (new (partial: Partial<T>) => T);
|
|
26
|
+
|
|
27
|
+
@Configuration()
|
|
28
|
+
export class BaseConfig {
|
|
29
|
+
name: string;
|
|
30
|
+
|
|
24
31
|
@IsString()
|
|
25
32
|
@IsIn(NODE_ENVIRONMENT_OPTIONS)
|
|
26
|
-
@
|
|
27
|
-
'Tells which env file to use and what environment we are running on'
|
|
28
|
-
|
|
33
|
+
@ConfigVariable(
|
|
34
|
+
'Tells which env file to use and what environment we are running on',
|
|
35
|
+
{ exclude: true }
|
|
36
|
+
)
|
|
29
37
|
NODE_ENV = 'development';
|
|
30
38
|
|
|
31
39
|
@IsBoolean()
|
|
32
|
-
@
|
|
40
|
+
@ConfigVariable([
|
|
33
41
|
'Create a file made out of the internal config. This is mostly for ',
|
|
34
42
|
'merging command line, environment, and file variables to a single instance'
|
|
35
|
-
])
|
|
43
|
+
], { exclude: true })
|
|
36
44
|
saveToFile = false;
|
|
37
45
|
|
|
38
|
-
|
|
46
|
+
@IsEnum(EFileFormats)
|
|
47
|
+
@IsOptional()
|
|
48
|
+
@ConfigVariable(
|
|
49
|
+
'Save the file to JSON if defaults to YAML and vise versa',
|
|
50
|
+
{ exclude: true }
|
|
51
|
+
)
|
|
52
|
+
convert: EFileFormats;
|
|
53
|
+
|
|
54
|
+
@IsString()
|
|
55
|
+
@IsOptional()
|
|
56
|
+
@ConfigVariable(
|
|
57
|
+
'Object Wrapper for saved file',
|
|
58
|
+
{ exclude: true }
|
|
59
|
+
)
|
|
60
|
+
wrapper;
|
|
61
|
+
|
|
62
|
+
constructor(partial: Partial<BaseConfig> = {}) {
|
|
39
63
|
Object.assign(this, partial);
|
|
40
64
|
}
|
|
41
65
|
|
|
@@ -50,17 +74,55 @@ export class Config {
|
|
|
50
74
|
|
|
51
75
|
const classForSchema = chain(configJsonSchemaObj)
|
|
52
76
|
.keys()
|
|
53
|
-
.
|
|
54
|
-
.
|
|
77
|
+
.find((className) => className === this.constructor.name)
|
|
78
|
+
.value();
|
|
79
|
+
const configJsonSchema = chain(configJsonSchemaObj[classForSchema])
|
|
80
|
+
.omit([
|
|
81
|
+
'properties.NODE_ENV',
|
|
82
|
+
'properties.nodeEnv',
|
|
83
|
+
'properties.saveToFile',
|
|
84
|
+
'properties.convert',
|
|
85
|
+
'properties.wrapper'
|
|
86
|
+
])
|
|
55
87
|
.value();
|
|
56
|
-
const configJsonSchema = configJsonSchemaObj[classForSchema];
|
|
57
88
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
89
|
+
if (configJsonSchema.required) {
|
|
90
|
+
configJsonSchema.required = chain(configJsonSchema.required)
|
|
91
|
+
.filter((value) => ![
|
|
92
|
+
'NODE_ENV',
|
|
93
|
+
'nodeEnv',
|
|
94
|
+
'saveToFile',
|
|
95
|
+
'convert',
|
|
96
|
+
'wrapper'
|
|
97
|
+
].includes(value))
|
|
98
|
+
.value();
|
|
99
|
+
}
|
|
63
100
|
|
|
64
101
|
return configJsonSchema;
|
|
65
102
|
}
|
|
103
|
+
|
|
104
|
+
private cleanFileName(fileName: string) {
|
|
105
|
+
return chain(fileName)
|
|
106
|
+
.replace(/Config$/i, '')
|
|
107
|
+
.replace(/Configuration$/i, '')
|
|
108
|
+
.value();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
setName(genericClass: TClass<BaseConfig>) {
|
|
112
|
+
this.name = this.cleanFileName(genericClass.name);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getFileName(ext: string, isSharedConfig = false) {
|
|
116
|
+
return [
|
|
117
|
+
'.env.',
|
|
118
|
+
getEnvironment(), '.',
|
|
119
|
+
isSharedConfig ? '_shared_.' : '',
|
|
120
|
+
kebabCase(this.name), '.',
|
|
121
|
+
ext
|
|
122
|
+
].join('');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
getSchemaFileName() {
|
|
126
|
+
return `${ kebabCase(this.name) }.env.schema.json`;
|
|
127
|
+
}
|
|
66
128
|
}
|