-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild-packs.ts
44 lines (38 loc) · 1.48 KB
/
build-packs.ts
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
import fs from "fs-extra";
import path from "path";
const packsSource = "packs";
const pf2eSystemPath = (() => {
const configPath = path.resolve(process.cwd(), "foundryconfig.json");
const configData = fs.existsSync(configPath) ? fs.readJSONSync(configPath) : undefined;
return configData !== undefined ? path.join(configData.dataPath, "Data", "modules", configData.moduleName) : null;
})();
const outDir = pf2eSystemPath ?? path.join(__dirname, "dist/");
function getFolders(dir: string) {
const results: string[] = [];
const folders = fs.readdirSync(packsSource);
for (const folder of folders) {
const stat = fs.statSync(path.join(dir, folder));
if (stat.isDirectory()) {
results.push(folder);
}
}
return folders;
}
fs.mkdirsSync(path.resolve(outDir, "packs"));
const folders = getFolders(packsSource);
for (const folder of folders) {
const folderPath = path.join(packsSource, folder);
const lines: string[] = [];
for (const file of fs.readdirSync(folderPath)) {
const filePath = path.join(folderPath, file);
try {
const contents = fs.readJSONSync(filePath, { encoding: "utf8" });
const minimized = JSON.stringify(contents);
lines.push(minimized);
} catch (err) {
console.error(`Failed to read JSON file ${filePath}`, err);
}
}
const result = lines.join("\n");
fs.writeFileSync(path.resolve(outDir, "packs", folder), result, "utf8");
}