2019-11-22 12:21:03 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
/*
|
|
|
|
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:
|
|
|
|
|
2021-04-16 08:20:39 +00:00
|
|
|
npm install svgo@2.3.0
|
2019-11-22 12:21:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var fs = require("fs"),
|
|
|
|
path = require("path"),
|
2021-04-16 08:20:39 +00:00
|
|
|
{ optimize } = require("svgo"),
|
|
|
|
config = {
|
2019-11-22 12:21:03 +00:00
|
|
|
plugins: [
|
2021-04-16 08:20:39 +00:00
|
|
|
'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)' } }
|
2019-11-22 12:21:03 +00:00
|
|
|
]
|
2021-04-16 08:20:39 +00:00
|
|
|
};
|
2019-11-22 12:21:03 +00:00
|
|
|
|
|
|
|
var basepath = "./core/images/",
|
|
|
|
files = fs.readdirSync(basepath).sort();
|
|
|
|
|
|
|
|
files.forEach(function(filename) {
|
|
|
|
if(filename.slice(-4) === ".tid") {
|
|
|
|
var filepath = path.resolve(basepath,filename),
|
|
|
|
data = fs.readFileSync(filepath,"utf8"),
|
|
|
|
lines = data.split("\n"),
|
|
|
|
blankLine = lines.indexOf(""),
|
|
|
|
header = lines.slice(0,blankLine),
|
|
|
|
body = lines.slice(blankLine + 1),
|
|
|
|
fakeSVG = body.join("\n");
|
|
|
|
// A hack to make the new-journal-button work
|
|
|
|
fakeSVG = fakeSVG.replace("<<now \"DD\">>","<<now "DD">>");
|
2021-04-16 08:20:39 +00:00
|
|
|
config.path = filepath;
|
|
|
|
var result = optimize(fakeSVG,config);
|
|
|
|
if(result) {
|
2019-11-22 12:21:03 +00:00
|
|
|
var newSVG = header.join("\n") + "\n\n" + result.data.replace("<<now "DD">>","<<now \"DD\">>");
|
|
|
|
fs.writeFileSync(filepath,newSVG);
|
2021-04-16 08:20:39 +00:00
|
|
|
} else {
|
2019-11-22 12:21:03 +00:00
|
|
|
console.log("Error " + err + " with " + filename)
|
|
|
|
process.exit();
|
2021-04-16 08:20:39 +00:00
|
|
|
};
|
2019-11-22 12:21:03 +00:00
|
|
|
}
|
|
|
|
});
|