-
Notifications
You must be signed in to change notification settings - Fork 6
/
post-build.js
45 lines (35 loc) · 976 Bytes
/
post-build.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
const tsfmt = require('typescript-formatter')
const fs = require('fs')
const path = require('path')
console.log('Start post build...')
formatDist()
async function formatDist () {
console.log('Start formatting dist files...')
const distPath = path.resolve(__dirname, './dist')
if (!fs.existsSync(distPath)) {
console.log('No dist folder, exit.')
return
}
const tsFiles = getAllFiles(distPath)
.filter(item => item.endsWith('.ts'))
await tsfmt.processFiles(tsFiles, {
replace: true,
editorconfig: true,
tslint: false
})
console.log('Dist formatting done.')
}
function getAllFiles (dirPath) {
let result = []
const files = fs.readdirSync(dirPath)
for (const filePath of files) {
const fullPath = path.resolve(dirPath, filePath)
const stat = fs.statSync(fullPath)
if (!stat.isDirectory()) {
result.push(fullPath)
} else {
result = result.concat(getAllFiles(fullPath))
}
}
return result
}