UNPKG

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