Skip to content

Commit 035975f

Browse files
committed
Add command to start Foundry
1 parent 78f6a75 commit 035975f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

build/start-foundry.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import fs from "fs-extra";
2+
import path from "path";
3+
import process from "process";
4+
import prompts from "prompts";
5+
import { dataPath, fvtt } from "../foundryconfig.json";
6+
import { exec } from "child_process";
7+
import { promisify } from "util";
8+
9+
const fvttVersion = (
10+
await prompts({
11+
type: "select",
12+
name: "value",
13+
message: "Select the FoundryVTT version you want to use.",
14+
choices: Object.keys(fvtt).map((version) => ({
15+
title: version,
16+
value: version,
17+
})),
18+
})
19+
).value as string;
20+
21+
const fvttPath = fvtt[fvttVersion];
22+
23+
if (!fvttPath) {
24+
console.error(`FoundryVTT version "${fvttVersion}" not found.`);
25+
process.exit(1);
26+
}
27+
28+
if (!dataPath || !/\bData$/.test(dataPath)) {
29+
console.error(`"${dataPath}" does not look like a Foundry data folder.`);
30+
process.exit(1);
31+
}
32+
33+
const entryPoint = path.resolve(fvttPath, "resources", "app", "main.js");
34+
35+
if (!fs.existsSync(entryPoint)) {
36+
console.error(`Cannot start FoundryVTT. "${entryPoint}" does not exist.`);
37+
process.exit(1);
38+
}
39+
40+
const execAsync = promisify(exec);
41+
42+
const startFoundry = async () => {
43+
console.log(`Starting FoundryVTT from ${entryPoint}...`);
44+
45+
try {
46+
const { stdout, stderr } = await execAsync(
47+
`node ${entryPoint} --datapath=${dataPath}`,
48+
);
49+
console.log(`stdout: ${stdout}`);
50+
if (stderr) console.error(`stderr: ${stderr}`);
51+
} catch (error) {
52+
console.error(error);
53+
}
54+
};
55+
56+
startFoundry().catch(console.error);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"stage": "tsc && npm run clean && vite build --mode stage",
1010
"dev": "tsc && npm run clean && vite build --mode development",
1111
"clean": "tsx ./build/clean.ts",
12+
"foundry": "tsx ./build/start-foundry.ts",
1213
"hot": "vite serve",
1314
"watch": "tsc && npm run clean && vite build --watch --mode development",
1415
"link": "tsx ./build/link-foundry.ts",

0 commit comments

Comments
 (0)