70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
import { spawn } from "node:child_process";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const projectRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const options = new Set(process.argv.slice(2));
|
|
const knownOptions = new Set(["--refresh", "--fetch", "--force", "--build", "--audit-only"]);
|
|
for (const option of options) {
|
|
if (!knownOptions.has(option)) throw new Error("Unknown option: " + option);
|
|
}
|
|
|
|
const npmCli = process.env.npm_execpath;
|
|
if (!npmCli) throw new Error("Run this batch through npm run dungeon:wow:all.");
|
|
|
|
function runNpm(script, argumentsList = []) {
|
|
return new Promise((resolve, reject) => {
|
|
console.log(
|
|
"\n==> npm run " + script
|
|
+ (argumentsList.length ? " -- " + argumentsList.join(" ") : ""),
|
|
);
|
|
const child = spawn(
|
|
process.execPath,
|
|
[npmCli, "run", script, ...(argumentsList.length ? ["--", ...argumentsList] : [])],
|
|
{
|
|
cwd: projectRoot,
|
|
env: process.env,
|
|
stdio: "inherit",
|
|
},
|
|
);
|
|
child.on("error", reject);
|
|
child.on("exit", (code, signal) => {
|
|
if (code === 0) resolve();
|
|
else {
|
|
reject(new Error(
|
|
script + " failed"
|
|
+ (signal ? " with signal " + signal : " with exit code " + code)
|
|
+ ".",
|
|
));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
if (options.has("--audit-only")) {
|
|
await runNpm("dungeon:wow:audit");
|
|
await runNpm("dungeon:wow:test");
|
|
return;
|
|
}
|
|
|
|
const refresh = options.has("--refresh") || options.has("--fetch") || options.has("--force");
|
|
if (refresh) {
|
|
const fetchArguments = options.has("--fetch") ? ["--fetch"] : [];
|
|
await runNpm("dungeon:source:azerothcore", fetchArguments);
|
|
await runNpm("dungeon:epoch:scripts", fetchArguments);
|
|
await runNpm(
|
|
"dungeon:five-player:import:remaining",
|
|
options.has("--force") ? ["--force"] : [],
|
|
);
|
|
}
|
|
|
|
await runNpm("dungeon:catalog");
|
|
await runNpm("dungeon:five-player:verify");
|
|
await runNpm("dungeon:wow:audit");
|
|
await runNpm("dungeon:wow:test");
|
|
if (options.has("--build")) await runNpm("build");
|
|
}
|
|
|
|
await main(); |