-
Notifications
You must be signed in to change notification settings - Fork 16
/
extract-packs.mjs
37 lines (31 loc) · 1.21 KB
/
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
31
32
33
34
35
36
37
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);
const replacer = (key, value) => {
if (key === "createdTime") return undefined
if (key === "modifiedTime") return undefined
if (key === "lastModifiedBy") return undefined
return value
}
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}`, {jsonOptions: {replacer: replacer, space: 2}});
}
console.log("Extraction Complete");