-
Notifications
You must be signed in to change notification settings - Fork 563
/
purge.js
35 lines (31 loc) · 959 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
const path = require("path");
const fs = require("fs");
const namesToRemove = process.argv.slice(2);
const peoplesPath = path.join(__dirname, "peoples");
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()}`, function (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}`);
}
});
}