Files
lucide/packages/lucide-static/scripts/generateSprite.mts
Eric Fennis 3e644fda2d chore(scripts): Refactor scripts to typescript (#3316)
* Adjust typescript types

* adjust types

* fix types in all helper files

* Fix types

* Migrate js files to ts files

* Refactor to TS files

* Rename extentions

* Adjust imports

* Fix builds

* Update lockfile

* Fix last typescript migration

* Fix entry path @lucide/outline-svg

* Fix types

* add checkout step

* format files

* Format files
2025-06-18 15:47:24 +02:00

48 lines
1.2 KiB
TypeScript

/* eslint-disable import/no-extraneous-dependencies */
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,
},
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);
}