diff options
author | codecalm <codecalm@gmail.com> | 2020-10-15 18:09:19 +0200 |
---|---|---|
committer | codecalm <codecalm@gmail.com> | 2020-10-15 18:09:19 +0200 |
commit | cc22ad9b1fc48aa10561eda05e7245205c4e9967 (patch) | |
tree | f97ccc690a4ce83d25a9f93d295e0917d96f7e44 /gulpfile.js | |
parent | icons tags (diff) | |
download | tabler-icons-cc22ad9b1fc48aa10561eda05e7245205c4e9967.tar.xz |
icons optimize
Diffstat (limited to 'gulpfile.js')
-rw-r--r-- | gulpfile.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/gulpfile.js b/gulpfile.js index 8f6da156..1817ff9d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ 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; @@ -406,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) { @@ -418,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(/<path d="([^"]+)"/g, function(f, r1) { + r1 = optimizePath(r1); + + return `<path d="${r1}"`; + }) .replace(/d="m/g, 'd="M') .replace(/([Aa])\s?([0-9.]+)\s([0-9.]+)\s([0-9.]+)\s?([0-1])\s?([0-1])\s?(-?[0-9.]+)\s?(-?[0-9.]+)/gi, '$1$2 $3 $4 $5 $6 $7 $8') .replace(/\n\n+/g, "\n") @@ -441,9 +458,6 @@ gulp.task('optimize', function (cb) { }) ; - // - // - if (svgFile.toString() !== svgFileContent) { fs.writeFileSync(file, svgFileContent); } @@ -652,15 +666,6 @@ gulp.task('update-icons-version', function (cb) { cb(); }); -// gulp.task('svg-path', function (cb) { -// let transformed = svgpath('m 9 5 a 2.4 2.4 0 0 1 2 -1 a 2.4 2.4 0 0 1 2 1 a 2.4 2.4 0 0 0 2 1 a 2.4 2.4 0 0 0 2 -1 a 2.4 2.4 0 0 1 2 -1 a 2.4 2.4 0 0 1 2 1') -// .rel() -// .toString(); -// -// console.log('transformed', transformed); -// cb(); -// }); - gulp.task('import-tags', function(cb) { fs.createReadStream('./_import.csv') .pipe(csv({ |