librelad d39852aa3d refactor(webui): reorganize into components/ + core/ taxonomy
Final modularization layout (user-chosen): every page is a self-contained
folder under components/<id>/ (controllers + CSS + its html fragment), and all
shared/framework code folds into core/:
  core/kernel  (feature-registry, lifecycle, services, spa)
  core/boot    (auth, system-loader/orchestrator, setup, loaders)
  core/lib     (data-loader, router, helpers, the task kernel, shared modules)
  core/ui      (topbar, modal, notifications, … + topbar.html)
  core/css     (all shared stylesheets)
  core/icons
Top level is now just: components/, core/, themes/, index.html (+ runtime data/).

Every path reference rewritten (index.html, scripts arrays, fetch()/
loadFragment()/loadScript() literals, system-loader + config-manager controller
paths, kernel manifest URL, feature.json, backend FEATURES_DIR). The
/api/features/list endpoint NAME is unchanged (it now scans components/).
Deleted 3 dead files (app-content.html, apps-content.html, html-cache.js).
Verified: 0 stale prefixes, 0 double-rewrites, all JS/JSON valid.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-30 07:13:52 +01:00

59 lines
2.3 KiB
JavaScript

const express = require('express');
const fs = require('fs');
const path = require('path');
const router = express.Router();
const FEATURES_DIR = path.join(__dirname, '..', '..', 'frontend', 'components');
/* =========================
GET /api/features/list
Walks frontend/components/<id>/ and returns one entry per directory that
contains a feature.json — the WebUI's page manifest, discovered from the
folders themselves (exactly how /api/themes/list discovers themes). Drop a
features/<id>/ folder in and its page appears; delete it and the page is
gone — no central edit. The navigation kernel fetches this and falls back to
the checked-in features/manifest.dev.json if the API is unavailable.
Each feature.json declares: id, routes[], optional module (self-registering
index.js), optional handler (legacy fallback method), navId, nav{}, and order
(controls list + route-precedence ordering — e.g. apps before app-detail so
the '/apps*' wildcard wins over '/app*').
Public — the page list isn't sensitive and the kernel needs it before login
to render the right route (same rationale as the themes list).
========================= */
router.get('/list', (req, res) => {
const features = [];
try {
if (fs.existsSync(FEATURES_DIR)) {
for (const entry of fs.readdirSync(FEATURES_DIR, { withFileTypes: true })) {
if (!entry.isDirectory()) continue;
const metaPath = path.join(FEATURES_DIR, entry.name, 'feature.json');
if (!fs.existsSync(metaPath)) continue;
try {
const meta = JSON.parse(fs.readFileSync(metaPath, 'utf8'));
if (meta && meta.id && Array.isArray(meta.routes)) {
features.push(meta);
} else {
console.warn(`[features] ${entry.name}/feature.json missing id/routes — skipped`);
}
} catch (e) {
console.warn(`[features] ${entry.name}/feature.json is malformed — skipped:`, e.message);
}
}
}
} catch (err) {
console.error('Error scanning features directory:', err);
}
// Ascending `order` controls both nav order and route-registration order
// (the latter preserves wildcard precedence). Missing order sorts last.
features.sort((a, b) => ((a.order ?? 999) - (b.order ?? 999)));
res.json({ version: 1, source: 'scan', features });
});
module.exports = router;