From ee7231af9c72001e3ace02973169fc349f2fa13a Mon Sep 17 00:00:00 2001 From: david Date: Thu, 13 Apr 2023 17:10:26 +1000 Subject: [PATCH] Added more documentation --- src/fileWatch.ts | 24 ++++++++++++++++-------- src/index.ts | 3 +++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/fileWatch.ts b/src/fileWatch.ts index 1b65fd7..057aed0 100644 --- a/src/fileWatch.ts +++ b/src/fileWatch.ts @@ -6,6 +6,16 @@ import { resolve, relative, isAbsolute } from "path"; import type { Signal } from "signal-js"; import type { File } from "./interfaces.js"; +/** + * Returns true if a directory is a subdirectory of a parent directory (not necessarily strict). + * @param dir The directory to perform the check on. + * @param parent The parent directory. + */ +function isSubDirOf(dir: string, parent: string) { + const relPath = relative(resolve(parent), resolve(dir)); + return !!relPath && !relPath.startsWith('..') && !isAbsolute(relPath); +} + /** * Returns true if the given file should be watched. * @param file The provided file. @@ -19,19 +29,17 @@ function fileFilter(file: File) { } /** - * Returns true if a directory is a subdirectory of a parent directory (not necessarily strict). - * @param dir The directory to perform the check on. - * @param parent The parent directory. + * Type guard for {@code NodeJS.ErrnoException}. + * @param err */ -function isSubDirOf(dir: string, parent: string) { - const relPath = relative(resolve(parent), resolve(dir)); - return !!relPath && !relPath.startsWith('..') && !isAbsolute(relPath); -} - function isError(err: unknown): err is NodeJS.ErrnoException { return (err as NodeJS.ErrnoException).code !== undefined; } +/** + * Sets up the file watch. + * @param signaller The signal event emitter. + */ export async function setupWatch(signaller: Signal) { try { await mkdir(resolve(config.get("scriptsFolder"))); diff --git a/src/index.ts b/src/index.ts index 14f1a1b..196b988 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,9 @@ import { EventType } from "./eventTypes.js"; import { messageHandler } from "./networking/messageHandler.js"; import { FileEvent } from "./interfaces.js"; +/** + * Starts the file watcher. + */ export async function start() { loadConfig(); const watch = await setupWatch(signal);