2015-05-07 17:27:53 +00:00
|
|
|
var gulp = require('gulp');
|
2015-05-21 14:45:41 +00:00
|
|
|
var gutil = require('gulp-util');
|
2015-05-07 17:27:53 +00:00
|
|
|
var rename = require('gulp-rename');
|
|
|
|
var svgstore = require('gulp-svgstore');
|
|
|
|
var svgmin = require('gulp-svgmin');
|
|
|
|
var cheerio = require('gulp-cheerio');
|
2015-05-21 14:45:41 +00:00
|
|
|
var through2 = require('through2');
|
|
|
|
|
2021-10-19 18:08:47 +00:00
|
|
|
var iconsource = 'icons/*.svg'
|
2015-05-07 17:27:53 +00:00
|
|
|
|
|
|
|
gulp.task('svgstore', function () {
|
|
|
|
return gulp
|
|
|
|
.src(iconsource)
|
|
|
|
.pipe(rename({prefix: 'icon-'}))
|
2017-08-28 21:30:35 +00:00
|
|
|
.pipe(svgmin({
|
|
|
|
js2svg: {
|
|
|
|
pretty: true
|
|
|
|
}
|
|
|
|
}))
|
2015-05-07 17:27:53 +00:00
|
|
|
.pipe(cheerio({
|
|
|
|
run: function ($) {
|
|
|
|
// remove green-screen color
|
2015-05-08 16:11:33 +00:00
|
|
|
$('[fill="#50E3C2"]').removeAttr('fill').parents('[fill="none"]').removeAttr('fill');
|
2016-03-03 10:39:22 +00:00
|
|
|
$('[fill="#BD0FE1"]').attr('fill', 'currentColor').parents('[fill="none"]').removeAttr('fill');
|
2019-06-04 03:40:48 +00:00
|
|
|
// color in Sketch changed slightly BD0FE1 -> BD10E0
|
|
|
|
$('[fill="#BD10E0"]').attr('fill', 'currentColor').parents('[fill="none"]').removeAttr('fill');
|
2015-05-07 17:27:53 +00:00
|
|
|
},
|
|
|
|
parserOptions: { xmlMode: true }
|
|
|
|
}))
|
|
|
|
.pipe(svgstore())
|
2015-05-21 14:45:41 +00:00
|
|
|
.pipe(through2.obj(function (file, encoding, cb) {
|
|
|
|
var $ = file.cheerio;
|
|
|
|
var data = $('svg > symbol').map(function () {
|
|
|
|
var viewBox = $(this).attr('viewBox').split(" ")
|
|
|
|
return [
|
|
|
|
'.'+ $(this).attr('id') + ' {' +
|
|
|
|
' width: ' + viewBox[2] + 'px;' +
|
|
|
|
' height: ' + viewBox[3] + 'px; ' +
|
|
|
|
'}'
|
|
|
|
];
|
|
|
|
}).get();
|
|
|
|
var cssFile = new gutil.File({
|
|
|
|
path: '../../../app/assets/stylesheets/svg-dimensions.css',
|
2015-05-26 08:10:29 +00:00
|
|
|
contents: new Buffer(data.join("\n"))
|
2015-05-21 14:45:41 +00:00
|
|
|
});
|
|
|
|
this.push(cssFile);
|
|
|
|
this.push(file);
|
|
|
|
cb();
|
|
|
|
}))
|
2021-10-19 18:08:47 +00:00
|
|
|
.pipe(gulp.dest('./'));
|
2015-05-07 17:27:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('watch', function () {
|
|
|
|
gulp.watch(iconsource, ['svgstore']);
|
|
|
|
});
|
|
|
|
|
2021-10-19 18:08:47 +00:00
|
|
|
gulp.task('default', ['svgstore', 'watch']);
|