-
Notifications
You must be signed in to change notification settings - Fork 560
/
purge.js
39 lines (35 loc) · 947 Bytes
/
purge.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
const path = require('node:path')
const fs = require('node:fs')
const namesToRemove = process.argv.slice(2)
const peoplesPath = path.join(__dirname, 'people')
if (!namesToRemove.length) {
fs.readdirSync(peoplesPath).forEach((file) => {
if (file.indexOf('mazipan.js') < 0) {
try {
fs.unlinkSync(path.join(peoplesPath, file))
console.log(`Success deleting file: ${file}`)
} catch (_e) {
console.error(`Error deleting file: ${file}`)
}
}
})
fs.writeFile(
`${peoplesPath}/LAST_UPDATE`,
`${new Date().toISOString()}`,
(err) => {
if (err) {
console.error(err)
} else {
console.log('File "LAST_UPDATE" is updated successfully.')
}
},
)
} else {
namesToRemove.forEach((name) => {
try {
fs.unlinkSync(path.join(peoplesPath, `${name}.js`))
} catch (_e) {
console.error(`Error deleting file for name: ${name}`)
}
})
}