chore: replace gulp by a pure rollup based build

This commit is contained in:
Johannes Loher 2021-11-30 17:30:25 +01:00
parent 294fbefd0a
commit 0d6b89a3ed
16 changed files with 1772 additions and 2573 deletions

55
tools/link-package.js Normal file
View file

@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
import fs from "fs-extra";
import path from "node:path";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { destinationDirectory, distDirectory, foundryconfigFile, name, sourceDirectory } from "./const.js";
/**
* Get the data path of Foundry VTT based on what is configured in the {@link foundryconfigFile}.
*/
function getDataPath() {
const config = fs.readJSONSync(foundryconfigFile);
if (config?.dataPath) {
if (!fs.existsSync(path.resolve(config.dataPath))) {
throw new Error("User data path invalid, no Data directory found");
}
return path.resolve(config.dataPath);
} else {
throw new Error(`No user data path defined in ${foundryconfigFile}`);
}
}
/**
* Link the built package to the user data folder.
* @param {boolean} clean Whether to remove the link instead of creating it
*/
async function linkPackage(clean) {
if (!fs.existsSync(path.resolve(sourceDirectory, "system.json"))) {
throw new Error("Could not find system.json");
}
const linkDirectory = path.resolve(getDataPath(), destinationDirectory, name);
if (clean) {
console.log(`Removing link to built package at ${linkDirectory}.`);
await fs.remove(linkDirectory);
} else if (!fs.existsSync(linkDirectory)) {
console.log(`Linking built package to ${linkDirectory}.`);
await fs.ensureDir(path.resolve(linkDirectory, ".."));
await fs.symlink(path.resolve(".", distDirectory), linkDirectory);
}
}
const argv = yargs(hideBin(process.argv)).usage("Usage: $0").option("clean", {
alias: "c",
type: "boolean",
default: false,
description: "Remove the link instead of creating it",
}).argv;
const clean = argv.c;
await linkPackage(clean);