-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean.js
38 lines (28 loc) · 884 Bytes
/
clean.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
const fs = require('fs')
const path = require('path')
const entryName = 'main'
const clean = (dir) => {
const files = fs.readdirSync(dir)
files.forEach(fileName => {
// .tex and .pdf files are not junk
if (fileName === `${entryName}.tex` || fileName === `${entryName}.pdf`) {
return
}
const pathToFile = path.resolve(dir, fileName)
const isDirectory = fs.lstatSync(pathToFile).isDirectory()
// Recurse over directories
if (isDirectory) {
clean(pathToFile)
return
}
const [head, ...rest] = fileName.split('.')
const ext = rest[rest.length - 1]
// Any remaining files are junk if they end in the .aux extension
// or if they match the pattern main.*
const fileIsJunk = ext === 'aux' || head === entryName
if (fileIsJunk) {
fs.unlinkSync(pathToFile)
}
})
}
clean(path.resolve('./'))