-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.ts
More file actions
48 lines (47 loc) · 1.57 KB
/
Copy pathscript.ts
File metadata and controls
48 lines (47 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { parseArgs } from "@std/cli";
import { parse, relative } from "@std/path";
import syncFlows from "./syncFlows.ts";
import syncSharedConfigs from "./syncSharedConfigs.ts";
import syncTriggers from "./syncTriggers.ts";
import syncResources from "./syncResources.ts";
import { debounceFileEvents } from "./helper.ts";
const args = parseArgs(Deno.args);
if (args.watch) {
console.log(`Watching ${args.watch} for changes...`);
const watcher = Deno.watchFs(args.watch);
try {
const debounceSync = debounceFileEvents(async (modifiedFiles) => {
modifiedFiles.sort((a, _) => a.endsWith("/_collection.json") ? -1 : 1);
for (const filePath of modifiedFiles) {
switch (relative(Deno.cwd(), filePath).split("/")[0]) {
case "flows":
await syncFlows(args, parse(filePath).name);
break;
case "resources":
await syncResources(args, filePath);
break;
case "sharedConfigs":
await syncSharedConfigs(args, parse(filePath).name);
break;
case "triggers":
await syncTriggers(args, parse(filePath).name);
break;
default:
console.log(
`Ignoring ${filePath} because it is not in a recognized resource collection`,
);
}
}
});
for await (const event of watcher) {
if (event.kind === "modify") debounceSync(event);
}
} finally {
watcher.close();
}
} else {
await syncFlows(args);
await syncSharedConfigs(args);
await syncTriggers(args);
await syncResources(args);
}