« get me outta code hell

basic actual stub for live-dev-server - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/write
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-01-08 11:49:44 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-01-08 11:49:44 -0400
commit154c050db72ebf06d4514326c696ab43fb3f8dc8 (patch)
tree96219177a6d692d0acba5cd9e5bbd7c3a25cb566 /src/write
parent47a4404b4a294e7e127b64f9f930236072b56194 (diff)
basic actual stub for live-dev-server
Diffstat (limited to 'src/write')
-rw-r--r--src/write/build-modes/live-dev-server.js43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/write/build-modes/live-dev-server.js b/src/write/build-modes/live-dev-server.js
index 76b6d47f..c3094712 100644
--- a/src/write/build-modes/live-dev-server.js
+++ b/src/write/build-modes/live-dev-server.js
@@ -1,4 +1,9 @@
-import {logInfo} from '../../util/cli.js';
+import * as pageSpecs from '../../page/index.js';
+
+import {
+  logInfo,
+  progressCallAll,
+} from '../../util/cli.js';
 
 export function getCLIOptions() {
   // Stub.
@@ -16,16 +21,40 @@ export async function go({
   _srcRootPath,
   _urls,
   _urlSpec,
-  _wikiData,
+  wikiData,
 
   _cachebust,
   _developersComment,
   _getSizeOfAdditionalFile,
 }) {
-  // Stub.
-  logInfo`So we are back in the mine!`;
-  logInfo`We are swinging our pickaxe in-`;
-  logInfo`...multiple directions,`;
-  logInfo`...multiple directions.`;
+  let targetSpecPairs = getPageSpecsWithTargets({wikiData});
+  const writes = progressCallAll(`Computing page data & paths for ${targetSpecPairs.length} targets.`,
+    targetSpecPairs.map(({
+      pageSpec,
+      target,
+      targetless,
+    }) => () =>
+      targetless
+        ? pageSpec.writeTargetless({wikiData})
+        : pageSpec.write(target, {wikiData}))).flat();
+
+  logInfo`Will be serving a total of ${writes.length} pages.`;
+
   return true;
 }
+
+function getPageSpecsWithTargets({
+  wikiData,
+}) {
+  return Object.values(pageSpecs)
+    .filter(pageSpec => pageSpec.condition?.({wikiData}) ?? true)
+    .flatMap(pageSpec => [
+      ...pageSpec.targets
+        ? pageSpec.targets({wikiData})
+            .map(target => ({pageSpec, target}))
+        : [],
+      Object.hasOwn(pageSpec, 'writeTargetless') &&
+        {pageSpec, targetless: true},
+    ])
+    .filter(Boolean);
+}