Loheide-eu-mitarbeiterplatt.../scripts/generate-icons.mjs
Friederich Loheide 23c36d28b5
All checks were successful
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m33s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m41s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m18s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m9s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m0s
Menü: Symbole je Menüpunkt, gemeinsame Symbolauswahl
- Optionales Symbol für jeden Menü- und Unterpunkt (Kopfzeile,
  Aufklappmenüs, „Mehr“, Handy-Menü)
- Gemeinsame Liste resources/icons/icons.json (66 Lucide-Symbole) für
  Menü, Schnellzugriffe und Pagebuilder; `npm run icons` erzeugt
  Frontend-Zuordnung und SVGs für die Vorschau im Admin
- Admin-Auswahl mit Symbolvorschau und Suche

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 14:14:52 +00:00

62 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Erzeugt aus resources/icons/icons.json (kuratierte Lucide-Symbole):
* resources/js/lib/icons.js Zuordnung Name → Vue-Komponente fürs Portal
* resources/icons/svg.php SVG-Inhalte für den Admin-Bereich (Vorschau in Auswahlfeldern)
*
* Aufruf nach Änderungen an der Liste: npm run icons – die Ergebnisse werden mitcommittet,
* beim Kunden läuft kein Node.
*/
import { readFileSync, readdirSync, writeFileSync } from 'node:fs';
const dir = 'node_modules/@lucide/vue/dist/esm/icons';
const list = JSON.parse(readFileSync('resources/icons/icons.json', 'utf8'));
// Name bzw. Alias → Datei
const index = {};
for (const file of readdirSync(dir).filter((f) => f.endsWith('.mjs'))) {
const source = readFileSync(`${dir}/${file}`, 'utf8');
const name = source.match(/name: "([^"]+)"/)?.[1];
const aliases = [...(source.match(/aliases: \[([^\]]*)\]/)?.[1] ?? '').matchAll(/"([^"]+)"/g)].map((m) => m[1]);
for (const key of [name, ...aliases].filter(Boolean)) index[key] ??= file;
}
const imports = [];
const entries = [];
const svgs = [];
for (const name of Object.keys(list)) {
const file = index[name];
if (!file) throw new Error(`Symbol „${name}“ gibt es in @lucide/vue nicht.`);
const source = readFileSync(`${dir}/${file}`, 'utf8');
const component = source.match(/const (\w+) = createLucideIcon/)[1];
const { node } = (await import(`../${dir}/${file}`)).__iconData;
const inner = node.map(([tag, attrs]) => `<${tag} ${Object.entries(attrs).filter(([k]) => k !== 'key').map(([k, v]) => `${k}="${v}"`).join(' ')}/>`).join('');
if (!imports.includes(component)) imports.push(component);
entries.push(` '${name}': ${component},`);
svgs.push(` '${name}' => '${inner.replace(/'/g, "\\'")}',`);
}
writeFileSync('resources/js/lib/icons.js', `// Erzeugt von scripts/generate-icons.mjs aus resources/icons/icons.json – nicht von Hand ändern.
import {
${imports.sort().map((c) => ` ${c},`).join('\n')}
} from '@lucide/vue';
/** Kuratierte Symbole für Menü, Schnellzugriffe und Pagebuilder – passt zu App\\Support\\Icons. */
export const icons = {
${entries.join('\n')}
};
`);
writeFileSync('resources/icons/svg.php', `<?php
// Erzeugt von scripts/generate-icons.mjs aus resources/icons/icons.json – nicht von Hand ändern.
// Lucide (ISC-Lizenz), SVG-Inhalt ohne umschließendes <svg>.
return [
${svgs.join('\n')}
];
`);
console.log(`${entries.length} Symbole erzeugt.`);