From 12ae84a1b03ae73e2c85d7c750bc5c39eaee5d33 Mon Sep 17 00:00:00 2001 From: Gadzhi Kharkharov Date: Thu, 29 Sep 2022 21:52:25 +0300 Subject: [PATCH] server: show path relative to cwd --- serve.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/serve.ts b/serve.ts index 8a3f019..0df85fd 100644 --- a/serve.ts +++ b/serve.ts @@ -19,9 +19,16 @@ const sockets: Set = new Set(); let servePath: string; async function watch(opts: WatchOpts) { - const watcher = Deno.watchFs(opts.config.inputPath); + const paths = [opts.config.inputPath, join(Deno.cwd(), ".ter")]; + const watcher = Deno.watchFs(paths); let timer = 0; + const isInOutputDir = (path: string): boolean => + relative(opts.config.outputPath, path).startsWith(".."); + + // const isInConfigDir = (path: string): boolean => + // relative(join(Deno.cwd(), ".ter"), path).startsWith("..") === false; + eventLoop: for await (const event of watcher) { if (["any", "access"].includes(event.kind)) { @@ -30,15 +37,14 @@ async function watch(opts: WatchOpts) { for (const eventPath of event.paths) { if ( - eventPath.match(RE_HIDDEN_OR_UNDERSCORED) || - !relative(opts.config.outputPath, eventPath).startsWith("..") + eventPath.match(RE_HIDDEN_OR_UNDERSCORED) || !isInOutputDir(eventPath) ) { continue eventLoop; } } console.log( - `>>> ${event.kind}: ${relative(opts.config.inputPath, event.paths[0])}`, + `>>> ${event.kind}: ${relative(Deno.cwd(), event.paths[0])}`, ); await opts.runner({ config: opts.config,