From fc2fac9ca4ce38930187008fd87ad53f2c7f38b8 Mon Sep 17 00:00:00 2001 From: Christopher Sandvik <9214195+csandman@users.noreply.github.com> Date: Wed, 30 Dec 2020 14:23:46 -0500 Subject: [PATCH] Fix optimizeSvgs script (#160) --- package.json | 2 +- scripts/helpers.js | 2 +- scripts/optimizeSvgs.js | 2 +- scripts/render/processSvg.js | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 33ec80e..14c6cff 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "htmlparser2": "^4.1.0", "jest": "^26.4.2", "minimist": "^1.2.5", - "prettier": "^1.8.2", + "prettier": "1.17.1", "rollup": "^2.7.3", "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-license": "^2.0.0", diff --git a/scripts/helpers.js b/scripts/helpers.js index 71ac1ac..41a2006 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -82,7 +82,7 @@ export const readSvg = (fileName, directory) => fs.readFileSync(path.join(direct * @param {string} content */ export const writeSvgFile = (fileName, outputDirectory, content) => - fs.appendFileSync(path.join(outputDirectory, fileName), content, 'utf-8'); + fs.writeFileSync(path.join(outputDirectory, fileName), content, 'utf-8'); // This is a djb2 hashing function export const hash = (string, seed = 5381) => { diff --git a/scripts/optimizeSvgs.js b/scripts/optimizeSvgs.js index 9bc2c8e..43600a9 100644 --- a/scripts/optimizeSvgs.js +++ b/scripts/optimizeSvgs.js @@ -11,5 +11,5 @@ const svgFiles = readSvgDirectory(ICONS_DIR); svgFiles.forEach(svgFile => { const content = fs.readFileSync(path.join(ICONS_DIR, svgFile)); - processSvg(content).then(svg => writeSvgFile(svg, ICONS_DIR, content)); + processSvg(content).then(svg => writeSvgFile(svgFile, ICONS_DIR, svg)); }); diff --git a/scripts/render/processSvg.js b/scripts/render/processSvg.js index 521299e..1c38dfb 100644 --- a/scripts/render/processSvg.js +++ b/scripts/render/processSvg.js @@ -14,7 +14,7 @@ function processSvg(svg) { return ( optimize(svg) .then(setAttrs) - .then(format) + .then(optimizedSvg => format(optimizedSvg, { parser: 'babel' })) // remove semicolon inserted by prettier // because prettier thinks it's formatting JSX not HTML .then(svg => svg.replace(/;/g, '')) @@ -36,9 +36,7 @@ function optimize(svg) { ], }); - return new Promise(resolve => { - svgo.optimize(svg, ({ data }) => resolve(data)); - }); + return svgo.optimize(svg).then(({ data }) => data); } /**