Improve optimize script

This commit is contained in:
Eric Fennis
2020-07-18 12:53:05 +02:00
parent ea8bec9320
commit 4365dddf57
3 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ export default function(fileName, outputDirectory, componentGetter, iconNodes) {
// Generate export for all the icons
//
// output: export const myIcon = getComponent(myIconVNode);
// (output): export const myIcon = getComponent(myIconVNode);
icons.forEach(iconName => {
const componentName = generateComponentName(iconName);
const constantString = `export const ${componentName} = ${componentGetter}(${componentName}VNode);\n`;
+11 -9
View File
@@ -1,16 +1,18 @@
import fs from 'fs';
import path from 'path';
const OUT_DIR = path.resolve(__dirname, '../dist/icons');
const ICONS_DIR = path.resolve(__dirname, '../icons');
console.log(`Optimizing SVGs in ${OUT_DIR}...`);
console.log(`Optimizing SVGs in ${ICONS_DIR}...`);
const svgFiles = fs.readdirSync(IN_DIR).filter(file => path.extname(file) === '.svg');
const svgFiles = fs.readdirSync(ICONS_DIR).filter(file => path.extname(file) === '.svg');
console.log(svgFiles);
// Object.keys(icons).forEach(name => {
// const svg = icons[name].toSvg();
// fs.writeFileSync(path.join(OUT_DIR, `${name}.svg`), svg);
// });
svgFiles
.filter(file => path.extname(file) === '.svg')
.forEach(svgFile => {
const svg = fs.readFileSync(path.join(ICONS_DIR, svgFile));
processSvg(svg).then(svg =>
fs.writeFileSync(path.join(ICONS_DIR, svgFile), svg),
);
});
+1 -1
View File
@@ -2,7 +2,7 @@ import Svgo from 'svgo';
import cheerio from 'cheerio';
import { format } from 'prettier';
import DEFAULT_ATTRS from '../src/default-attrs.json';
import DEFAULT_ATTRS from './default-attrs.json';
/**
* Process SVG string.