Skip to content

Commit

Permalink
server: show path relative to cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
kkga committed Sep 29, 2022
1 parent c5e22e2 commit 12ae84a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ const sockets: Set<WebSocket> = 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)) {
Expand All @@ -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,
Expand Down

0 comments on commit 12ae84a

Please sign in to comment.