-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
115 lines (100 loc) · 3.26 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const gulp = require('gulp');
const del = require('del');
const sketchClean = require('gulp-clean-sketch');
const svgmin = require('gulp-svgmin');
const raster = require('gulp-raster');
const imagemin = require('gulp-imagemin');
const rename = require('gulp-rename');
const svgCss = require('gulp-svg-css');
const fileList = require('gulp-filelist');
const headerComment = require('gulp-header-comment');
// Clean & Minimise SVG
gulp.task('cleanSVG', function(cb){
return gulp.src('dist/svg/*.svg')
.pipe(sketchClean())
.pipe(svgmin({js2svg : {pretty : true}}))
.pipe(gulp.dest('dist/svg'))
cb(err);
});
// Create PNG
gulp.task('createPNG', ['cleanSVG'], function(cb) {
return gulp.src('dist/svg/*.svg')
.pipe(raster())
.pipe(rename({extname : '.png'}))
.pipe(gulp.dest('dist/png/@1x'))
cb(err);
});
// Create PNG Scaled for Retina
gulp.task('createRetinaPNG', ['createPNG'], function(cb){
return gulp.src('dist/svg/*.svg')
.pipe(raster({scale : 2}))
.pipe(rename({extname : '.png', suffix : '@2x'}))
.pipe(gulp.dest('dist/png/@2x'))
cb(err);
});
// Create JPG
gulp.task('createJPG', ['createRetinaPNG'], function(cb){
return gulp.src('dist/svg/*.svg')
.pipe(raster())
.pipe(rename({extname : '.jpg'}))
.pipe(gulp.dest('dist/jpg/@1x'))
cb(err);
});
// Create JPG Scaled for Retina
gulp.task('createRetinaJPG', ['createJPG'], function(cb){
return gulp.src('dist/svg/*.svg')
.pipe(raster({scale : 2}))
.pipe(rename({extname : '.jpg', suffix : '@2x'}))
.pipe(gulp.dest('dist/jpg/@2x'))
cb(err);
});
// Optimise PNGs Images
gulp.task('optimisePNG', ['createRetinaPNG'], function(){
return gulp.src('dist/png/**/*.png')
.pipe(imagemin([imagemin.optipng({optimizationLevel: 5})]))
.pipe(gulp.dest('dist/png'))
});
// Optimise JPG Images
gulp.task('optimiseJPG', ['createRetinaJPG'], function(){
return gulp.src('dist/jpg/**/*.jpg')
.pipe(imagemin([imagemin.jpegtran({progressive: true})]))
.pipe(gulp.dest('dist/jpg'))
});
// Generate Css
gulp.task('genCss', ['cleanSVG'], function(){
return gulp.src('dist/svg/*.svg')
.pipe(svgCss({
fileName : '16pxls'
}))
.pipe(gulp.dest('dist/css'))
});
// Create .JSON List of Icons
gulp.task('iconList', function(){
gulp.src('dist/svg/*.svg')
.pipe(fileList('iconList.json', {
flatten : true,
removeExtensions: true
}))
.pipe(gulp.dest('dist/docs/assets/json'))
});
gulp.task('licenseComment', function(){
gulp.src('dist/svg/*.svg')
.pipe(headerComment(`
<%= _.capitalize(pkg.name) %> (c) by <%= _.capitalize(pkg.author) %>
<%= _.capitalize(pkg.name) %> is licensed under a
Creative Commons Attribution-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-sa/4.0/>.
`))
.pipe(gulp.dest('dist/svg/'))
});
// Remove .DS_Store
gulp.task('clean', function(){
return del(['**/.DS_Store']);
});
// Clear Icons from Dist
gulp.task('cleanIcons', function(){
return del(['dist/png/**/*.png', 'dist/css/*.css', 'dist/jpg/**/*.jpg'])
});
// Process Icons Task
gulp.task('processIcons', ['cleanSVG', 'createPNG', 'createRetinaPNG', 'createJPG', 'createRetinaJPG', 'optimisePNG', 'optimiseJPG' , 'genCss']);