This commit is contained in:
+40
-7
@@ -14,17 +14,50 @@
|
||||
|
||||
import ExcelJS from "exceljs"
|
||||
|
||||
//import parseV1V2 from "./parse/v1_v2.js";
|
||||
import parseV3 from "./parse/v3.js";
|
||||
import generateArchivedV1_V2 from "./parse/archived/v1_v2.js";
|
||||
import parseV3 from "./parse/v3.js";
|
||||
import fs from "fs/promises";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export default async function parseThisShit(downloadedFilePath: string) {
|
||||
type Save = {
|
||||
filePath: string | string[],
|
||||
parser: (workbook: ExcelJS.Workbook, downloadedFilePath: string) => Promise<any>
|
||||
}
|
||||
|
||||
async function doAll(saves: Save[], workbook: ExcelJS.Workbook, downloadedFilePath: string) {
|
||||
const promises = saves.map(save => {
|
||||
return (async function() {
|
||||
const res = await save.parser(workbook, downloadedFilePath);
|
||||
|
||||
if (typeof save.filePath === "string") {
|
||||
save.filePath = [save.filePath];
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
save.filePath.map(filePath => fs.writeFile(filePath, JSON.stringify(res)))
|
||||
);
|
||||
})()
|
||||
})
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
export default async function parseAll(downloadedFilePath: string) {
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.readFile(downloadedFilePath);
|
||||
|
||||
//await parseV1V2(workbook);
|
||||
await generateArchivedV1_V2();
|
||||
await parseV3(workbook, downloadedFilePath);
|
||||
await doAll([
|
||||
{
|
||||
filePath: ["volume/db/v1.json", "volume/db/v2.json"],
|
||||
parser: generateArchivedV1_V2,
|
||||
},
|
||||
{
|
||||
filePath: "volume/db/v3.json",
|
||||
parser: parseV3
|
||||
},
|
||||
], workbook, downloadedFilePath);
|
||||
}
|
||||
|
||||
//parseThisShit("volume/db/current.xlsx")
|
||||
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
||||
await parseAll("volume/db/current.xlsx");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user