forked from morlay/svg-scaler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gruntfile.js
67 lines (46 loc) · 1.7 KB
/
Gruntfile.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
var gulp = require('vinyl-fs');
var rename = require('gulp-rename');
var svgscaler = require('./index');
module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-svg2png');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.config('clean.dest', {
src: ['./example/dest']
});
var sizes = ['16', '32', '64', '128', '256', '512'];
grunt.registerTask('svg2pngs', function () {
var done = this.async();
var svg2pngFiles = [];
var pngFiles = [];
var cnt = 0;
sizes.forEach(function (size) {
svg2pngFiles.push({
src: ['example/dest/svg/' + size + '/*.svg'],
dest: 'example/dest/png/' + size
});
gulp.src('example/src/*.svg')
.pipe(svgscaler({ width: size}))
.pipe(rename(function (path) {
pngFiles.push(size + '/' + path.basename + '.png');
}))
.pipe(gulp.dest('example/dest/svg/' + size))
.on('end', function () {
cnt++;
if (cnt === size.length) {
done();
grunt.config('svg2png.all', {
files: svg2pngFiles
});
grunt.task.run('svg2png');
imagePreview(pngFiles)
}
});
});
});
grunt.registerTask('default', ['clean:dest', 'svg2pngs']);
function imagePreview(pngFiles) {
grunt.file.write('example/dest/preview.html', pngFiles.map(function (fileName) {
return '<img src="png/' + fileName + '"/>';
}).join(''))
}
};