From caec6bc3fea9155eb2b0aae64d577c565dd7b088 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Fri, 16 Apr 2021 09:20:39 +0100 Subject: [PATCH] Update SVG optimiser script --- bin/optimise-svgs.js | 84 +++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 41 deletions(-) diff --git a/bin/optimise-svgs.js b/bin/optimise-svgs.js index 28f4f715d..4920ab920 100755 --- a/bin/optimise-svgs.js +++ b/bin/optimise-svgs.js @@ -5,52 +5,52 @@ Optimise the SVGs in ./core/images using SVGO from https://github.com/svg/svgo Install SVGO with the following command in the root of the repo: -npm install svgo +npm install svgo@2.3.0 */ "use strict"; var fs = require("fs"), path = require("path"), - SVGO = require("svgo"), - svgo = new SVGO({ + { optimize } = require("svgo"), + config = { plugins: [ - {cleanupAttrs: true}, - {removeDoctype: true}, - {removeXMLProcInst: true}, - {removeComments: true}, - {removeMetadata: true}, - {removeTitle: true}, - {removeDesc: true}, - {removeUselessDefs: true}, - {removeEditorsNSData: true}, - {removeEmptyAttrs: true}, - {removeHiddenElems: true}, - {removeEmptyText: true}, - {removeEmptyContainers: true}, - {removeViewBox: false}, - {cleanupEnableBackground: true}, - {convertStyleToAttrs: true}, - {convertColors: true}, - {convertPathData: true}, - {convertTransform: true}, - {removeUnknownsAndDefaults: true}, - {removeNonInheritableGroupAttrs: true}, - {removeUselessStrokeAndFill: true}, - {removeUnusedNS: true}, - {cleanupIDs: true}, - {cleanupNumericValues: true}, - {moveElemsAttrsToGroup: true}, - {moveGroupAttrsToElems: true}, - {collapseGroups: true}, - {removeRasterImages: false}, - {mergePaths: true}, - {convertShapeToPath: true}, - {sortAttrs: true}, - {removeDimensions: false}, - {removeAttrs: {attrs: "(stroke|fill)"}} + 'cleanupAttrs', + 'removeDoctype', + 'removeXMLProcInst', + 'removeComments', + 'removeMetadata', + 'removeTitle', + 'removeDesc', + 'removeUselessDefs', + 'removeEditorsNSData', + 'removeEmptyAttrs', + 'removeHiddenElems', + 'removeEmptyText', + 'removeEmptyContainers', + // 'removeViewBox', + 'cleanupEnableBackground', + 'convertStyleToAttrs', + 'convertColors', + 'convertPathData', + 'convertTransform', + 'removeUnknownsAndDefaults', + 'removeNonInheritableGroupAttrs', + 'removeUselessStrokeAndFill', + 'removeUnusedNS', + 'cleanupIDs', + 'cleanupNumericValues', + 'moveElemsAttrsToGroup', + 'moveGroupAttrsToElems', + 'collapseGroups', + // 'removeRasterImages', + 'mergePaths', + 'convertShapeToPath', + 'sortAttrs', + //'removeDimensions', + {name: 'removeAttrs', params: { attrs: '(stroke|fill)' } } ] - }); + }; var basepath = "./core/images/", files = fs.readdirSync(basepath).sort(); @@ -66,12 +66,14 @@ files.forEach(function(filename) { fakeSVG = body.join("\n"); // A hack to make the new-journal-button work fakeSVG = fakeSVG.replace("<>","<<now "DD">>"); - svgo.optimize(fakeSVG, {path: filepath}).then(function(result) { + config.path = filepath; + var result = optimize(fakeSVG,config); + if(result) { var newSVG = header.join("\n") + "\n\n" + result.data.replace("<<now "DD">>","<>"); fs.writeFileSync(filepath,newSVG); - },function(err) { + } else { console.log("Error " + err + " with " + filename) process.exit(); - }); + }; } });