-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
69 lines (59 loc) · 1.99 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
const fs = require("fs");
const { sites } = require("./config");
fs.readdirSync("./scripts").forEach((script) => {
global[script.slice(0, -3)] = require(`./scripts/${script}`);
});
console.clear();
console.log("Image Parser by Xaliks");
console.log("");
if (process.argv[2] === "delete") {
if (
process.version.split(".")[0] < 14 &&
process.version.split(".")[1] < 14
) {
console.log(
`Версия ${color.yellow("node.js")} должна быть не ниже ${color.red(
"14.14.0"
)}!`
);
process.exit();
}
if (!fs.existsSync("./images")) {
console.log(`Папка ${color.cyan("images")} уже удалена!`);
} else {
fs.rmSync("./images", { recursive: true, force: true });
console.log(`Папка ${color.cyan("images")} удалена!`);
}
if (!fs.existsSync("./FoundLinks.txt")) {
console.log(`Файл ${color.cyan("FoundLinks.txt")} уже удалён!`);
} else {
fs.unlinkSync("./FoundLinks.txt");
console.log(`Файл ${color.cyan("FoundLinks.txt")} удалён!`);
}
process.exit();
}
if (!fs.existsSync("./images")) {
console.log(`Папки ${color.cyan("images")} не существует! Создаю...`);
fs.mkdirSync("./images");
}
if (!fs.existsSync("./FoundLinks.txt")) {
console.log(`Файла ${color.cyan("FoundLinks.txt")} не существует! Создаю...`);
fs.writeFileSync(
"./FoundLinks.txt",
"Здесь будут найденные ссылки на картинки!\n"
);
}
sites
.filter((site) => site.enabled)
.forEach((site) => {
if (!fs.existsSync(`./images/${site.name}`)) {
console.log(
`Папки ${color.cyan(`images/${site.name}`)} не существует! Создаю...`
);
fs.mkdirSync(`./images/${site.name}`);
}
if (!fs.existsSync(`./images/${site.name}`)) {
throw new Error(`Для сайта ${color.cyan(site.name)} нет скрипта!`);
}
require(`./sites/${site.name}`)(site);
});