UNPKG

597 BJavaScriptView Raw
1const fs = require('fs')
2const path = require('path')
3const _ = require('lodash')
4const GLOBAL_CONF_NAME = require('./get').GLOBAL_CONF_NAME
5const cfgPath = path.join(__dirname, '../../../.globalf2econfig')
6
7if (!fs.existsSync(cfgPath)) {
8 fs.writeFileSync(cfgPath, '{}')
9}
10
11module.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}