|
| 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); |
0 commit comments