Files
Void-Homelab/lib/health/registry.js
2026-06-02 22:52:46 +10:00

31 lines
1.0 KiB
JavaScript

import { readFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const CONFIG = path.join(__dirname, '../../config/services.json');
export const CATEGORY_ORDER = ['agents', 'infrastructure', 'media', 'other'];
let cache = null;
export function load() {
if (!cache) cache = JSON.parse(readFileSync(CONFIG, 'utf8'));
return cache;
}
export function _reset() { cache = null; } // tests
export function iconSlug(svc) {
return (svc.icon || svc.name).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');
}
export function grouped(services) {
const map = new Map();
for (const s of services) {
const cat = CATEGORY_ORDER.includes(s.category) ? s.category : 'other';
if (!map.has(cat)) map.set(cat, []);
map.get(cat).push(s);
}
return [...CATEGORY_ORDER, ...[...map.keys()].filter(c => !CATEGORY_ORDER.includes(c))]
.filter(c => map.has(c))
.map(category => ({ category, services: map.get(category) }));
}