« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/upd8.js20
-rw-r--r--src/url-spec.js10
-rw-r--r--src/web-routes.js8
-rw-r--r--src/write/build-modes/live-dev-server.js4
-rw-r--r--src/write/build-modes/static-build.js12
5 files changed, 34 insertions, 20 deletions
diff --git a/src/upd8.js b/src/upd8.js
index a1ef2924..4b5064a6 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -40,7 +40,7 @@ import {fileURLToPath} from 'node:url';
 
 import wrap from 'word-wrap';
 
-import {showAggregate} from '#aggregate';
+import {mapAggregate, showAggregate} from '#aggregate';
 import CacheableObject from '#cacheable-object';
 import {displayCompositeCacheAnalysis} from '#composite';
 import {bindFind, getAllFindSpecs} from '#find';
@@ -1788,13 +1788,27 @@ async function main() {
       timeStart: Date.now(),
     });
 
+    const fromRoot = urls.from('shared.root');
+
     try {
-      webRoutes = await identifyAllWebRoutes({
+      const webRouteSources = await identifyAllWebRoutes({
         mediaCachePath,
         mediaPath,
       });
+
+      const {aggregate, result} =
+        mapAggregate(
+          webRouteSources,
+          ({to, ...rest}) => ({
+            ...rest,
+            to: fromRoot.to(...to),
+          }),
+          {message: `Errors computing effective web route paths`},);
+
+      aggregate.close();
+      webRoutes = result;
     } catch (error) {
-      console.error(error);
+      niceShowAggregate(error);
 
       logError`There was an issue identifying web routes!`;
       fileIssue();
diff --git a/src/url-spec.js b/src/url-spec.js
index 8537dfe0..2dd63509 100644
--- a/src/url-spec.js
+++ b/src/url-spec.js
@@ -99,6 +99,16 @@ const urlSpec = {
     prefix: 'thumb/',
     paths: genericPaths,
   },
+
+  static: {
+    prefix: 'static/',
+    paths: genericPaths,
+  },
+
+  util: {
+    prefix: 'util/',
+    paths: genericPaths,
+  },
 };
 
 // This gets automatically switched in place when working from a baseDirectory,
diff --git a/src/web-routes.js b/src/web-routes.js
index 1d010b66..ab9633b8 100644
--- a/src/web-routes.js
+++ b/src/web-routes.js
@@ -17,12 +17,12 @@ function getNodeDependencyRootPath(dependencyName) {
 export const stationaryCodeRoutes = [
   {
     from: path.join(codeSrcPath, 'static'),
-    to: '/static',
+    to: ['static.root'],
   },
 
   {
     from: path.join(codeSrcPath, 'util'),
-    to: '/util',
+    to: ['util.root'],
   },
 ];
 
@@ -39,8 +39,8 @@ export async function identifyDynamicWebRoutes({
 }) {
   const routeFunctions = [
     () => Promise.resolve([
-      {from: path.resolve(mediaPath), to: '/media'},
-      {from: path.resolve(mediaCachePath), to: '/thumb'},
+      {from: path.resolve(mediaPath), to: ['media.root']},
+      {from: path.resolve(mediaCachePath), to: ['thumb.root']},
     ]),
   ];
 
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index 464e689d..91ed4ee3 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -225,10 +225,10 @@ export async function go({
 
     const matchedWebRoute =
       webRoutes
-        .find(({to}) => pathname.startsWith(to));
+        .find(({to}) => pathname.startsWith('/' + to));
 
     if (matchedWebRoute) {
-      const localFilePath = pathname.slice(matchedWebRoute.to.length);
+      const localFilePath = pathname.slice(1 + matchedWebRoute.to.length);
 
       // Not security tested, man, this is a dev server!!
       const safePath =
diff --git a/src/write/build-modes/static-build.js b/src/write/build-modes/static-build.js
index a70da3e7..68cf0949 100644
--- a/src/write/build-modes/static-build.js
+++ b/src/write/build-modes/static-build.js
@@ -438,17 +438,7 @@ function writeWebRouteSymlinks({
 }) {
   const promises =
     webRoutes.map(async route => {
-      // TODO: Make web routes specify `to` via url spec
-      /*
-      const pathname = urls.from('shared.root').toDevice(urlKey);
-      const file = path.join(outputPath, pathname);
-      */
-
-      const parts =
-        route.to
-          .replace(/^\//, '')
-          .split('/');
-
+      const parts = route.to.split('/');
       const parentDirectoryParts = parts.slice(0, -1);
       const symlinkNamePart = parts.at(-1);