Create synchronized folder if necessary
This commit is contained in:
parent
9fbe101203
commit
d7d953c425
1 changed files with 14 additions and 0 deletions
|
@ -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,
|
||||||
|
|
Loading…
Add table
Reference in a new issue