forked from uso-archive/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-style-info.js
48 lines (39 loc) · 1.52 KB
/
get-style-info.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
const fs = require("fs").promises;
const path = require("path");
const utils = require("./lib/utils");
const uso = require("./lib/uso");
const logger = require("./lib/logger");
async function main() {
let started = 0;
const maxInParralel = 100;
const skipTo = parseInt(process.argv[2]);
const files = (await fs.readdir(path.resolve(__dirname, "data", "styles"))).sort().slice(skipTo);
let regular = skipTo || 0;
let full = 0;
const total = (skipTo || 0) + files.length;
for (const stylePath of files) {
await utils.waitUntilTrue(() => started < maxInParralel);
(async () => {
started++;
const json = JSON.parse(await fs.readFile(path.resolve(__dirname, "data", "styles", stylePath)));
if (uso.shouldBeFullyArchived(json)) {
try {
await uso.saveStyle(await uso.getStyle(json.id, true, true));
}
catch (e) {
logger.error(["Get Style Info"], e);
}
full++;
logger.info(["Get Style Info"], `Style ${json.id} is fully saved. Progress: ${regular+full}/${total} (full: ${full}, regular: ${regular})`);
} else {
// const styleData = uso.convertStyle(json);
// await uso.saveStyle({ usercss: styleData.usercss, markdown: styleData.markdown });
regular++;
// logger.info(["Get Style Info"], `Style ${json.id} is saved. Progress: ${regular+full}/${total} (full: ${full}, regular: ${regular})`);
}
started--;
})().catch(e => logger.error(["Get Style Info"], e));
}
await utils.waitUntilTrue(() => started === 0, 5000);
}
main().catch(e => logger.error(["Get Style Info"], e));