forked from w0rm/gulp-svgstore
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
72 lines (52 loc) · 1.63 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var svgstore = require('./index');
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var connect = require('connect');
var serveStatic = require('serve-static');
var http = require('http');
var inject = require('gulp-inject');
gulp.task('svg', function () {
function transformSvg(svg, cb) {
// remove all fill="none" attributes
svg.find('[fill="none"]').removeAttr('fill');
cb(null);
}
return gulp
.src('test/src/*.svg')
.pipe(svgstore({
fileName: 'icons.svg', prefix: 'icon-', transformSvg: transformSvg
}))
.pipe(gulp.dest('test/dest'));
})
gulp.task('inline-svg', function () {
var svgs;
function transformSvg(svg, cb) {
svg.attr({style: 'display:none'});
// remove all fill="none" attributes
svg.find('[fill="none"]').removeAttr('fill');
cb(null);
}
function fileContents(filePath, file) {
return file.contents.toString('utf8');
}
svgs = gulp.src('test/src/*.svg')
.pipe(svgstore({
prefix: 'icon-', inlineSvg: true, transformSvg: transformSvg
}));
return gulp
.src('test/src/inline-svg.html')
.pipe(inject(svgs, {transform: fileContents}))
.pipe(gulp.dest('test/dest'));
})
gulp.task('test', ['svg', 'inline-svg'], function () {
var app = connect().use(serveStatic('test'));
var server = http.createServer(app);
server.listen(process.env.PORT || 8888);
function serverClose() {
server.close()
}
return gulp
.src('test.js', {read: false})
.pipe(mocha())
.on('end', serverClose);
})