From d48ad82e37c776c08e2a1295083cf640e001edfa Mon Sep 17 00:00:00 2001 From: codecalm Date: Sat, 5 Dec 2020 17:26:57 +0100 Subject: [PATCH] icons optimize --- gulpfile.js | 59 ++++++++++++++++++++++++++---- src/_icons/arrow-big-down.svg | 2 +- src/_icons/arrow-big-left.svg | 2 +- src/_icons/arrow-big-right.svg | 2 +- src/_icons/arrow-big-top.svg | 2 +- src/_icons/arrows-double-ne-sw.svg | 8 ++-- src/_icons/arrows-double-nw-se.svg | 8 ++-- src/_icons/arrows-double-se-nw.svg | 8 ++-- src/_icons/arrows-double-sw-ne.svg | 8 ++-- src/_icons/bell-minus.svg | 6 +-- src/_icons/bell-plus.svg | 8 ++-- src/_icons/bell-x.svg | 6 +-- src/_icons/file-alert.svg | 4 +- src/_icons/file-analytics.svg | 6 +-- src/_icons/zoom-question.svg | 8 ++-- 15 files changed, 91 insertions(+), 46 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index da9f4aa06..d461eecd6 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -4,6 +4,7 @@ const gulp = require('gulp'), fs = require('fs'), path = require('path'), p = require('./package.json'), + csv = require('csv-parser'), zip = require('gulp-zip'), puppeteer = require('puppeteer'), outlineStroke = require('svg-outline-stroke'), @@ -12,6 +13,8 @@ const gulp = require('gulp'), sass = require('node-sass'), cleanCSS = require('clean-css'), argv = require('minimist')(process.argv.slice(2)), + svgParse = require('parse-svg-path'), + svgpath = require('svgpath'), svgr = require('@svgr/core').default; async function asyncForEach(array, callback) { @@ -404,6 +407,17 @@ gulp.task('optimize', function (cb) { return Math.round((parseFloat(n1) + parseFloat(n2)) * 1000) / 1000 }; + const optimizePath = function(path) { + let transformed = svgpath(path) + .rel() + .round(3) + .toString(); + + return svgParse(transformed).map(function(a){ + return a.join(' '); + }).join(' '); + }; + glob("src/_icons/*.svg", {}, function (er, files) { files.forEach(function (file, i) { @@ -416,6 +430,11 @@ gulp.task('optimize', function (cb) { .replace(/\s?\/>/g, ' />') .replace(/\n\s*<(line|circle|path|polyline|rect)/g, "\n <$1") .replace(/polyline points="([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s([0-9.]+)"/g, 'line x1="$1" y1="$2" x2="$3" y2="$4"') + .replace(//i, function(m){ return `version: ${version}\n${m}`; }); - + fs.writeFileSync(`src/_icons/${file}.svg`, svgFile); } else { console.log(`File ${file} already has version`); } - + } else { console.log(`File ${file} doesn't exists`); } @@ -636,7 +652,7 @@ gulp.task('update-icons-version', function (cb) { cp.exec(`git diff v${version} HEAD --name-status`, function (err, ret) { let newIcons = []; - + ret.replace(/[A]\s+src\/_icons\/([a-z0-9-]+)\.svg/g, function (m, fileName) { newIcons.push(fileName); }); @@ -650,6 +666,35 @@ gulp.task('update-icons-version', function (cb) { cb(); }); +gulp.task('import-tags', function(cb) { + fs.createReadStream('./_import.csv') + .pipe(csv({ + headers: false, + separator: "\t" + })) + .on('data', (row) => { + console.log(row[0], row[1]); + + const filename = `src/_icons/${row[0]}.svg`; + + let data = fs.readFileSync(filename).toString(); + data = data.replace(/(---[\s\S]+?---)/, function(m, headerContent){ + + headerContent = headerContent.replace(/tags: .*\n/, ''); + headerContent = headerContent.replace(/---/, `---\ntags: [${row[1]}]`); + + return headerContent; + }); + + fs.writeFileSync(filename, data); + + }) + .on('end', () => { + console.log('CSV file successfully processed'); + }); + cb(); +}); + gulp.task("build-react", function (cb) { cp.exec("npm run build-react", function () { cb(); diff --git a/src/_icons/arrow-big-down.svg b/src/_icons/arrow-big-down.svg index 90ff7ae2e..426b52058 100644 --- a/src/_icons/arrow-big-down.svg +++ b/src/_icons/arrow-big-down.svg @@ -2,5 +2,5 @@ category: Arrows --- - + diff --git a/src/_icons/arrow-big-left.svg b/src/_icons/arrow-big-left.svg index b2f8e3a17..abc3d7f61 100644 --- a/src/_icons/arrow-big-left.svg +++ b/src/_icons/arrow-big-left.svg @@ -2,5 +2,5 @@ category: Arrows --- - + diff --git a/src/_icons/arrow-big-right.svg b/src/_icons/arrow-big-right.svg index 572a6a239..1963b71ef 100644 --- a/src/_icons/arrow-big-right.svg +++ b/src/_icons/arrow-big-right.svg @@ -2,5 +2,5 @@ category: Arrows --- - + diff --git a/src/_icons/arrow-big-top.svg b/src/_icons/arrow-big-top.svg index 15dce3827..ec12b0b74 100644 --- a/src/_icons/arrow-big-top.svg +++ b/src/_icons/arrow-big-top.svg @@ -2,5 +2,5 @@ category: Arrows --- - + diff --git a/src/_icons/arrows-double-ne-sw.svg b/src/_icons/arrows-double-ne-sw.svg index 6e35356af..f6734e60a 100644 --- a/src/_icons/arrows-double-ne-sw.svg +++ b/src/_icons/arrows-double-ne-sw.svg @@ -2,8 +2,8 @@ category: Arrows --- - - - - + + + + diff --git a/src/_icons/arrows-double-nw-se.svg b/src/_icons/arrows-double-nw-se.svg index 0780c5840..a3dea4e8f 100644 --- a/src/_icons/arrows-double-nw-se.svg +++ b/src/_icons/arrows-double-nw-se.svg @@ -2,8 +2,8 @@ category: Arrows --- - - - - + + + + diff --git a/src/_icons/arrows-double-se-nw.svg b/src/_icons/arrows-double-se-nw.svg index 56cb2ba60..bde9f502c 100644 --- a/src/_icons/arrows-double-se-nw.svg +++ b/src/_icons/arrows-double-se-nw.svg @@ -2,8 +2,8 @@ category: Arrows --- - - - - + + + + diff --git a/src/_icons/arrows-double-sw-ne.svg b/src/_icons/arrows-double-sw-ne.svg index 366a568aa..85ea04ee0 100644 --- a/src/_icons/arrows-double-sw-ne.svg +++ b/src/_icons/arrows-double-sw-ne.svg @@ -2,8 +2,8 @@ category: Arrows --- - - - - + + + + diff --git a/src/_icons/bell-minus.svg b/src/_icons/bell-minus.svg index 9e296ebba..6e858cc5c 100644 --- a/src/_icons/bell-minus.svg +++ b/src/_icons/bell-minus.svg @@ -2,7 +2,7 @@ category: System --- - - - + + + diff --git a/src/_icons/bell-plus.svg b/src/_icons/bell-plus.svg index 87bd9cd8f..ff558eecd 100644 --- a/src/_icons/bell-plus.svg +++ b/src/_icons/bell-plus.svg @@ -2,8 +2,8 @@ category: System --- - - - - + + + + diff --git a/src/_icons/bell-x.svg b/src/_icons/bell-x.svg index 0f6254c00..8167ee4c1 100644 --- a/src/_icons/bell-x.svg +++ b/src/_icons/bell-x.svg @@ -2,7 +2,7 @@ category: System --- - - - + + + diff --git a/src/_icons/file-alert.svg b/src/_icons/file-alert.svg index 459b4bd90..786c46e8a 100644 --- a/src/_icons/file-alert.svg +++ b/src/_icons/file-alert.svg @@ -5,6 +5,6 @@ category: Document - - + + diff --git a/src/_icons/file-analytics.svg b/src/_icons/file-analytics.svg index d5397dde2..bfacad28b 100644 --- a/src/_icons/file-analytics.svg +++ b/src/_icons/file-analytics.svg @@ -5,7 +5,7 @@ category: Document - - - + + + diff --git a/src/_icons/zoom-question.svg b/src/_icons/zoom-question.svg index b3689fa4b..85c5a8813 100644 --- a/src/_icons/zoom-question.svg +++ b/src/_icons/zoom-question.svg @@ -2,8 +2,8 @@ category: Map --- - - - - + + + +