-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·366 lines (305 loc) · 11.9 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
// ===========================================================================================================
// Gulp config file for Timber Seed Wordpress Base theme
// Author: Ash Whiting
// Version: 0.2.6
// ===========================================================================================================
// ===========================================================================================================
// Global File paths
// ===========================================================================================================
var config = {
uploadPath: '../../uploads',
bowerPath: 'bower/',
bowerPathAll: 'bower/**/*',
jsPath: 'library/js/',
jsPathAll: 'library/js/*.js',
jsPathVendor: 'library/js/vendor-libs/',
temp: 'library/temp',
scssPath: 'library/scss',
scssPathAll: 'library/scss/**/*.scss',
imgPath: 'build/images',
destImg: 'build/images/**/*.{gif,png,jpg,jpeg,svg}',
dest: 'build',
destCss: 'build/css',
destJs: 'build/js',
modernizr: 'library/js/modernizr',
};
// ===========================================================================================================
// Add the JS files here (these are compiled out from the bower directory and placed in the vendor_libs folder)
// Alternatively, just refer to the bower folders directly if you like
// Uncomment the ones we have already added if you need to use them
// ===========================================================================================================
var jsFileList = [
config.bowerPath + 'respond/dest/respond.src.js',
config.bowerPath + 'respond/dest/respond.matchmedia.addListener.src.js',
config.bowerPath + 'bootstrap-sass/assets/javascripts/bootstrap.js',
config.bowerPath + 'matchHeight/dist/jquery.matchHeight.js',
config.bowerPath + 'parallax.js/parallax.js',
config.bowerPath + 'jquery-cycle2/build/jquery.cycle2.js',
config.bowerPath + 'jquery-cycle2/src/jquery.cycle2.swipe.js',
config.jsPathVendor + 'lightgallery/lightgallery.js',
config.jsPathVendor + 'lg-thumbnail/lg-thumbnail.js',
config.jsPathVendor + 'lg-video/lg-video.js',
config.jsPathVendor + 'lg-fullscreen/lg-fullscreen.js',
config.jsPath + '/scripts.js'
];
// Styles paths
var scssFilePaths = [
config.bowerPath + 'components-font-awesome/scss/',
config.bowerPath + 'lightgallery/dist/css/',
];
var bootstrapPath = [
config.bowerPath + 'bootstrap-sass/assets/stylesheets/'
]
// ===========================================================================================================
// Load some Gulp plugins
// ===========================================================================================================
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();
var gulp = require('gulp'); // Load the Gulp core
var runSequence = require('run-sequence'); // Load as this isn't gulp based
var buster = require('gulp-asset-hash'); // Load as this didn't work :P
var cssSelectorLimit = require('gulp-css-selector-limit');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');
var plumber = require('gulp-plumber');
var babel = require('gulp-babel');
var postcss = require('gulp-postcss');
var flexibility = require('postcss-flexibility');
// Load all the other plugins by referring to package.json
// ===========================================================================================================
// TASKS
//
// Sequencing became necessary because we only want to lint scripts.js (not every script!)
//
// If there is a better solution then fill your boots
// ===========================================================================================================
gulp.task('default', function() {
runSequence('bower', 'bower-files', 'modernizr', 'lint', 'scripts', 'styles', 'watch');
});
// ===========================================================================================================
// Bower tasks
//
// This gets all the Bower stuff in the correct place. Takes a little bit of jiggery pokery to sort out, but it's worth it as you will always
// be up to date with the script repos by running bower update
//
// Be sure to check your paths and dependencies here
// ===========================================================================================================
gulp.task('bower', function() {
return plugins.bower()
.pipe(gulp.dest(config.bowerPath))
});
// ===========================================================================================================
// Copy asset files from bower components in the /library folder
// ===========================================================================================================
gulp.task('bower-files', [
'bootstrap-scss',
'fontawesome',
'lightgallery-css',
'lightgallery-fonts',
'lightgallery-img',
'lightgallery-thumbnail',
'lightgallery-video',
'lightgallery-fullscreen',
'lightgallery'
]);
// ===========================================================================================================
// Move all the bits and bobs from the bower folder into the project
// You don't have to do this, and can refer directly to the bower folder if you want to
// ===========================================================================================================
// Bootstrap styles
gulp.task('bootstrap-scss', function () {
return gulp.src(config.bowerPath + 'bootstrap-sass/assets/fonts/**/**.*')
.pipe(gulp.dest(config.dest + '/fonts'))
});
// Copy fontawesome fonts in destination dir
gulp.task('fontawesome', function () {
return gulp.src(config.bowerPath + 'components-font-awesome/fonts/**/**.*')
.pipe(gulp.dest(config.destCss + '/fonts'))
});
// Copy lightgallery fonts in destination dir
gulp.task('lightgallery-fonts', function () {
return gulp.src(config.bowerPath + 'lightgallery/dist/fonts/**/**.*')
.pipe(gulp.dest(config.dest + '/fonts'))
});
// Copy lightgallery images in destination dir
gulp.task('lightgallery-img', function () {
return gulp.src(config.bowerPath + 'lightgallery/dist/img/**/**.*')
.pipe(gulp.dest(config.dest + '/images'))
});
gulp.task('lightgallery-css', function () {
return gulp.src(config.bowerPath + 'lightgallery/dist/css/lightgallery.css')
.pipe(gulp.dest(config.scssPath + '/lightgallery'))
});
// Copy lightgallery scripts to vendor dir
gulp.task('lightgallery', function() {
return gulp.src(config.bowerPath + 'lightgallery/dist/js/lightgallery.js')
.pipe(gulp.dest(config.jsPathVendor + '/lightgallery'))
});
gulp.task('lightgallery-video', function() {
return gulp.src(config.bowerPath + 'lg-video/dist/lg-video.js')
.pipe(gulp.dest(config.jsPathVendor + '/lg-video'))
});
gulp.task('lightgallery-fullscreen', function() {
return gulp.src(config.bowerPath + 'lg-fullscreen/dist/lg-fullscreen.js')
.pipe(gulp.dest(config.jsPathVendor + '/lg-fullscreen'))
});
gulp.task('lightgallery-thumbnail', function() {
return gulp.src(config.bowerPath + 'lg-thumbnail/dist/lg-thumbnail.js')
.pipe(gulp.dest(config.jsPathVendor + '/lg-thumbnail'))
});
// Errors
var onError = function (err) {
console.log(err.toString());
this.emit('end');
};
function reportError (error) {
notify().write({
title: 'Gulp: CSS',
message: 'Error'
});
console.log(error.toString());
}
// Styles task
// ===========================================================================================================
gulp.task('styles', function () {
return gulp
.src([config.scssPath + '/styles.scss']) // Base scss include
.pipe(sourcemaps.init())
.pipe(plugins.sass({
includePaths: scssFilePaths,
includePaths: bootstrapPath
}))
.pipe(postcss([flexibility]))
.pipe(plugins.autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(plugins.rename('styles.min.css'))
.pipe(plugins.cleanCss({compatibility: 'ie8'}))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(config.destCss))
.pipe(plumber({
errorHandler: reportError
}))
.on('error',console.log.bind(console))
.pipe(buster.hash({
manifest: './build/manifest.json',
template: '<%= name %>.<%= ext %>'
}))
});
// Scripts task
// ===========================================================================================================
gulp.task('scripts', function () {
return gulp
.src(jsFileList)
.pipe(sourcemaps.init())
.pipe(plumber({
errorHandler: reportError
}))
.pipe(plugins.concat({
path: config.destJs + '/scripts.js',
cwd: ''
}))
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(plugins.rename('scripts.min.js'))
.pipe(plugins.uglify())
.pipe(gulp.dest(config.destJs))
.pipe(buster.hash({
manifest: './build/manifest.json',
template: '<%= name %>.<%= ext %>'
}))
.on('error',console.log.bind(console))
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(config.destJs))
});
// Linting task
// ===========================================================================================================
gulp.task('lint', function(){
return gulp.src(config.jsPath + 'js/scripts.js')
.pipe(plumber({
errorHandler: reportError
}))
.pipe(plugins.jshint())
.pipe(plugins.plumber(function(error) {
errorHandler:reportError
}))
.pipe(plugins.jshint.reporter('default'))
});
// Modernizr task
// ===========================================================================================================
gulp.task('modernizr', function() {
return gulp.src(config.modernizr + "/modernizr.js")
.pipe(plugins.modernizr({
options: [
'setClasses',
'addTest',
'html5printshiv',
'testPropsAll',
'fnBind',
'domPrefixes'
]
}))
.pipe(plugins.uglify())
.pipe(plugins.rename('modernizr.min.js'))
.pipe(gulp.dest(config.destJs))
});
// Images task
// ===========================================================================================================
gulp.task('images', function () {
return gulp.src('build/images/**/*.{gif,png,jpg,jpeg,svg}')
.pipe(plugins.cache(plugins.imagemin({
optimizationLevel: 3,
progressive: false,
interlaced: false
})))
.pipe(gulp.dest(config.imgPath))
});
gulp.task('images-uploads', function () {
return gulp.src('../../uploads/**/*.{gif,png,jpg,jpeg,svg}')
.pipe(plugins.cache(plugins.imagemin({
optimizationLevel: 3,
progressive: false,
interlaced: false
})))
.pipe(gulp.dest(config.uploadPath))
});
// Watch task
// ===========================================================================================================
gulp.task('watch', function () {
gulp.watch(config.scssPathAll,function(){
runSequence('styles')
});
gulp.watch(config.destImg, ['images']);
gulp.watch(config.uploadPath, ['images-uploads']);
// Run the scripts task in the correct sequence
gulp.watch(config.jsPathAll, function() {
runSequence('lint','scripts');
});
});
// Selector limit check
// ===========================================================================================================
gulp.task('selector', function(){
return gulp.src('build/css/splitCSS/*.css')
.pipe(cssSelectorLimit())
.pipe(cssSelectorLimit.reporter('default'))
.pipe(cssSelectorLimit.reporter('fail'));
});
gulp.task('bless', function() {
gulp.src('build/css/styles.min.css')
.pipe(plugins.bless({
imports:false,
cacheBuster:false
}))
.pipe(gulp.dest('build/css'));
});
gulp.task('minify-bless', function(){
gulp.src('build/css/*.css')
.pipe(cleanCSS({debug: true}, function(details) {
console.log(details.name + ': ' + details.stats.originalSize);
console.log(details.name + ': ' + details.stats.minifiedSize);
}))
.pipe(buster.hash({
manifest: './build/manifest.json',
template: '<%= name %>.<%= ext %>'
}))
.pipe(gulp.dest('build/css/'));
});