-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbuild.mjs
More file actions
49 lines (43 loc) · 1.59 KB
/
Copy pathbuild.mjs
File metadata and controls
49 lines (43 loc) · 1.59 KB
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
45
46
47
48
49
import { compilePack } from "@foundryvtt/foundryvtt-cli";
import { existsSync } from "fs";
import fs from "fs/promises";
import path from "path";
// Clean output directory, or create build directory
const outDir = path.resolve(process.cwd(), "build");
if (existsSync(outDir)) {
const filesToClean = (await fs.readdir(outDir)).map((dirName) => path.resolve(outDir, dirName));
for (const file of filesToClean) {
await fs.rm(file, { recursive: true });
}
} else {
await fs.mkdir(outDir);
}
console.log("Clean Finished");
// Build packs
const packFolders = await fs.readdir("packs");
for (const pack of packFolders) {
await compilePack(`packs/${pack}`, path.resolve(outDir, `packs/${pack}`));
}
console.log("Build Packs Finished");
// Copy files and folders to output
const files = ["art", "assets", "fonts", "lang", "scripts", "styles", "module.json", "ORCLicense.md"];
for (const file of files) {
await fs.cp(file, path.resolve(outDir, file), { recursive: true });
}
console.log("Build Complete");
if (process.argv[2] === "--watch") {
const watcher = fs.watch(process.cwd(), { recursive: true });
console.log("Watching Files");
for await (const event of watcher) {
const file = (event.filename ?? "").split(path.sep)[0];
if (files.includes(file)) {
const outFile = path.resolve(outDir, file);
if (existsSync(file)) {
await fs.cp(file, outFile , { recursive: true });
} else {
await fs.rm(outFile, { recursive: true })
}
console.log("Files updated");
}
}
}