|
| 1 | +import Config from "../config.mjs"; |
| 2 | +import {spawn} from "child_process"; |
| 3 | +import path from "path"; |
| 4 | + |
| 5 | +export function getCommand() { |
| 6 | + return { |
| 7 | + command: "launch", |
| 8 | + describe: "Launch Foundry VTT", |
| 9 | + builder: (yargs) => { |
| 10 | + yargs.option("demo", { |
| 11 | + describe: "Launch Foundry VTT in demo mode", |
| 12 | + type: "boolean", |
| 13 | + default: false |
| 14 | + }); |
| 15 | + |
| 16 | + yargs.option("port", { |
| 17 | + describe: "The port to launch Foundry VTT on", |
| 18 | + type: "number", |
| 19 | + default: 30000 |
| 20 | + }); |
| 21 | + |
| 22 | + yargs.option("world", { |
| 23 | + describe: "The world to launch Foundry VTT with", |
| 24 | + type: "string" |
| 25 | + }); |
| 26 | + |
| 27 | + yargs.option("noupnp", { |
| 28 | + describe: "Disable UPnP port forwarding", |
| 29 | + type: "boolean", |
| 30 | + default: false |
| 31 | + }); |
| 32 | + |
| 33 | + yargs.option("noupdate", { |
| 34 | + describe: "Disable automatic update checking", |
| 35 | + type: "boolean", |
| 36 | + default: false |
| 37 | + }); |
| 38 | + |
| 39 | + yargs.option("adminKey", { |
| 40 | + describe: "The admin key to secure Foundry VTT's Setup screen with", |
| 41 | + type: "string" |
| 42 | + }); |
| 43 | + }, |
| 44 | + handler: async (argv) => { |
| 45 | + |
| 46 | + // Run the command node main.js --debug --port 30000 |
| 47 | + // Launch Foundry VTT in debug mode on port 30000 |
| 48 | + const {demo, port, world, noupnp, noupdate, adminKey} = argv; |
| 49 | + |
| 50 | + // Determine the installation path |
| 51 | + const installPath = Config.instance.get("installPath"); |
| 52 | + if ( !installPath ) { |
| 53 | + console.error("The installation path is not set. Use `configure set installPath <path>` to set it. Install paths look like `C:/Program Files/Foundry Virtual Tabletop`"); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
| 57 | + // Determine the data path |
| 58 | + const dataPath = Config.instance.get("dataPath"); |
| 59 | + if ( !dataPath ) { |
| 60 | + console.error("The data path is not set. Use `configure set dataPath <path>` to set it. Data paths look like `C:/Users/Example/AppData/Local/FoundryVTT/Data`"); |
| 61 | + return; |
| 62 | + } |
| 63 | + |
| 64 | + function normalizePath(pathToNormalize) { |
| 65 | + return path.normalize(pathToNormalize).split(path.sep).join(path.posix.sep); |
| 66 | + } |
| 67 | + |
| 68 | + // Launch Foundry VTT |
| 69 | + const foundry = spawn("node", [ |
| 70 | + normalizePath(path.join(installPath, "resources", "app", "main.js")), |
| 71 | + `--dataPath=${dataPath}`, |
| 72 | + `--port=${port}`, |
| 73 | + demo ? "--demo" : "", |
| 74 | + world ? `--world=${world}` : "", |
| 75 | + noupnp ? "--noupnp" : "", |
| 76 | + noupdate ? "--noupdate" : "", |
| 77 | + adminKey ? `--adminKey=${adminKey}` : "" |
| 78 | + ]); |
| 79 | + foundry.stdout.on("data", (data) => { |
| 80 | + console.log(data.toString()); |
| 81 | + }); |
| 82 | + foundry.stderr.on("data", (data) => { |
| 83 | + console.error(data.toString()); |
| 84 | + }); |
| 85 | + foundry.on("close", (code) => { |
| 86 | + console.log(`Foundry VTT exited with code ${code}`); |
| 87 | + }); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments