1 | const fs = require('fs-extra');
|
2 |
|
3 | const getDirTemp = require('../libs/get-dir-tmp');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = async (options = {}) => {
|
13 | const { kootDev = false, args = [] } = options;
|
14 | const customArgs = {};
|
15 |
|
16 |
|
17 | if (
|
18 | !kootDev &&
|
19 | typeof process.env.KOOT_PROJECT_CONFIG_FULL_PATHNAME !== 'string'
|
20 | )
|
21 | await fs.remove(getDirTemp());
|
22 |
|
23 |
|
24 | {
|
25 | const keys = [];
|
26 | args.forEach(arg => {
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | const segs = arg.split('=');
|
32 |
|
33 | const key = segs.shift();
|
34 | const value = segs.join('=');
|
35 | if (typeof process.env[key] !== 'undefined')
|
36 | throw new Error(
|
37 | `Environment Variable "${key}" exists and cannot be set!`
|
38 | );
|
39 | keys.push(key);
|
40 | process.env[key] = value;
|
41 | customArgs[key] = value;
|
42 | });
|
43 |
|
44 | if (typeof process.env.KOOT_CUSTOM_ENV_KEYS === 'undefined') {
|
45 | process.env.KOOT_CUSTOM_ENV_KEYS = JSON.stringify(keys);
|
46 | } else {
|
47 | const keysAll = JSON.parse(process.env.KOOT_CUSTOM_ENV_KEYS).concat(
|
48 | keys
|
49 | );
|
50 | process.env.KOOT_CUSTOM_ENV_KEYS = JSON.stringify(keysAll);
|
51 | }
|
52 | }
|
53 |
|
54 | return { customArgs };
|
55 | };
|