Add a script for linking Foundry into the project root
This commit is contained in:
parent
d15301663c
commit
bf06edc5c6
6 changed files with 69 additions and 2 deletions
2
.env.template
Normal file
2
.env.template
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# The absolute path to the Foundry installation to create symlinks to
|
||||||
|
FOUNDRY_ROOT=""
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,6 +1,7 @@
|
||||||
dist/
|
dist/
|
||||||
*.link
|
*.link
|
||||||
*.txt
|
*.txt
|
||||||
|
/foundry
|
||||||
|
|
||||||
# Dependency directories
|
# Dependency directories
|
||||||
node_modules/
|
node_modules/
|
||||||
|
|
|
||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
|
|
@ -1,9 +1,10 @@
|
||||||
{
|
{
|
||||||
"files.exclude": {
|
"files.exclude": {
|
||||||
"**/node_modules": true
|
"**/node_modules": true,
|
||||||
|
"foundry": true
|
||||||
},
|
},
|
||||||
"search.exclude": {
|
"search.exclude": {
|
||||||
"foundry.*.link": true
|
"foundry": true
|
||||||
},
|
},
|
||||||
"html.customData": [
|
"html.customData": [
|
||||||
"./.vscode/foundry.html-data.json",
|
"./.vscode/foundry.html-data.json",
|
||||||
|
|
|
||||||
14
package-lock.json
generated
14
package-lock.json
generated
|
|
@ -8,6 +8,7 @@
|
||||||
"@eslint/js": "^9.16.0",
|
"@eslint/js": "^9.16.0",
|
||||||
"@foundryvtt/foundryvtt-cli": "^1.0.3",
|
"@foundryvtt/foundryvtt-cli": "^1.0.3",
|
||||||
"@stylistic/eslint-plugin": "^2.12.0",
|
"@stylistic/eslint-plugin": "^2.12.0",
|
||||||
|
"dotenv": "^17.2.3",
|
||||||
"eslint": "^9.16.0"
|
"eslint": "^9.16.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -775,6 +776,19 @@
|
||||||
"url": "https://github.com/sponsors/ljharb"
|
"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": {
|
"node_modules/dunder-proto": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,11 @@
|
||||||
"@eslint/js": "^9.16.0",
|
"@eslint/js": "^9.16.0",
|
||||||
"@foundryvtt/foundryvtt-cli": "^1.0.3",
|
"@foundryvtt/foundryvtt-cli": "^1.0.3",
|
||||||
"@stylistic/eslint-plugin": "^2.12.0",
|
"@stylistic/eslint-plugin": "^2.12.0",
|
||||||
|
"dotenv": "^17.2.3",
|
||||||
"eslint": "^9.16.0"
|
"eslint": "^9.16.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"link": "node scripts/linkFoundry.mjs",
|
||||||
"lint": "eslint --fix",
|
"lint": "eslint --fix",
|
||||||
"lint:nofix": "eslint"
|
"lint:nofix": "eslint"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
47
scripts/linkFoundry.mjs
Normal file
47
scripts/linkFoundry.mjs
Normal 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);
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue