From 183fc904ab99e195ec8d9f367f92e2117a516dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Kuna?= <1282324+codecalm@users.noreply.github.com> Date: Wed, 29 Jan 2025 21:44:38 +0100 Subject: [PATCH] Enhance icon sprite generation: add support for multiple sprite files and improve SVG handling (#1314) --- packages/icons-sprite/build.mjs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/icons-sprite/build.mjs b/packages/icons-sprite/build.mjs index 3ecc4093a..5d3450c6c 100644 --- a/packages/icons-sprite/build.mjs +++ b/packages/icons-sprite/build.mjs @@ -3,26 +3,36 @@ import { getAllIcons } from '../../.build/helpers.mjs' const icons = getAllIcons(true) +fs.mkdirSync('dist', { recursive: true }) + const buildSprite = () => { - let svgContent = '' + Object.entries(icons).forEach(([type, iconsInCategory]) => { + let svgContent = '' + console.log(`Building ${type} sprite...`) + iconsInCategory.forEach(icon => { + + console.log(`Adding ${icon.name}...`) const svgFileContent = icon.content .replace(/]+>/g, '') .replace(/<\/svg>/g, '') .replace(/\n+/g, '') .replace(/>\s+<') + .replace('', '') .trim() - svgContent += `${svgFileContent}` + svgContent += `${svgFileContent}` }) + + let svg = `${svgContent}` + + fs.writeFileSync(`dist/tabler-sprite${type == 'outline' ? '' : `-${type}`}.svg`, svg) + + if (type == 'outline') { + fs.writeFileSync(`dist/tabler-sprite-nostroke.svg`, svg.replace(/stroke-width="2"\s/g, '')) + } }) - - let svg = `${svgContent}` - - fs.mkdirSync('dist', { recursive: true }) - fs.writeFileSync('dist/tabler-sprite.svg', svg) - fs.writeFileSync('dist/tabler-sprite-nostroke.svg', svg.replace(/stroke-width="2"\s/g, '')) } buildSprite()