diff --git a/scripts/convert-svg-to-vue.mjs b/scripts/convert-svg-to-vue.mjs new file mode 100644 index 0000000..afdea76 --- /dev/null +++ b/scripts/convert-svg-to-vue.mjs @@ -0,0 +1,70 @@ +#!/usr/bin/env node +/** + * Usage: node convert-svg-to-svelte.js [inputDir] [outputDir] + * Defaults: svgs src/icons + */ +import fs from "fs"; +import path from "path"; + +const INPUT_DIR = process.argv[2] || "svgs"; +const OUTPUT_DIR = process.argv[3] || "src/icons"; + +if (!fs.existsSync(OUTPUT_DIR)) fs.mkdirSync(OUTPUT_DIR, { recursive: true }); + +function processSvg(svgContent) { + // Strip XML/DOCTYPE + let out = svgContent + .replace(/<\?xml[\s\S]*?\?>\s*/i, "") + .replace(/\s*/i, ""); + + // Remove ALL comments + out = out.replace(/\s*/g, ""); + + // Remove with any whitespace between tags + out = out.replace(/\s*<\/g>\s*/gi, ""); + + // Ensure only width="100%" height="100%" on the tag + out = out.replace(/]*>/i, match => { + let tag = match + .replace(/\s+(width|height)\s*=\s*"[^"]*"/gi, "") + .replace(/\s+(width|height)\s*=\s*'[^']*'/gi, ""); + return tag.replace(/>$/, ' width="100%" height="100%">'); + }); + + // Prepend the single license comment + out = + "\n" + + out.replace(/^\s+/, ""); + + // Wrap with