Skip to content

Commit 5efdc71

Browse files
committed
add file watcher to showcase
1 parent 17c3c26 commit 5efdc71

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

vuu-ui/package-lock.json

Lines changed: 47 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vuu-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"deploy:websocket-test": "node ./tools/deploy-websocket-test.mjs",
3838
"view-bundle": "node ./scripts/visualize-bundle.mjs",
3939
"type-defs": "node ./scripts/build-all-type-defs.mjs",
40-
"showcase": "cd showcase && tsx ../tools/vuu-showcase/scripts/showcase-vite-api.ts",
40+
"showcase": "cd showcase && tsx ../tools/vuu-showcase/scripts/showcase-dev.ts",
4141
"showcase:prod": "npm run build:worker && cd showcase && tsx ../tools/vuu-showcase/scripts/showcase-build.ts",
4242
"test:cypress": "npm run build:worker && cypress run --component --browser chrome --headless",
4343
"test:cypress:local": "cypress open --component --browser chrome",

vuu-ui/tools/vuu-showcase/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"@fontsource/open-sans": "^4.5.13",
3030
"@salt-ds/core": "1.43.0",
3131
"@salt-ds/theme": "1.28.0",
32-
"symlink-dir": "^6.0.5"
32+
"symlink-dir": "^6.0.5",
33+
"watcher": "2.3.1"
3334
},
3435
"peerDependencies": {
3536
"clsx": "^2.0.0",

vuu-ui/tools/vuu-showcase/scripts/showcase-vite-api.ts renamed to vuu-ui/tools/vuu-showcase/scripts/showcase-dev.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import mdx from "@mdx-js/rollup";
2-
import chalk from "chalk";
32
import fs from "fs";
43
import MagicString from "magic-string";
5-
import open from "open";
64
import { createFilter, createServer, type PluginOption } from "vite";
75
import INDEX_HTML from "./html-template";
86
import path from "path";
7+
import Watcher from "watcher";
98

109
import { createFolder, linkSourceDirectory, writeFile } from "./utils";
1110
import { treeSourceFromFileSystem } from "./treeSourceFromFileSystem";
@@ -18,6 +17,16 @@ const treeSourceJson = treeSourceFromFileSystem(pathToExhibits);
1817
const end = performance.now();
1918
console.log(`[showcase-vite-api] building tree took ${end - start}ms`);
2019

20+
const watcher = new Watcher(pathToExhibits, {
21+
recursive: true,
22+
ignoreInitial: true,
23+
});
24+
watcher.on("all", (event, targetPath /* targetPathNext*/) => {
25+
// This is what the library does internally when you pass it a handler directly
26+
console.log(`[watcher] ${event} ${targetPath}`); // => could be any target event: 'add', 'addDir', 'change', 'rename', 'renameDir', 'unlink' or 'unlinkDir'
27+
// console.log(targetPathNext); // => the file system path "targetPath" got renamed to, this is only provided on 'rename'/'renameDir' events
28+
});
29+
2130
const cwd = process.cwd();
2231
const __dirname = path.join(cwd, ".showcase/dev");
2332

@@ -109,3 +118,10 @@ server.bindCLIShortcuts({ print: true });
109118

110119
// console.log(`opening showcase at ${chalk.green("http://localhost:5173/")} ...`);
111120
// open("http://localhost:5173/");
121+
122+
process.on("SIGINT", async function () {
123+
console.log("[showcase-dev] shutting down");
124+
watcher.close();
125+
await server.close();
126+
process.exit();
127+
});

0 commit comments

Comments
 (0)