mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-03-10 08:43:08 -07:00
* fix: apply automatic eslint fixes * lint: allow hashbang comment for tiddlywiki.js * lint: first back of manual lint fixes for unused vars * lint: added more fixes for unused vars * lint: missed files * lint: updated eslint config with selected rules from #9669
79 lines
2 KiB
JavaScript
Executable file
79 lines
2 KiB
JavaScript
Executable file
#!/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:
|
|
|
|
npm install svgo@2.3.0
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
var fs = require("fs"),
|
|
path = require("path"),
|
|
{ optimize } = require("svgo"),
|
|
config = {
|
|
plugins: [
|
|
"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();
|
|
|
|
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">>");
|
|
config.path = filepath;
|
|
var result = optimize(fakeSVG,config);
|
|
if(result) {
|
|
var newSVG = header.join("\n") + "\n\n" + result.data.replace("<<now "DD">>","<<now \"DD\">>");
|
|
fs.writeFileSync(filepath,newSVG);
|
|
} else {
|
|
console.log("Error " + err + " with " + filename);
|
|
process.exit();
|
|
};
|
|
}
|
|
});
|