1 | const path = require('path')
|
2 | const chalk = require('chalk')
|
3 | const getAppTypeString = require('./get-app-type-string')
|
4 | const __ = require('./translate')
|
5 | const envUpdateAppType = require('../libs/env/update-app-type')
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | module.exports = ({
|
12 | config,
|
13 | type,
|
14 | port
|
15 | }, quiet = false) => {
|
16 | let modified = false
|
17 | const log = (key, value) => {
|
18 | if (quiet) return
|
19 | console.log(
|
20 | chalk.green('√ ')
|
21 | + chalk.yellowBright('[koot] ')
|
22 | + `set process.env.` + chalk.green(key)
|
23 | + `\n -> `
|
24 | + value
|
25 | )
|
26 | }
|
27 |
|
28 | if (typeof config === 'string') {
|
29 | config = path.resolve(config)
|
30 | process.env.KOOT_BUILD_CONFIG_PATHNAME = config
|
31 | log('KOOT_BUILD_CONFIG_PATHNAME', config)
|
32 | modified = true
|
33 | }
|
34 |
|
35 | if (typeof type === 'string') {
|
36 | process.env.KOOT_PROJECT_TYPE = getAppTypeString(type)
|
37 | envUpdateAppType(process.env.KOOT_PROJECT_TYPE)
|
38 | log('KOOT_PROJECT_TYPE', process.env.KOOT_PROJECT_TYPE + ` (${__(`appType.${process.env.KOOT_PROJECT_TYPE}`)})`)
|
39 | modified = true
|
40 | }
|
41 |
|
42 | if (typeof port === 'string' || typeof port === 'number') {
|
43 | process.env.SERVER_PORT = port
|
44 | log('SERVER_PORT', port)
|
45 | modified = true
|
46 | }
|
47 |
|
48 | if (modified) console.log(' ')
|
49 |
|
50 | return {
|
51 | config, type, port
|
52 | }
|
53 | }
|