UNPKG

863 BJavaScriptView Raw
1// @ts-check
2const path = require('path')
3const fs = require('fs')
4const { getConfig } = require('../conf/F2E_CONFIG')
5const root = process.cwd()
6const _ = require('lodash')
7
8const 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
22module.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}