-
Notifications
You must be signed in to change notification settings - Fork 15
/
extract-packs.mjs
30 lines (25 loc) · 982 Bytes
/
extract-packs.mjs
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
import { extractPack } from "@foundryvtt/foundryvtt-cli";
import { existsSync } from "fs";
import fs from "fs/promises";
import path from "path";
const outDir = path.resolve(process.cwd(), "build");
const packsCompiled = path.resolve(outDir, "packs/");
if (!existsSync(packsCompiled)) {
console.error("Packs directory does not exist in the build");
}
const packFolders = await fs.readdir(packsCompiled);
console.log("Cleaning packs");
for (const pack of packFolders) {
const files = await fs.readdir(`packs/${pack}`, { withFileTypes: true });
const jsonFiles = files
.filter((f) => f.isFile() && f.name.toLowerCase().endsWith(".json"))
.map((f) => f.name);
for (const file of jsonFiles) {
await fs.rm(path.resolve("packs", pack, file));
}
}
for (const pack of packFolders) {
console.log(`Extracting pack: ${pack}`);
await extractPack(path.resolve(packsCompiled, pack), `packs/${pack}`);
}
console.log("Extraction Complete");