Skip to content

Instantly share code, notes, and snippets.

@jonyrock
Created September 23, 2017 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonyrock/6e9919841d112c0991ef69181c80857d to your computer and use it in GitHub Desktop.
Save jonyrock/6e9919841d112c0991ef69181c80857d to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
const IN_DIR = '/Users/alex/Downloads/meteocons-icons/SVG';
const OUT_DIR = '/Users/alex/Projects/grafana-plugins-exploring/grafana-ico-line-plugin/src/assets/weather-dark';
const topFiles = fs
.readdirSync(IN_DIR)
.filter(
f => fs.lstatSync(path.join(IN_DIR, f)).isFile()
);
function getStripped(text) {
text = text.replace(new RegExp(/\t/, 'g'), '');
text = text.replace(new RegExp(/\r?\n|\r/, 'g'), '');
return text;
}
var CUT_TEXT = '<g id="Grid_1_"><g id="Layer_1_1_"><g id="Grid"><g><rect fill="none" stroke="#A9CCDB" stroke-miterlimit="10" width="512" height="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="480" x2="512" y2="480"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="448" x2="512" y2="448"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="416" x2="512" y2="416"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="384" x2="512" y2="384"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="352" x2="512" y2="352"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="320" x2="512" y2="320"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="288" x2="512" y2="288"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="256" x2="512" y2="256"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="224" x2="512" y2="224"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="192" x2="512" y2="192"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="160" x2="512" y2="160"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="128" x2="512" y2="128"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="96" x2="512" y2="96"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="64" x2="512" y2="64"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="0" y1="32" x2="512" y2="32"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="480" y1="0" x2="480" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="448" y1="0" x2="448" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="416" y1="0" x2="416" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="384" y1="0" x2="384" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="352" y1="0" x2="352" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="320" y1="0" x2="320" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="288" y1="0" x2="288" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="256" y1="0" x2="256" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="224" y1="0" x2="224" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="192" y1="0" x2="192" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="160" y1="0" x2="160" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="128" y1="0" x2="128" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="96" y1="0" x2="96" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="64" y1="0" x2="64" y2="512"/><line fill="none" stroke="#A9CCDB" stroke-miterlimit="10" x1="32" y1="0" x2="32" y2="512"/></g></g></g></g>';
function processImage(fileName) {
var filePath = path.join(IN_DIR, fileName);
console.log(filePath);
var content = getStripped(fs.readFileSync(filePath).toString());
content = content.replace('<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->', '');
content = content.replace(CUT_TEXT, '');
content = content.replace('<g><g>', '');
content = content.replace('</g></g>', '');
content = content.replace('#1D1D1B', 'white');
fs.writeFileSync(path.join(OUT_DIR, fileName), content);
}
topFiles.forEach(processImage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment