forked from foundryvtt/pf2e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-packs.ts
20 lines (17 loc) · 933 Bytes
/
build-packs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import fs from "fs";
import path from "path";
import url from "url";
import { CompendiumPack, PackError } from "./lib/compendium-pack.ts";
const asJson = process.argv[2]?.toLowerCase() === "json";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const packsDataPath = path.resolve(__dirname, "../packs");
const packDirPaths = fs.readdirSync(packsDataPath).map((dirName) => path.resolve(__dirname, packsDataPath, dirName));
// Loads all packs into memory for the sake of making all document name/id mappings available
const packs = packDirPaths.map((p) => CompendiumPack.loadJSON(p));
const documentCounts = await Promise.all(packs.map((p) => p.save(asJson)));
const total = documentCounts.reduce((total, c) => total + c, 0);
if (documentCounts.length > 0) {
console.log(`Created ${documentCounts.length} packs with ${total} documents.`);
} else {
throw PackError("No data available to build packs.");
}