mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-07 13:24:16 +02:00
Fancier dev setup
This commit is contained in:
parent
a4428fd5be
commit
ba738244ab
7 changed files with 107 additions and 73 deletions
|
|
@ -1,47 +1,70 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import readline from 'readline';
|
||||
import { isContainedPath, readEnvFile } from './util.mjs';
|
||||
|
||||
console.log('Creates a foundry symlink in the base folder for type purposes\n');
|
||||
const projectRoot = path.resolve(import.meta.dirname, '../')
|
||||
const { foundryRoot, dataPath } = readEnvFile();
|
||||
|
||||
const askQuestion = question => {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
async function createFoundrySymlink() {
|
||||
// If foundry already exists, exit and inform the user. This operation can't complete correctly otherwise.
|
||||
// If the folder is empty, its fine. It may have failed due to perms
|
||||
const foundryDestPath = path.join(projectRoot, 'foundry');
|
||||
if (fs.existsSync(foundryDestPath) && fs.readdirSync(foundryDestPath).length) {
|
||||
console.log('"foundry" folder already exists in this project');
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise(resolve =>
|
||||
rl.question(question, answer => {
|
||||
rl.close();
|
||||
resolve(answer);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
const installPath = await askQuestion('Enter your Foundry install path: ');
|
||||
|
||||
// Determine if it's an Electron install (nested structure)
|
||||
const nested = fs.existsSync(path.join(installPath, 'resources', 'app'));
|
||||
const fileRoot = nested ? path.join(installPath, 'resources', 'app') : installPath;
|
||||
|
||||
try {
|
||||
await fs.promises.mkdir('foundry');
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
}
|
||||
|
||||
// JavaScript files
|
||||
for (const p of ['client', 'common', 'tsconfig.json']) {
|
||||
console.log('Creating "foundry" symlinks for types');
|
||||
try {
|
||||
await fs.promises.symlink(path.join(fileRoot, p), path.join('foundry', p));
|
||||
await fs.promises.mkdir(foundryDestPath);
|
||||
console.log('Root foundry folder created');
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
}
|
||||
|
||||
// JavaScript files
|
||||
for (const p of ['client', 'common', 'tsconfig.json']) {
|
||||
try {
|
||||
await fs.promises.symlink(path.join(foundryRoot, p), path.join(foundryDestPath, p));
|
||||
console.log(`${p} folder created`);
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// Language files
|
||||
try {
|
||||
await fs.promises.symlink(path.join(foundryRoot, 'public', 'lang'), path.join(foundryDestPath, 'lang'));
|
||||
console.log(`lang folder created`);
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
console.log(`lang folder already exists`);
|
||||
}
|
||||
}
|
||||
|
||||
// Language files
|
||||
try {
|
||||
await fs.promises.symlink(path.join(fileRoot, 'public', 'lang'), path.join('foundry', 'lang'));
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
async function createDaggerheartSymlink() {
|
||||
if (isContainedPath(dataPath, projectRoot)) {
|
||||
console.log('The Daggerheart project repo is in foundry data, so a symlink won\'t be created');
|
||||
return;
|
||||
}
|
||||
|
||||
const destination = path.join(dataPath, 'Data', 'systems', 'daggerheart');
|
||||
if (fs.existsSync(destination)) {
|
||||
console.log('A Daggerheart folder already exists in Foundry data');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Creating Daggerheart symlink in the foundry systems folder')
|
||||
try {
|
||||
await fs.promises.symlink(projectRoot, destination);
|
||||
console.log('Daggerheart system folder symlink created');
|
||||
} catch (e) {
|
||||
if (e.code !== 'EEXIST') throw e;
|
||||
console.log(`Daggerheart system folder already exists`);
|
||||
}
|
||||
}
|
||||
|
||||
await createFoundrySymlink();
|
||||
console.log();
|
||||
await createDaggerheartSymlink();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue