-
Notifications
You must be signed in to change notification settings - Fork 0
/
moduleResolver.js
32 lines (29 loc) · 926 Bytes
/
moduleResolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var fs = require('fs');
var { modules, root, base } = JSON.parse(
fs.readFileSync('./modules.json', 'utf8'),
);
let tsConf = JSON.parse(fs.readFileSync('./tsconfig.json', 'utf8'));
tsConf.compilerOptions.baseUrl = root;
const extraPaths = {
'*': [`${root}/${base}/*`],
redux: ['./node_modules/redux'],
};
const getDeeper = fPath => {
const path = fPath.split('/');
return { parent: path[0], target: path[1] };
};
const checkDeep = fPath => {
if (fPath.indexOf('/') !== -1) {
let { parent, target } = getDeeper(fPath);
let path = `${parent}/${target}`;
return { path, target };
}
return { path: fPath, target: fPath };
};
let paths = { ...extraPaths };
modules.forEach(module => {
const { path, target } = checkDeep(module);
paths[`@${target}/*`] = [`${root}/${base}/${path}/*`];
});
tsConf.compilerOptions.paths = paths;
fs.writeFileSync('./tsconfig.json', JSON.stringify(tsConf, null, 2));