1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const path = require('path'),
|
12 | { getConfig } = require('./lib');
|
13 |
|
14 | const MODULE_ROOT = path.join(__dirname, '../');
|
15 | const debug_i = require('./lib/debug-logger')('index');
|
16 |
|
17 | let utils = Object.create(null);
|
18 | let _isConfigFrozen = (() => {
|
19 |
|
20 | })();
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | utils.get = (options) => {
|
27 | let config = getConfig(null, options);
|
28 |
|
29 | config[Symbol.for('utils')] = utils;
|
30 | debug_i('Symbol.for(utils)');
|
31 |
|
32 | return config;
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | utils.use = (options) => {
|
40 |
|
41 | if (_isConfigFrozen) {
|
42 | debug_i.error('module is already initiated!')
|
43 | }
|
44 |
|
45 | let config = utils.get(options);
|
46 |
|
47 |
|
48 | if (module.loaded) {
|
49 | require.cache[module.filename] = config;
|
50 | }
|
51 | else {
|
52 | module.exports = config;
|
53 | }
|
54 |
|
55 | return config;
|
56 | };
|
57 |
|
58 | utils.moduleRoot = () => {
|
59 | return MODULE_ROOT;
|
60 | }
|
61 |
|
62 |
|
63 | Object.freeze(utils);
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 | if (!process.env.CONFIG_PREVENT_DEFAULT) {
|
70 | utils.use();
|
71 | }
|
72 | else {
|
73 | debug_i('Symbol.for(utils)');
|
74 | module.exports[Symbol.for('utils')] = utils;
|
75 | } |
\ | No newline at end of file |