-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-tsconfig.app.json-files.js
58 lines (47 loc) · 1.87 KB
/
update-tsconfig.app.json-files.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var fs = require('fs');
const findTSFilesInFormsFolder = () => {
// List all files in a directory in Node.js recursively in a synchronous fashion
const walkSync = (dir, filelist = []) => {
var path = path || require('path')
var fs = fs || require('fs')
fs.readdirSync(dir).forEach(file => {
filelist = fs.statSync(path.join(dir, file)).isDirectory()
? walkSync(path.join(dir, file), filelist)
: filelist.concat(path.join(dir, file))
});
return filelist;
}
const formsDir = 'app/__forms'
const formsDirPath = `src/${formsDir}`
let formsTsFiles = walkSync(formsDirPath)
.filter(element => {
return element.toLowerCase().endsWith('.ts')
})
formsTsFiles.forEach(element => {
console.log(element)
});
formsTsFiles = formsTsFiles.map((element) => {
return element.replace('src/', '')/*windows...*/.replace('src\\', '')
})
return {
formsTsFiles: formsTsFiles, filterMatchingFormsTsFiles: element => {
return element.startsWith(formsDir) || element.startsWith(formsDirPath)
}
}
}
const updateFilesInTSConfigJSON = (tsconfig_json, formsFolderState) => {
var tcj = JSON.parse(fs.readFileSync(tsconfig_json));
let tcj_files = tcj['files'] || []
// filter out existing entries
tcj_files = tcj_files.filter(element => {
return !formsFolderState.filterMatchingFormsTsFiles(element)
})
// put all together
tcj_files = tcj_files.concat(formsFolderState.formsTsFiles)
tcj['files'] = tcj_files
// finally write files
fs.writeFileSync(tsconfig_json, JSON.stringify(tcj, null, 2))
}
const formsFolderState = findTSFilesInFormsFolder()
updateFilesInTSConfigJSON('src/tsconfig.app.json', formsFolderState)
updateFilesInTSConfigJSON('src/tsconfig.spec.json', formsFolderState)