-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsconfig.update.js
36 lines (29 loc) · 1.02 KB
/
tsconfig.update.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
33
34
35
36
const fs = require('fs');
const isSingleModule = fs.existsSync('./src/index.ts') || fs.existsSync('./src/index.tsx');
const isMultiModule = !isSingleModule;
const tsConfigJson = require('./tsconfig.json');
if (isSingleModule) {
tsConfigJson.files = [
fs.existsSync("./src/index.ts") && "./src/index.ts",
fs.existsSync("./src/index.tsx") && "./src/index.tsx",
]
.filter(Boolean);
}
if (isMultiModule) {
const getModuleNames =
root =>
fs.readdirSync(root, {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name);
const moduleNames = getModuleNames('./src');
tsConfigJson.files =
moduleNames
.map(moduleName => {
const indexFilename = `./src/${moduleName}/index.ts`;
if (fs.existsSync(indexFilename)) return indexFilename;
if (fs.existsSync(indexFilename + 'x')) return indexFilename + 'x';
return null;
})
.filter(Boolean);
}
fs.writeFileSync('./tsconfig.json', JSON.stringify(tsConfigJson, null, 2));