forked from badlogic/heissepreise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pages.js
61 lines (55 loc) · 2.3 KB
/
pages.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
const fs = require("fs");
const path = require("path");
const analysis = require("./analysis.js");
const bundle = require("./bundle.js");
const outputDir = path.resolve("docs");
const dataDir = path.join(outputDir, "data");
const { execSync } = require("child_process");
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);
}
}
});
}
(async function () {
try {
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir);
deleteFiles(outputDir);
bundle.bundle("site", outputDir, false);
if (fs.existsSync(`${dataDir}/latest-canonical.json`)) {
const data = analysis.readJSON(`${dataDir}/latest-canonical.json`);
analysis.writeJSON(`${dataDir}/latest-canonical.json`, data, analysis.FILE_COMPRESSOR);
}
await analysis.updateData(dataDir);
const items = analysis.readJSON(`${dataDir}/latest-canonical.json.${analysis.FILE_COMPRESSOR}`);
for (const store of analysis.STORE_KEYS) {
const storeItems = items.filter((item) => item.store === store);
analysis.writeJSON(`${dataDir}/latest-canonical.${store}.compressed.json`, storeItems, false, 0, true);
}
fs.readdirSync(dataDir).forEach((file) => {
const filePath = path.join(dataDir, file);
if (fs.statSync(filePath).isFile() && !file.startsWith("latest-canonical")) fs.unlinkSync(filePath);
});
try {
const output = execSync(`ls -lah ${dataDir}`).toString();
console.log(output);
} catch (error) {
console.error(`Error executing command: ${error}`);
}
// analysis.migrateCompression(dataDir, `.json.${analysis.FILE_COMPRESSOR}`, ".json");
fs.unlinkSync(`${dataDir}/latest-canonical.json.${analysis.FILE_COMPRESSOR}`);
analysis.writeJSON(`${dataDir}/latest-canonical.json`, items, false);
console.log("done");
} catch (e) {
console.error(e);
}
process.exit(1);
})();