@canopy-iiif/app 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/build/dev.js +85 -1
- package/lib/build/mdx.js +591 -4
- package/lib/build/pages.js +24 -1
- package/lib/search/search.js +13 -1
- package/package.json +1 -1
- package/ui/dist/server.mjs +1 -0
- package/ui/dist/server.mjs.map +2 -2
package/lib/build/dev.js
CHANGED
|
@@ -15,7 +15,9 @@ const {
|
|
|
15
15
|
ASSETS_DIR,
|
|
16
16
|
ensureDirSync,
|
|
17
17
|
} = require("../common");
|
|
18
|
-
|
|
18
|
+
const APP_COMPONENTS_DIR = path.join(process.cwd(), "app", "components");
|
|
19
|
+
|
|
20
|
+
function resolveTailwindCli() {
|
|
19
21
|
const bin = path.join(
|
|
20
22
|
process.cwd(),
|
|
21
23
|
"node_modules",
|
|
@@ -35,6 +37,11 @@ const UI_DIST_DIR = path.resolve(path.join(__dirname, "../../ui/dist"));
|
|
|
35
37
|
const APP_PACKAGE_ROOT = path.resolve(path.join(__dirname, "..", ".."));
|
|
36
38
|
const APP_LIB_DIR = path.join(APP_PACKAGE_ROOT, "lib");
|
|
37
39
|
const APP_UI_DIR = path.join(APP_PACKAGE_ROOT, "ui");
|
|
40
|
+
const CUSTOM_COMPONENT_EXTENSIONS = new Set(
|
|
41
|
+
[".js", ".jsx", ".ts", ".tsx", ".mjs", ".cjs", ".mts", ".cts"].map((
|
|
42
|
+
ext
|
|
43
|
+
) => ext.toLowerCase())
|
|
44
|
+
);
|
|
38
45
|
let loadUiTheme = null;
|
|
39
46
|
try {
|
|
40
47
|
const uiTheme = require(path.join(APP_UI_DIR, "theme.js"));
|
|
@@ -338,6 +345,74 @@ function watchAssetsPerDir() {
|
|
|
338
345
|
};
|
|
339
346
|
}
|
|
340
347
|
|
|
348
|
+
function handleCustomComponentChange(fullPath, eventType) {
|
|
349
|
+
if (!fullPath) return;
|
|
350
|
+
const ext = path.extname(fullPath).toLowerCase();
|
|
351
|
+
if (ext && !CUSTOM_COMPONENT_EXTENSIONS.has(ext)) return;
|
|
352
|
+
try {
|
|
353
|
+
console.log(`[components] ${eventType}: ${prettyPath(fullPath)}`);
|
|
354
|
+
} catch (_) {}
|
|
355
|
+
nextBuildSkipIiif = true;
|
|
356
|
+
try {
|
|
357
|
+
onBuildStart();
|
|
358
|
+
} catch (_) {}
|
|
359
|
+
debounceBuild();
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
function tryRecursiveWatchAppComponents(dir) {
|
|
363
|
+
try {
|
|
364
|
+
return fs.watch(dir, { recursive: true }, (eventType, filename) => {
|
|
365
|
+
if (!filename) return;
|
|
366
|
+
const full = path.join(dir, filename);
|
|
367
|
+
handleCustomComponentChange(full, eventType);
|
|
368
|
+
});
|
|
369
|
+
} catch (_) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function watchAppComponentsPerDir(dir) {
|
|
375
|
+
const watchers = new Map();
|
|
376
|
+
|
|
377
|
+
function watchDir(target) {
|
|
378
|
+
if (watchers.has(target)) return;
|
|
379
|
+
try {
|
|
380
|
+
const watcher = fs.watch(target, (eventType, filename) => {
|
|
381
|
+
const full = filename ? path.join(target, filename) : target;
|
|
382
|
+
handleCustomComponentChange(full, eventType);
|
|
383
|
+
scan(target);
|
|
384
|
+
});
|
|
385
|
+
watchers.set(target, watcher);
|
|
386
|
+
} catch (_) {}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function scan(target) {
|
|
390
|
+
let entries = [];
|
|
391
|
+
try {
|
|
392
|
+
entries = fs.readdirSync(target, { withFileTypes: true });
|
|
393
|
+
} catch (_) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
for (const entry of entries) {
|
|
397
|
+
if (!entry.isDirectory()) continue;
|
|
398
|
+
const next = path.join(target, entry.name);
|
|
399
|
+
watchDir(next);
|
|
400
|
+
scan(next);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
watchDir(dir);
|
|
405
|
+
scan(dir);
|
|
406
|
+
|
|
407
|
+
return () => {
|
|
408
|
+
for (const watcher of watchers.values()) {
|
|
409
|
+
try {
|
|
410
|
+
watcher.close();
|
|
411
|
+
} catch (_) {}
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
341
416
|
// Watch @canopy-iiif/app/ui dist output to enable live reload for UI edits during dev.
|
|
342
417
|
// When UI dist changes, rebuild the search runtime bundle and trigger a browser reload.
|
|
343
418
|
async function rebuildSearchBundle() {
|
|
@@ -1280,6 +1355,15 @@ async function dev() {
|
|
|
1280
1355
|
const urw = tryRecursiveWatchUiDist();
|
|
1281
1356
|
if (!urw) watchUiDistPerDir();
|
|
1282
1357
|
}
|
|
1358
|
+
if (fs.existsSync(APP_COMPONENTS_DIR)) {
|
|
1359
|
+
console.log(
|
|
1360
|
+
"[Watching]",
|
|
1361
|
+
prettyPath(APP_COMPONENTS_DIR),
|
|
1362
|
+
"(app components)"
|
|
1363
|
+
);
|
|
1364
|
+
const crw = tryRecursiveWatchAppComponents(APP_COMPONENTS_DIR);
|
|
1365
|
+
if (!crw) watchAppComponentsPerDir(APP_COMPONENTS_DIR);
|
|
1366
|
+
}
|
|
1283
1367
|
if (HAS_APP_WORKSPACE) {
|
|
1284
1368
|
watchAppSources();
|
|
1285
1369
|
}
|