-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
222 lines (199 loc) · 6.01 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
'use strict';
// Plugin definition
var del = require('del');
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();
// Other plugins with not a 'gulp-***' names
var imageminPngquant = require('imagemin-pngquant');
var runSequence = require('run-sequence');
// Kit name definition
var kitPrefix = 'sst-',
iconFontName = kitPrefix+'icons';
// Paths definition
var srcDir = './kit-src',
buildDir = './build',
pubDir = './www',
path = {
src: { // Sources
js: srcDir + '/js',
css: srcDir + '/css',
img: srcDir + '/img',
icons: srcDir + '/icons',
fonts: srcDir + '/fonts'
},
vendor: { // Vendor dependant sources
js: srcDir + '/js/vendor',
css: srcDir + '/css/vendor'
},
out: { // Output path
js: buildDir + '/js',
css: buildDir + '/css',
img: buildDir + '/images',
fonts: buildDir + '/fonts'
}
};
// Icon font glyphs will be saved here
var _glyphs = {};
//--------------------------------------------------------------
// TASKS
//--------------------------------------------------------------
// Compile Icon Font
gulp.task('compile:font', function(){
return gulp.src([
path.src.icons + '/*.svg'
])
.pipe(plugins.iconfont({
fontName: iconFontName,
fontWeight: 'normal',
fontStyle: 'normal',
//fixedWidth: '20',
fontHeight: '500',
round: 100,
descent: 75,
normalize: true,
centerHorizontally: true,
formats: ['ttf', 'eot', 'woff', 'woff2', 'svg']
}))
// Glyphs for Stylus iconfont CSS part creation
.on('glyphs', function(glyphs, options) {
// Modifying glyph names and codes to CSS format
glyphs.forEach(function(glyph) {
glyph.name = glyph.name.replace(/^[0-9\-]+/g, ""); // Replace digits from names
glyph.name = glyph.name.replace(/__/g, "-"); // Replace "__" with "-" in names
glyph.name = glyph.name.replace(/--/g, "-"); // Replace "--" with "-" in names
glyph.unicode = glyph.unicode[0].charCodeAt(0).toString(16).toUpperCase(); // Transform Unicode to ASCII code
});
_glyphs = glyphs;
})
.pipe(gulp.dest(path.out.fonts));
});
// Compile CSS
gulp.task('compile:css', function () {
// console.log(_glyphs);
return gulp.src(srcDir + '/toolkit.styl')
.pipe(plugins.stylus({
// Sending IconFont glyphs to Stylus
define: {
$fontName: iconFontName,
$fontPath: '../fonts/',
$iconClass : 'icon',
$glyphs: _glyphs
},
'include css': true,
'prefix' : kitPrefix // Toolkit prefix for all CSS classes
}))
.pipe(plugins.autoprefixer({
// Adds vendor CSS prefixes according to www.Caniuse.com
browsers: [
'> 1%',
'last 2 versions',
'firefox >= 4',
'safari 7',
'safari 8',
'IE 8',
'IE 9',
'IE 10',
'IE 11'
], cascade: false
}))
.pipe(plugins.rename({prefix: kitPrefix}))
.pipe(gulp.dest(path.out.css))
.pipe(plugins.livereload());
});
/*
// Now disabled as useless because of @imports in toolkit.styl
// Concatenate CSS
gulp.task('concat:css', function () {
return gulp.src(path.out.css + '/!*.css')
.pipe(plugins.concat('toolkit.css'))
.pipe(plugins.rename({prefix: kitPrefix}))
.pipe(gulp.dest(pubDir));
});
*/
// Minify CSS
gulp.task('minify:css', function () {
return gulp.src([
path.out.css + '/*.css',
'!' + path.out.css + '/*.min.css',
'!' + path.out.css + '/*-min.css'
])
.pipe(plugins.minifyCss())
.pipe(plugins.rename({suffix: '.min'}))
.pipe(gulp.dest(path.out.css));
});
// Compile JS
gulp.task('compile:js', function () {
return gulp.src([
path.src.js + '/*.js'
])
.pipe(plugins.concat('toolkit.js'))
.pipe(plugins.rename({prefix: kitPrefix}))
.pipe(gulp.dest(path.out.js))
.pipe(plugins.livereload());
});
// Minify JS
gulp.task('minify:js', function () {
return gulp.src([
path.out.js + '/*.js'
])
.pipe(plugins.uglify({
mangle: true
}))
.pipe(plugins.rename({suffix: '.min'}))
.pipe(gulp.dest(path.out.js));
});
// Minify pictures
gulp.task('minify:images', function () {
return gulp.src(path.src.img + '/**/*.{jpg,gif,png}')
.pipe(plugins.imagemin({
progressive: true,
use: [imageminPngquant({quality: '65-80', speed: 4})]
}))
.pipe(gulp.dest(path.out.img));
});
// Clean
gulp.task('clean', function () {
return del([ buildDir ]);
});
// Copy to WWW
gulp.task('copy', function(){
return gulp.src( buildDir + '/**/*' )
.pipe(gulp.dest( pubDir ));
//.pipe(plugins.notify("Copying to /www... <%= file.path %>"));
});
// Builder
gulp.task('build', function () {
// runSequence ïîçâîëÿåò çàïóñêàòü çàäà÷è ïî ïîðÿäêó
runSequence(
['clean'], // 1
['compile:font'], // 2
['compile:css', 'compile:js'], // 3
['minify:css', 'minify:js'], // 4
['copy'] // 5
);
});
// Watcher
gulp.task('default', ['compile:font'], function () {
// Notifies Livereload to reload browser if above tasks being runned
plugins.livereload.listen();
// CSS watcher
gulp.watch([
path.src.css + '/*.styl',
path.src.css + '/*.css'
], function () {
runSequence(
['compile:css'],
['minify:css'],
['copy']
);
});
// JS watcher
gulp.watch(path.src.js + '/*.js', function () {
runSequence(
['compile:js'],
//['minify:js'],
['copy']
);
});
});