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 |
|
14 | const {
|
15 | kootDev = false,
|
16 | args = []
|
17 | } = options
|
18 | const customArgs = {}
|
19 |
|
20 |
|
21 | if (!kootDev && typeof process.env.KOOT_PROJECT_CONFIG_FULL_PATHNAME !== 'string')
|
22 | await fs.remove(getDirTemp())
|
23 |
|
24 |
|
25 | {
|
26 | const keys = []
|
27 | args.forEach(arg => {
|
28 | const segs = arg.split('=')
|
29 |
|
30 | const key = segs.shift()
|
31 | const value = segs.join('=')
|
32 | if (typeof process.env[key] !== 'undefined')
|
33 | throw new Error(`Environment Variable "${key}" exists and cannot be set!`)
|
34 | keys.push(key)
|
35 | process.env[key] = value
|
36 | customArgs[key] = value
|
37 | })
|
38 |
|
39 | if (typeof process.env.KOOT_CUSTOM_ENV_KEYS === 'undefined') {
|
40 | process.env.KOOT_CUSTOM_ENV_KEYS = JSON.stringify(keys)
|
41 | } else {
|
42 | const keysAll = JSON.parse(process.env.KOOT_CUSTOM_ENV_KEYS)
|
43 | .concat(keys)
|
44 | process.env.KOOT_CUSTOM_ENV_KEYS = JSON.stringify(keysAll)
|
45 | }
|
46 | }
|
47 |
|
48 | return { customArgs }
|
49 | }
|