1 | const fs = require('fs')
|
2 | const path = require('path')
|
3 | const _ = require('lodash')
|
4 | const GLOBAL_CONF_NAME = require('./get').GLOBAL_CONF_NAME
|
5 | const cfgPath = path.join(__dirname, '../../../.globalf2econfig')
|
6 |
|
7 | if (!fs.existsSync(cfgPath)) {
|
8 | fs.writeFileSync(cfgPath, '{}')
|
9 | }
|
10 |
|
11 | module.exports = ({port = 80, host = 'localhost', root}) => {
|
12 | let confStr = fs.readFileSync(cfgPath).toString() || '{}'
|
13 | let conf = JSON.parse(confStr)
|
14 | _.set(conf, [port, host], root)
|
15 | global[GLOBAL_CONF_NAME] = conf
|
16 | fs.writeFile(cfgPath, JSON.stringify(conf, 0, 2), err => err && console.log(err))
|
17 | }
|