refactor: Convert the build scripts to TypeScript and group them (#2696)

- Closes: #2695
This commit is contained in:
Dermot Duffy
2026-08-21 14:18:37 -07:00
committed by GitHub
parent 1e03e6a3d9
commit 2d7c86c93c
16 changed files with 137 additions and 93 deletions
+27
View File
@@ -0,0 +1,27 @@
import { readFileSync } from 'node:fs';
import type { Plugin } from 'vite';
/**
* Importing an SVG yields `{ path, viewBox }` extracted at build time, the shape a
* Home Assistant custom iconset serves. The SVG must be a single-path icon.
*/
export const svgPath = (): Plugin => ({
name: 'svg-path',
// Run before Vite's builtin asset handling.
enforce: 'pre',
load(id) {
if (!id.endsWith('.svg')) {
return null;
}
const source = readFileSync(id, 'utf-8');
const path = / d="([^"]*)"/.exec(source)?.[1];
const viewBox = /viewBox="([^"]*)"/.exec(source)?.[1];
if (!path || !viewBox) {
throw new Error(`Imported SVG must have a path and viewBox: ${id}`);
}
return `export default ${JSON.stringify({ path, viewBox })};`;
},
});