From e692f3814d37e4981ce0a54ea4e7ffdea49b67d6 Mon Sep 17 00:00:00 2001 From: Luiz HD Costa Date: Sun, 17 Aug 2025 13:51:29 -0300 Subject: [PATCH] Add setup script for development (#981) --- .env.example | 2 ++ .gitignore | 1 + README.md | 45 +++++++++++++++++++++++++++++++-------------- package.json | 5 +++-- tools/dev-setup.mjs | 18 ++++++++++++++++++ tools/run-start.mjs | 27 +++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 16 deletions(-) create mode 100644 .env.example create mode 100644 tools/dev-setup.mjs create mode 100644 tools/run-start.mjs diff --git a/.env.example b/.env.example new file mode 100644 index 00000000..730309d3 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +FOUNDRY_MAIN_PATH=/path/to/foundry/resources/app/main.js +FOUNDRY_DATA_PATH=/path/to/foundry/data \ No newline at end of file diff --git a/.gitignore b/.gitignore index 264581a4..9a22c0ce 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vscode +.env node_modules /packs Build diff --git a/README.md b/README.md index fda78b4b..0c2dabc3 100644 --- a/README.md +++ b/README.md @@ -24,24 +24,41 @@ You can find the documentation here: https://github.com/Foundryborne/daggerheart ## Development Setup -- Open a terminal in the directory with the repo `cd //` -- NOTE: The repo should be placed in the system files are or somewhere else and a link (if on linux) is placed in the system directory -- NOTE: Linux link can be made using `ln -snf daggerheart` inside the system folder -- Install npm `npm install` -- Update package.json to match your profile +1. **Navigate to the repo directory:** -``` -"start": "concurrently \"rollup -c --watch\" \"node C:/FoundryDev/resources/app/main.js --dataPath=C:/FoundryDevFiles --noupnp\" \"gulp\"", -"start-test": "node C:/FoundryDev/resources/app/main.js --dataPath=C:/FoundryDevFiles && rollup -c --watch && gulp", + ```bash + cd // + ``` -``` +2. **Install dependencies:** -- Replace `C:/FoundryDev/resources/app/main.js` with `////` -- The main is likely in `/resouces/app/main.js` -- Replace `--dataPath=C:/FoundryDevFiles` with `////` + ```bash + npm install + ``` -Now you should be able to build the app using `npm start` -[Foundry VTT Website][1] +3. **Configure your Foundry paths:** + + ```bash + npm run setup:dev -- --foundry-path="/path/to/foundry/main.js" --data-path="/path/to/data" + ``` + +4. **Start developing:** + ```bash + npm start + ``` + +### Available Scripts + +- `npm start` - Start development with file watching and Foundry launching +- `npm run build` - One-time build +- `npm run setup:dev -- --foundry-path="" --data-path=""` - Configure development environment + +### Notes + +- The repo should be placed in your Foundry `Data/systems/` directory or symlinked there +- Linux symlink can be made using `ln -snf daggerheart` inside the systems folder +- Your `.env` file is ignored by git, so each developer can have their own configuration + [Foundry VTT Website][1] [1]: https://foundryvtt.com/ diff --git a/package.json b/package.json index 023ccff2..dbece0c7 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "rollup": "^4.40.0" }, "scripts": { - "start": "concurrently \"rollup -c --watch\" \"node ../../../../FoundryDev/main.js --dataPath=../../../ --noupnp\" \"gulp\"", + "start": "node ./tools/run-start.mjs", "start-test": "node ./resources/app/main.js --dataPath=./ && rollup -c --watch && gulp", "build": "npm run rollup && npm run gulp", "rollup": "rollup -c", @@ -16,7 +16,8 @@ "pushLDBtoYML": "node ./tools/pushLDBtoYML.mjs", "pullYMLtoLDB": "node ./tools/pullYMLtoLDB.mjs", "pullYMLtoLDBBuild": "node ./tools/pullYMLtoLDBBuild.mjs", - "createSymlink": "node ./tools/create-symlink.mjs" + "createSymlink": "node ./tools/create-symlink.mjs", + "setup:dev": "node ./tools/dev-setup.mjs" }, "devDependencies": { "@foundryvtt/foundryvtt-cli": "^1.0.2", diff --git a/tools/dev-setup.mjs b/tools/dev-setup.mjs new file mode 100644 index 00000000..f232f5a8 --- /dev/null +++ b/tools/dev-setup.mjs @@ -0,0 +1,18 @@ +#!/usr/bin/env node +import fs from 'fs'; + +const args = process.argv.slice(2); +const foundryPath = args.find(arg => arg.startsWith('--foundry-path='))?.split('=')[1]; +const dataPath = args.find(arg => arg.startsWith('--data-path='))?.split('=')[1]; + +if (!foundryPath || !dataPath) { + console.log('Usage: npm run setup:dev -- --foundry-path="/path/to/foundry/main.js" --data-path="/path/to/data"'); + process.exit(1); +} + +const envContent = `FOUNDRY_MAIN_PATH=${foundryPath} +FOUNDRY_DATA_PATH=${dataPath} +`; + +fs.writeFileSync('.env', envContent); +console.log(`✅ Development environment configured: ${foundryPath}, ${dataPath}`); diff --git a/tools/run-start.mjs b/tools/run-start.mjs new file mode 100644 index 00000000..e620d13f --- /dev/null +++ b/tools/run-start.mjs @@ -0,0 +1,27 @@ +#!/usr/bin/env node +import { spawn } from 'child_process'; +import fs from 'fs'; + +// Load .env file if it exists +if (fs.existsSync('.env')) { + const envFile = fs.readFileSync('.env', 'utf8'); + envFile.split('\n').forEach(line => { + const [key, value] = line.split('='); + if (key && value) { + process.env[key] = value; + } + }); +} + +// Set defaults if not in environment +const foundryPath = process.env.FOUNDRY_MAIN_PATH || '../../../../FoundryDev/main.js'; +const dataPath = process.env.FOUNDRY_DATA_PATH || '../../../'; + +// Run the original command with proper environment +const args = ['rollup -c --watch', `node "${foundryPath}" --dataPath="${dataPath}" --noupnp`, 'gulp']; + +spawn('npx', ['concurrently', ...args.map(arg => `"${arg}"`)], { + stdio: 'inherit', + cwd: process.cwd(), + shell: true +});