Add setup script for development (#981)

This commit is contained in:
Luiz HD Costa 2025-08-17 13:51:29 -03:00 committed by GitHub
parent 505ee6d3cf
commit e692f3814d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 82 additions and 16 deletions

2
.env.example Normal file
View file

@ -0,0 +1,2 @@
FOUNDRY_MAIN_PATH=/path/to/foundry/resources/app/main.js
FOUNDRY_DATA_PATH=/path/to/foundry/data

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
.vscode .vscode
.env
node_modules node_modules
/packs /packs
Build Build

View file

@ -24,24 +24,41 @@ You can find the documentation here: https://github.com/Foundryborne/daggerheart
## Development Setup ## Development Setup
- Open a terminal in the directory with the repo `cd <path>/<to>/<repo>` 1. **Navigate to the repo directory:**
- 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 <path to development folder> daggerheart` inside the system folder
- Install npm `npm install`
- Update package.json to match your profile
``` ```bash
"start": "concurrently \"rollup -c --watch\" \"node C:/FoundryDev/resources/app/main.js --dataPath=C:/FoundryDevFiles --noupnp\" \"gulp\"", cd <path>/<to>/<repo>
"start-test": "node C:/FoundryDev/resources/app/main.js --dataPath=C:/FoundryDevFiles && rollup -c --watch && gulp", ```
``` 2. **Install dependencies:**
- Replace `C:/FoundryDev/resources/app/main.js` with `<your>/<path>/<to>/<foundry>/<main.js>` ```bash
- The main is likely in `<Foundry Install Location>/resouces/app/main.js` npm install
- Replace `--dataPath=C:/FoundryDevFiles` with `<your>/<path>/<to>/<foundry>/<data>` ```
Now you should be able to build the app using `npm start` 3. **Configure your Foundry paths:**
[Foundry VTT Website][1]
```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="<path>" --data-path="<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 <path to development folder> 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/ [1]: https://foundryvtt.com/

View file

@ -7,7 +7,7 @@
"rollup": "^4.40.0" "rollup": "^4.40.0"
}, },
"scripts": { "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", "start-test": "node ./resources/app/main.js --dataPath=./ && rollup -c --watch && gulp",
"build": "npm run rollup && npm run gulp", "build": "npm run rollup && npm run gulp",
"rollup": "rollup -c", "rollup": "rollup -c",
@ -16,7 +16,8 @@
"pushLDBtoYML": "node ./tools/pushLDBtoYML.mjs", "pushLDBtoYML": "node ./tools/pushLDBtoYML.mjs",
"pullYMLtoLDB": "node ./tools/pullYMLtoLDB.mjs", "pullYMLtoLDB": "node ./tools/pullYMLtoLDB.mjs",
"pullYMLtoLDBBuild": "node ./tools/pullYMLtoLDBBuild.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": { "devDependencies": {
"@foundryvtt/foundryvtt-cli": "^1.0.2", "@foundryvtt/foundryvtt-cli": "^1.0.2",

18
tools/dev-setup.mjs Normal file
View file

@ -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}`);

27
tools/run-start.mjs Normal file
View file

@ -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
});