mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-07 05:14:16 +02:00
Fancier dev setup
This commit is contained in:
parent
a4428fd5be
commit
ba738244ab
7 changed files with 107 additions and 73 deletions
39
tools/util.mjs
Normal file
39
tools/util.mjs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function readEnvFile() {
|
||||
if (!fs.existsSync('.env')) {
|
||||
console.error('No configured .env file. Copy .env.example to .env and configure it.');
|
||||
process.exit();
|
||||
}
|
||||
|
||||
const envFile = fs.readFileSync('.env', 'utf8');
|
||||
envFile.split('\n').forEach(line => {
|
||||
const [key, value] = line.split('=');
|
||||
if (key && value) {
|
||||
process.env[key] = value;
|
||||
}
|
||||
});
|
||||
|
||||
// Determine foundry path, handling if its an electron install (nested structure)
|
||||
const foundryPath = path.normalize(process.env.FOUNDRY_MAIN_PATH);
|
||||
const dataPath = path.normalize(process.env.FOUNDRY_DATA_PATH);
|
||||
if (!foundryPath.endsWith(path.join('app', 'main.js'))) {
|
||||
console.error('Configured FOUNDRY_MAIN_PATH is invalid, it must end with app/main.js');
|
||||
process.exit();
|
||||
}
|
||||
if (/Data(\/|\\)?$/.test(dataPath) || !fs.existsSync(path.join(dataPath, 'Data'))) {
|
||||
console.error('Configured FOUNDRY_DATA_PATH is incorrect. This must be a folder that contains "Data"');
|
||||
}
|
||||
|
||||
return {
|
||||
foundryPath,
|
||||
foundryRoot: path.dirname(foundryPath),
|
||||
dataPath
|
||||
};
|
||||
}
|
||||
|
||||
export function isContainedPath(parent, child) {
|
||||
const relative = path.relative(parent, child);
|
||||
return relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue