Create synchronized folder if necessary

This commit is contained in:
LJNeon 2022-10-01 15:54:33 -07:00
parent 9fbe101203
commit d7d953c425
No known key found for this signature in database
GPG key ID: 837C6B23D22030BE

View file

@ -1,6 +1,7 @@
import CheapWatch from "cheap-watch"; import CheapWatch from "cheap-watch";
import { config } from "./config"; import { config } from "./config";
import { EventType } from "./eventTypes"; import { EventType } from "./eventTypes";
import { mkdir } from "fs/promises";
import { resolve } from "path"; import { resolve } from "path";
import type { Signal } from "signal-js"; import type { Signal } from "signal-js";
import type { File } from "./interfaces"; import type { File } from "./interfaces";
@ -11,7 +12,20 @@ function fileFilter(file: File) {
return false; return false;
} }
function isError(err: unknown): err is NodeJS.ErrnoException {
return (err as NodeJS.ErrnoException).code !== undefined;
}
export async function setupWatch(signaller: Signal) { export async function setupWatch(signaller: Signal) {
try {
await mkdir(resolve(config.get("scriptsFolder")));
} catch (err) {
if (isError(err) && err.code !== "EEXIST") {
console.log(`Unable to create folder '${config.get("scriptsFolder")}', exiting...`);
process.exit();
}
}
const watch = new CheapWatch({ const watch = new CheapWatch({
dir: config.get("scriptsFolder"), dir: config.get("scriptsFolder"),
filter: fileFilter, filter: fileFilter,