1 |
|
2 | const path = require('path')
|
3 | const fs = require('fs')
|
4 | const { getConfig } = require('../conf/F2E_CONFIG')
|
5 | const root = process.cwd()
|
6 | const _ = require('lodash')
|
7 |
|
8 | const renderCfg = (cf) => {
|
9 | let conf = {}
|
10 | if (fs.existsSync(cf)) {
|
11 | try {
|
12 | conf = require(cf)
|
13 | } catch (e) {
|
14 | console.error(`${getConfig()} error`, e)
|
15 | }
|
16 | } else {
|
17 | console.info(`\n no\n ${getConfig()}! \n run\n 'f2e conf' `)
|
18 | }
|
19 | return conf
|
20 | }
|
21 |
|
22 | module.exports = (c = {}) => {
|
23 | if (!c.root) {
|
24 | c.root = root
|
25 | }
|
26 | const conf = renderCfg(path.join(c.root, getConfig()))
|
27 | if (conf.root) {
|
28 | c.root = conf.root
|
29 | }
|
30 | return _.cloneDeep(_.extend({
|
31 | onServerCreate: (server) => {},
|
32 | buildFilter: (pathname, data) => !/node_modules|([\\/]|^)\./.test(pathname)
|
33 | }, conf, c))
|
34 | }
|