Added more documentation
This commit is contained in:
parent
fbab8a375f
commit
ee7231af9c
2 changed files with 19 additions and 8 deletions
|
@ -6,6 +6,16 @@ import { resolve, relative, isAbsolute } from "path";
|
||||||
import type { Signal } from "signal-js";
|
import type { Signal } from "signal-js";
|
||||||
import type { File } from "./interfaces.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.
|
* Returns true if the given file should be watched.
|
||||||
* @param file The provided file.
|
* @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).
|
* Type guard for {@code NodeJS.ErrnoException}.
|
||||||
* @param dir The directory to perform the check on.
|
* @param err
|
||||||
* @param parent The parent directory.
|
|
||||||
*/
|
*/
|
||||||
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 {
|
function isError(err: unknown): err is NodeJS.ErrnoException {
|
||||||
return (err as NodeJS.ErrnoException).code !== undefined;
|
return (err as NodeJS.ErrnoException).code !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets up the file watch.
|
||||||
|
* @param signaller The signal event emitter.
|
||||||
|
*/
|
||||||
export async function setupWatch(signaller: Signal) {
|
export async function setupWatch(signaller: Signal) {
|
||||||
try {
|
try {
|
||||||
await mkdir(resolve(config.get("scriptsFolder")));
|
await mkdir(resolve(config.get("scriptsFolder")));
|
||||||
|
|
|
@ -13,6 +13,9 @@ import { EventType } from "./eventTypes.js";
|
||||||
import { messageHandler } from "./networking/messageHandler.js";
|
import { messageHandler } from "./networking/messageHandler.js";
|
||||||
import { FileEvent } from "./interfaces.js";
|
import { FileEvent } from "./interfaces.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the file watcher.
|
||||||
|
*/
|
||||||
export async function start() {
|
export async function start() {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
const watch = await setupWatch(signal);
|
const watch = await setupWatch(signal);
|
||||||
|
|
Loading…
Add table
Reference in a new issue