Files
lucide/packages/lucide-static/scripts/generateSprite.mjs
Eric Fennis 50630b3aaf ci: Improve build speeds (#2778)
* Revert sync to async functions

* Replace more sync fs functions

* Format files

* Fix build svelte package
2025-02-10 14:13:52 +01:00

40 lines
1.0 KiB
JavaScript

/* eslint-disable import/no-extraneous-dependencies */
import { stringify } from 'svgson';
import { format } from 'prettier';
import { appendFile } from '@lucide/helpers';
export default async function generateSprite(svgs, packageDir, license) {
const symbols = svgs.map(({ name, parsedSvg }) => ({
name: 'symbol',
type: 'element',
attributes: {
id: name,
},
children: parsedSvg.children,
}));
const spriteSvgObject = {
name: 'svg',
type: 'element',
attributes: {
xmlns: 'http://www.w3.org/2000/svg',
version: '1.1',
},
children: [
{
name: 'defs',
type: 'element',
children: symbols,
},
],
};
const spriteSvg = stringify(spriteSvgObject);
const prettifiedSprite = 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);
}