Files
labtimesheet/src/main/frontend/build-icons.mjs
T

25 lines
1.3 KiB
JavaScript

import { mkdir, readFile, writeFile } from 'node:fs/promises';
import { dirname, resolve } from 'node:path';
const names = [
'bell', 'calendar-days', 'check-circle-2', 'chevron-left', 'chevron-right',
'circle-user-round', 'clock', 'folder-kanban', 'folder-open', 'inbox',
'layout-dashboard', 'list-check', 'log-out', 'monitor', 'moon', 'panel-left',
'settings', 'sun', 'triangle-alert', 'users', 'x'
];
const output = resolve('src/main/resources/static/assets/icons.svg');
const symbols = await Promise.all(names.map(async (name) => {
const svg = await readFile(resolve(`node_modules/lucide-static/icons/${name}.svg`), 'utf8');
const root = svg.match(/<svg\b([^>]*)>/)?.[1];
const viewBox = root?.match(/viewBox="([^"]+)"/)?.[1] ?? '0 0 24 24';
const presentation = ['fill', 'stroke', 'stroke-width', 'stroke-linecap', 'stroke-linejoin']
.map((attribute) => root?.match(new RegExp(`${attribute}="[^"]+"`))?.[0])
.join(' ');
const body = svg.match(/<svg[\s\S]*?>([\s\S]*?)<\/svg>/)?.[1];
if (!body) throw new Error(`Invalid Lucide SVG: ${name}`);
return `<symbol id="${name}" viewBox="${viewBox}" ${presentation}>${body.trim()}</symbol>`;
}));
await mkdir(dirname(output), { recursive: true });
await writeFile(output, `<svg xmlns="http://www.w3.org/2000/svg" style="display:none">${symbols.join('')}</svg>\n`);