From 6866bea13160c996e375b463d6b52f415449e8fd Mon Sep 17 00:00:00 2001 From: Eldritch-Oliver Date: Sun, 28 Sep 2025 00:34:49 -0600 Subject: [PATCH] Update scripts to allow auto-linking of Foundry source for intellisense --- .gitignore | 1 + .vscode/settings.json | 2 +- augments.d.ts | 5 +++++ eslint.config.mjs | 2 +- jsconfig.json | 16 +++++++++++++-- package.json | 3 +++ scripts/linkFoundry.mjs | 45 +++++++++++++++++++++++++++++++++++++---- 7 files changed, 66 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 7ab2098..f3a0af4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules/ deprecated .env +/foundry diff --git a/.vscode/settings.json b/.vscode/settings.json index 70ee187..aa3ed17 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,7 +11,7 @@ ".styles": false, "node_modules": true, "packs": true, - "foundry": false + "foundry": true }, "html.customData": [ "./.vscode/components.html-data.json" diff --git a/augments.d.ts b/augments.d.ts index df16590..a08bb60 100644 --- a/augments.d.ts +++ b/augments.d.ts @@ -1,3 +1,8 @@ +declare global { + class Hooks extends foundry.helpers.Hooks {}; + const fromUuid = foundry.utils.fromUuid; +} + interface Actor { /** The system-specific data */ system: any; diff --git a/eslint.config.mjs b/eslint.config.mjs index 454af9e..55aea5c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -4,7 +4,7 @@ import stylistic from "@stylistic/eslint-plugin"; export default [ // Tell eslint to ignore files that I don't mind being formatted slightly differently - { ignores: [ `scripts/` ] }, + { ignores: [ `scripts/`, `foundry/*` ] }, { languageOptions: { globals: globals.browser, diff --git a/jsconfig.json b/jsconfig.json index 231558c..fd36906 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,7 +1,19 @@ { "compilerOptions": { + "module": "es2022", + "target": "es2022", "types": [ "./augments.d.ts" - ] - } + ], + "paths": { + "@client/*": ["./foundry/client/*"], + "@common/*": ["./foundry/common/*"], + } + }, + "include": [ + "module/main.mjs", + "foundry/client/client.mjs", + "foundry/client/global.d.mts", + "foundry/common/primitives/global.d.mts" + ] } diff --git a/package.json b/package.json index 4804900..c2b1830 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,9 @@ "globals": "^15.9.0" }, "scripts": { + "build": "node scripts/buildCompendia.mjs", + "extract": "node scripts/extractCompendia.mjs", + "link": "node scripts/linkFoundry.mjs", "lint": "eslint --fix", "lint:nofix": "eslint" } diff --git a/scripts/linkFoundry.mjs b/scripts/linkFoundry.mjs index 2ed162f..1cbb71a 100644 --- a/scripts/linkFoundry.mjs +++ b/scripts/linkFoundry.mjs @@ -1,10 +1,47 @@ +import { existsSync } from "fs"; +import { symlink, unlink } from "fs/promises"; +import { join } from "path"; import { config } from "dotenv"; -config(); -console.log(process.env) +config({ quiet: true }); + const root = process.env.FOUNDRY_ROOT; // Early exit -if (!root) { process.exit(1) }; +if (!root) { + console.error(`Must provide a FOUNDRY_ROOT environment variable`); + process.exit(1); +}; -// Assert root exists +// 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); +};