2023-05-28 09:53:19 +02:00
|
|
|
const fs = require("fs");
|
2023-06-05 20:54:11 +02:00
|
|
|
const path = require("path");
|
2023-05-28 09:53:19 +02:00
|
|
|
const analysis = require("./analysis.js");
|
2023-06-03 22:00:52 +02:00
|
|
|
const template = require("./template.js");
|
2023-06-05 20:54:11 +02:00
|
|
|
const outputDir = path.resolve("docs");
|
|
|
|
const dataDir = path.join(outputDir, "data");
|
2023-05-28 09:53:19 +02:00
|
|
|
|
2023-06-05 20:54:11 +02:00
|
|
|
function deleteFiles(folderPath) {
|
|
|
|
const files = fs.readdirSync(folderPath);
|
|
|
|
|
|
|
|
files.forEach((file) => {
|
|
|
|
const filePath = path.join(folderPath, file);
|
|
|
|
|
|
|
|
if (filePath !== dataDir) {
|
|
|
|
if (fs.statSync(filePath).isFile()) {
|
|
|
|
fs.unlinkSync(filePath);
|
|
|
|
} else {
|
|
|
|
deleteFiles(filePath);
|
|
|
|
fs.rmdirSync(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2023-05-28 09:53:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
(async function () {
|
|
|
|
try {
|
2023-06-05 20:54:11 +02:00
|
|
|
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
|
|
|
|
deleteFiles(outputDir);
|
2023-06-03 22:00:52 +02:00
|
|
|
template.generateSite("site", outputDir, false);
|
|
|
|
|
2023-06-03 00:08:35 +02:00
|
|
|
analysis.migrateCompression(dataDir, ".json", ".json.br");
|
|
|
|
analysis.migrateCompression(dataDir, ".json.gz", ".json.br");
|
2023-05-28 09:53:19 +02:00
|
|
|
await analysis.updateData(dataDir);
|
2023-06-03 22:00:52 +02:00
|
|
|
|
2023-06-03 00:01:26 +02:00
|
|
|
const items = analysis.readJSON(`${dataDir}/latest-canonical.json.${analysis.FILE_COMPRESSOR}`);
|
2023-05-30 15:46:10 +02:00
|
|
|
for (const store of analysis.STORE_KEYS) {
|
2023-06-03 22:00:52 +02:00
|
|
|
const storeItems = items.filter((item) => item.store === store);
|
2023-06-05 20:54:11 +02:00
|
|
|
analysis.writeJSON(`${dataDir}/latest-canonical.${store}.compressed.json`, storeItems, false, 0, true);
|
2023-05-30 15:46:10 +02:00
|
|
|
}
|
2023-06-05 20:54:11 +02:00
|
|
|
fs.readdirSync(dataDir).forEach((file) => {
|
|
|
|
const filePath = path.join(dataDir, file);
|
|
|
|
if (fs.statSync(filePath).isFile() && !file.startsWith("latest-canonical")) fs.unlinkSync(filePath);
|
|
|
|
});
|
|
|
|
analysis.migrateCompression(dataDir, ".json.br", ".json");
|
2023-05-30 15:46:10 +02:00
|
|
|
} catch (e) {
|
2023-06-05 20:54:11 +02:00
|
|
|
console.error(e);
|
2023-05-28 09:53:19 +02:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
})();
|