import fs from 'fs'
import path from 'path'
import { fileURLToPath } from 'url'
import { parseSync } from 'svgson'
const svgFiles = fs.readdirSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), './svg'))
.filter((file) => path.extname(file) === '.svg')
.map(svgFile => {
const name = path.basename(svgFile, '.svg'),
contents = fs.readFileSync(path.join(path.resolve(path.dirname(fileURLToPath(import.meta.url)), './svg'), svgFile), 'utf-8').trim().replace('', ''),
obj = parseSync(contents.replace('', ''));
return {
name,
contents,
obj
};
});
// Build sprites
(() => {
let svgContent = ''
svgFiles.forEach(function(file, i) {
const svgFileContent = file.contents.replace(/', '').replace(/(\r\n|\n|\r)/gm, '').replace(/(\s){2,}/g, '');
acc[name] = trimmedContent;
return acc;
}, {});
const iconContentsStringified = JSON.stringify(iconContents, null, 2);
fs.writeFileSync(`./src/tabler-contents.json`, iconContentsStringified);
})();