forked from osano/cookieconsent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (84 loc) · 2.91 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var minifyJS = require('gulp-uglify');
var minifyCSS = require('gulp-minify-css');
var deleteDirs = require('del');
var runSequence = require('run-sequence');
var autoprefixer = require('gulp-autoprefixer');
var bump = require('gulp-bump');
var yargs = require('yargs');
var diff = require('gulp-diff');
var browserSync = require('browser-sync').create();
var buildFolder = './build';
var jsBuildFiles = [
'./src/cookieconsent.js'
];
var cssBuildFiles = [
// defined explicitly so they are combined in order
'./src/styles/animation.css',
'./src/styles/base.css',
'./src/styles/layout.css',
'./src/styles/media.css',
'./src/styles/pukcookie.css',
// all theme files
'./src/styles/themes/*.css',
];
gulp.task('cleanup:begin', function () {
return deleteDirs([buildFolder]);
});
gulp.task('minify:js', function () {
return gulp.src(jsBuildFiles) // get files
.pipe(minifyJS()) // minify them
.pipe(concat('cookieconsent.min.js')) // combine them
.pipe(gulp.dest(buildFolder)); // save under a new name
});
gulp.task('minify:css', function () {
return gulp.src(cssBuildFiles) // get files
.pipe(autoprefixer({browsers: ['IE 10', 'last 2 versions']}))
.pipe(minifyCSS()) // minify them
.pipe(concat('cookieconsent.min.css')) // combine them
.pipe(gulp.dest(buildFolder)); // save under a new name
});
gulp.task('bump', function(callback) {
return gulp.src(['./bower.json', './package.json'])
.pipe(bump({'version': yargs.argv.tag}))
.pipe(gulp.dest('./'))
});
gulp.task('build', function(callback) {
return runSequence('cleanup:begin', 'minify:js', 'minify:css', callback);
});
gulp.task('verify', function(callback) {
buildFolder = "./build-verify";
return runSequence('cleanup:begin', 'minify:js', 'minify:css', 'verify:diff', callback);
});
gulp.task('verify:diff', function(callback) {
return gulp.src('./build/*')
.pipe(diff('./build-verify'))
.pipe(diff.reporter({ fail: true }));
});
gulp.task('build:release', function(callback) {
if (yargs.argv.tag===undefined) {
throw "A version number (e.g. 3.0.1) is required to build a release of cookieconsent"
}
return runSequence('build', 'bump', callback)
});
gulp.task('watch', function() {
gulp.watch(cssBuildFiles.concat(jsBuildFiles), ['build']);
});
gulp.task('serve', ['build'], function(){
gulp.watch(cssBuildFiles.concat(jsBuildFiles), ['build']);
browserSync.init({
open: true,
startPath: '/demo/index.html',
notify: false,
port: 9000,
server: {
baseDir: ['.']
}
});
gulp.watch([
buildFolder + '/cookieconsent.min.css',
buildFolder + '/cookieconsent.min.js'
]).on('change', browserSync.reload);
});