-
Notifications
You must be signed in to change notification settings - Fork 14
/
symlink-module-build-dir.js
58 lines (48 loc) · 1.63 KB
/
symlink-module-build-dir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import yargs from 'yargs/yargs';
import {hideBin} from 'yargs/helpers';
import fs from 'fs-extra';
import {resolve} from 'path';
const {ensureDir, existsSync, readJSONSync, remove, symlink} = fs;
const argv = yargs(hideBin(process.argv)).argv;
const moduleDirectory = 'tidy5e-sheet';
const buildDirectory = './dist';
/**
* Get the data path for Foundry VTT based on what is configured in `foundry-data-path-config.json`
*/
function getFoundryDataPath() {
const config = readJSONSync('foundry-data-path-config.json');
if (config?.dataPath) {
if (!existsSync(resolve(config.dataPath))) {
throw new Error('Supplied Foundry data path is invalid, directory not found');
}
return resolve(config.dataPath);
} else {
throw new Error('No Foundry data path defined in foundry-data-path-config.json');
}
}
/**
* Symlink build folder within Foundry VTT data folder
*/
async function createSymlink() {
let destinationDirectory;
if (existsSync(resolve(buildDirectory, 'module.json'))) {
destinationDirectory = 'modules';
} else {
throw new Error(`Could not find module.json in ${buildDirectory}`);
}
const symlinkDirectory = resolve(
getFoundryDataPath(),
'Data',
destinationDirectory,
moduleDirectory
);
if (argv.clean || argv.c) {
console.log(`[== Removing link: ${symlinkDirectory} ==]\n`);
await remove(symlinkDirectory);
} else if (!existsSync(symlinkDirectory)) {
console.log(`[== Linking ${buildDirectory} to ${symlinkDirectory} ==]\n`);
await ensureDir(resolve(symlinkDirectory, '..'));
await symlink(resolve(buildDirectory), symlinkDirectory);
}
}
createSymlink();