« get me outta code hell

web-routes, client: import shims, more adaptive web routes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/web-routes.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-13 14:01:54 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:53 -0300
commit3b9f95a125d28b8cda3ebca1fe248e2026d2e56d (patch)
tree0affe1b32b05103ab0b7a572908bd6d041512415 /src/web-routes.js
parent6863f9ec64af7f9cf079150f3a798d7fe75b9045 (diff)
web-routes, client: import shims, more adaptive web routes
Diffstat (limited to 'src/web-routes.js')
-rw-r--r--src/web-routes.js46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/web-routes.js b/src/web-routes.js
index 2ebd6f3e..8bb2fba3 100644
--- a/src/web-routes.js
+++ b/src/web-routes.js
@@ -8,10 +8,10 @@ const codeSrcPath = __dirname;
 const codeRootPath = path.resolve(codeSrcPath, '..');
 
 function getNodeDependencyRootPath(dependencyName) {
-  const packageJSON =
-    import.meta.resolve(dependencyName + '/package.json');
-
-  return path.dirname(fileURLToPath(packageJSON));
+  return (
+    path.dirname(
+      fileURLToPath(
+        import.meta.resolve(dependencyName))));
 }
 
 export const stationaryCodeRoutes = [
@@ -36,23 +36,33 @@ export const stationaryCodeRoutes = [
   },
 ];
 
-export const dependencyRoutes = [
-  {
-    from:
-      path.join(
-        getNodeDependencyRootPath('flexsearch'),
-        'dist'),
+function quickNodeDependency({
+  name,
+  path: subpath = '',
+}) {
+  const root = getNodeDependencyRootPath(name);
 
-    to: ['staticLib.path', 'flexsearch'],
-  },
+  return [
+    {
+      from:
+        (subpath
+          ? path.join(root, subpath)
+          : root),
 
-  {
-    from:
-      getNodeDependencyRootPath('chroma-js'),
+      to: ['staticLib.path', name],
+    },
+  ];
+}
 
-    to: ['staticLib.path', 'chroma-js'],
-  }
-];
+export const dependencyRoutes = [
+  quickNodeDependency({
+    name: 'chroma-js',
+  }),
+
+  quickNodeDependency({
+    name: 'flexsearch',
+  }),
+].flat();
 
 export const allStaticWebRoutes = [
   ...stationaryCodeRoutes,