isaacscript
Version:
A command line tool for managing Isaac mods written in TypeScript.
45 lines • 1.38 kB
JavaScript
import syncDirectory from "@zamiell/sync-directory";
import { assertDefined } from "complete-common";
import { getArgs } from "complete-node";
import { FILE_SYNCED_MESSAGE } from "../../../constants.js";
const SUBPROCESS_NAME = "directory syncer";
let modSourcePath;
let modTargetPath;
init();
function init() {
const args = getArgs();
const firstArg = args[0];
assertDefined(firstArg, `The ${SUBPROCESS_NAME} process did not get a valid first argument.`);
const secondArg = args[1];
assertDefined(secondArg, `The ${SUBPROCESS_NAME} process did not get a valid second argument.`);
modSourcePath = firstArg;
modTargetPath = secondArg;
syncDirectory(modSourcePath, modTargetPath, {
watch: true,
type: "copy",
afterEachSync,
onError,
chokidarWatchOptions: {
awaitWriteFinish: {
stabilityThreshold: 1000,
},
},
});
}
function afterEachSync(params) {
if (params === undefined) {
return;
}
if (params.eventType !== "init:copy") {
send(`${FILE_SYNCED_MESSAGE} ${params.relativePath}`);
}
}
function onError(err) {
send(`The directory syncer encountered an error: ${err.message}`);
}
function send(msg) {
if (process.send !== undefined) {
process.send(msg);
}
}
//# sourceMappingURL=modDirectorySyncer.js.map