UNPKG

1.49 kBJavaScriptView Raw
1
2const path = require('path');
3const fs = require('fs');
4
5const serverConfig = (devToolsPath) => {
6 const serverConfig = {};
7 if (fs.existsSync(devToolsPath)) {
8 const devTools = require(devToolsPath);
9 if (devTools.hasOwnProperty('server')) {
10 Object.assign(serverConfig, devTools.server);
11 }
12 }
13
14 const defaultConfig = {
15 "port": 4000,
16 "ip": '0.0.0.0',
17 "proxyServers": [],
18 "folders": [
19 { "route": "", "root": true, "path": "dist" },
20 { "route": "dist", "path": "dist" },
21 { "route": "node_modules", "path": "node_modules" }
22 ]
23 };
24
25 Object.keys(serverConfig).forEach(key => {
26 if (defaultConfig[key]) {
27 if (Array.isArray(defaultConfig[key]) && Array.isArray(serverConfig[key])) {
28 const others = serverConfig[key].filter(config => {
29 const value = defaultConfig[key].find(result => JSON.stringify(result) === JSON.stringify(config));
30 return (!(value));
31 });
32 if (others) {
33 const predicate = (folder) => (folder['root'] && (folder.root === true));
34 if (key === 'folders' && others.find(predicate)) {
35 const index = defaultConfig[key].findIndex(predicate);
36 defaultConfig[key].splice(index, 1);
37 }
38 defaultConfig[key].concat(others);
39 }
40 } else {
41 defaultConfig[key] = serverConfig[key];
42 }
43 }
44 });
45
46 return defaultConfig;
47};
48
49module.exports = serverConfig(path.resolve('.devtools.json'));
50