Merge pull request #24 from LJNeon/create-folder
Create synchronized folder if necessary
This commit is contained in:
commit
7911d8584d
1 changed files with 14 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
import CheapWatch from "cheap-watch";
|
||||
import { config } from "./config";
|
||||
import { EventType } from "./eventTypes";
|
||||
import { mkdir } from "fs/promises";
|
||||
import { resolve } from "path";
|
||||
import type { Signal } from "signal-js";
|
||||
import type { File } from "./interfaces";
|
||||
|
@ -11,7 +12,20 @@ function fileFilter(file: File) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function isError(err: unknown): err is NodeJS.ErrnoException {
|
||||
return (err as NodeJS.ErrnoException).code !== undefined;
|
||||
}
|
||||
|
||||
export async function setupWatch(signaller: Signal) {
|
||||
try {
|
||||
await mkdir(resolve(config.get("scriptsFolder")));
|
||||
} catch (err) {
|
||||
if (isError(err) && err.code !== "EEXIST") {
|
||||
console.log(`Failed to watch folder '${config.get("scriptsFolder")}' (${err.code})`);
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
const watch = new CheapWatch({
|
||||
dir: config.get("scriptsFolder"),
|
||||
filter: fileFilter,
|
||||
|
|
Loading…
Add table
Reference in a new issue