Files
lucide/packages/lucide-static/scripts/generateSprite.mts
Copilot 75b55160aa chore(dev): upgrade ESLint to latest compatible stack (v10) (#4378)
* chore: upgrade eslint to v9 latest with compatible lint deps

Agent-Logs-Url: https://github.com/lucide-icons/lucide/sessions/f7c1f1b5-d213-4afa-91a8-b799a16397ec

* Fix eslint config

* Fix a lot of eslint errors

* Fix eslint

* Fix eslint errors

* Fix eslint errors

* Fix types

* Fix eslint warning

* Format code

* Add eslint 10

* Remove unused vars

* Update pnpm

* Update deps

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
2026-08-18 13:09:22 +02:00

48 lines
1.2 KiB
TypeScript

import { type INode, stringify } from 'svgson';
import { format } from 'prettier';
import { appendFile } from '@lucide/helpers';
import { type SVGFile } from './readSvgs.mts';
export default async function generateSprite(
svgs: SVGFile[],
packageDir: string,
license: string
) {
const symbols = svgs.map<INode>(({ name, parsedSvg }) => ({
name: 'symbol',
type: 'element',
value: '',
attributes: {
id: name,
viewBox: parsedSvg.attributes.viewBox,
},
children: parsedSvg.children,
}));
const spriteSvgObject: INode = {
name: 'svg',
type: 'element',
attributes: {
xmlns: 'http://www.w3.org/2000/svg',
version: '1.1',
},
value: '',
children: [
{
name: 'defs',
type: 'element',
children: symbols,
value: '',
} as INode,
],
};
const spriteSvg = stringify(spriteSvgObject);
const prettifiedSprite = (await format(spriteSvg, { parser: 'babel' })).replace(/;/g, '');
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n<!-- ${license} -->\n`;
await appendFile(xmlMeta, `sprite.svg`, packageDir);
await appendFile(prettifiedSprite, `sprite.svg`, packageDir);
}