Add a script for linking Foundry into the project root

This commit is contained in:
Eldritch-Oliver 2025-10-04 20:43:41 -06:00
parent d15301663c
commit bf06edc5c6
6 changed files with 69 additions and 2 deletions

2
.env.template Normal file
View file

@ -0,0 +1,2 @@
# The absolute path to the Foundry installation to create symlinks to
FOUNDRY_ROOT=""

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
dist/
*.link
*.txt
/foundry
# Dependency directories
node_modules/

View file

@ -1,9 +1,10 @@
{
"files.exclude": {
"**/node_modules": true
"**/node_modules": true,
"foundry": true
},
"search.exclude": {
"foundry.*.link": true
"foundry": true
},
"html.customData": [
"./.vscode/foundry.html-data.json",

14
package-lock.json generated
View file

@ -8,6 +8,7 @@
"@eslint/js": "^9.16.0",
"@foundryvtt/foundryvtt-cli": "^1.0.3",
"@stylistic/eslint-plugin": "^2.12.0",
"dotenv": "^17.2.3",
"eslint": "^9.16.0"
}
},
@ -775,6 +776,19 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/dotenv": {
"version": "17.2.3",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz",
"integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==",
"dev": true,
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/dunder-proto": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.0.tgz",

View file

@ -3,9 +3,11 @@
"@eslint/js": "^9.16.0",
"@foundryvtt/foundryvtt-cli": "^1.0.3",
"@stylistic/eslint-plugin": "^2.12.0",
"dotenv": "^17.2.3",
"eslint": "^9.16.0"
},
"scripts": {
"link": "node scripts/linkFoundry.mjs",
"lint": "eslint --fix",
"lint:nofix": "eslint"
}

47
scripts/linkFoundry.mjs Normal file
View file

@ -0,0 +1,47 @@
import { existsSync } from "fs";
import { symlink, unlink } from "fs/promises";
import { join } from "path";
import { config } from "dotenv";
config({ quiet: true });
const root = process.env.FOUNDRY_ROOT;
// Early exit
if (!root) {
console.error(`Must provide a FOUNDRY_ROOT environment variable`);
process.exit(1);
};
// Assert Foundry exists
if (!existsSync(root)) {
console.error(`Foundry root not found.`);
process.exit(1);
};
// Removing existing symlink
if (existsSync(`foundry`)) {
console.log(`Attempting to unlink foundry instance`);
try {
await unlink(`foundry`);
} catch {
console.error(`Failed to unlink foundry folder.`);
process.exit(1);
};
};
// Account for if the root is pointing at an Electron install
let targetRoot = root;
if (existsSync(join(root, `resources`, `app`))) {
console.log(`Switching to use the "${root}/resources/app" directory`);
targetRoot = join(root, `resources`, `app`);
};
// Create symlink
console.log(`Linking foundry source into folder`);
try {
await symlink(targetRoot, `foundry`);
} catch (e) {
console.error(e);
process.exit(1);
};