diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..180dbd6 --- /dev/null +++ b/.env.template @@ -0,0 +1,2 @@ +# The absolute path to the Foundry installation to create symlinks to +FOUNDRY_ROOT="" diff --git a/.gitignore b/.gitignore index a86caf7..6ef05ba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ dist/ *.link *.txt +/foundry # Dependency directories node_modules/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 8463326..c60389c 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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", diff --git a/package-lock.json b/package-lock.json index 9384e26..af1a200 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 9b335a7..1c663e7 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/scripts/linkFoundry.mjs b/scripts/linkFoundry.mjs new file mode 100644 index 0000000..3ee94c5 --- /dev/null +++ b/scripts/linkFoundry.mjs @@ -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); +};