forked from feimosi/baguetteBox.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
169 lines (147 loc) · 4.44 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
/* jshint node:true */
'use strict';
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
browserSync = require('browser-sync'),
jsonfile = require('jsonfile'),
runSequence = require('run-sequence');
var src = {
css: ['./src/*.scss', './src/*.css'],
js: './src/*.js'
},
build = {
css: './build/css/',
js: './build/js/',
html: './build/'
},
dist = {
css: './dist/',
js: './dist/'
};
var autoprefixerBrowsers = [
'last 2 version',
'> 1%',
'Edge >= 12',
'Explorer >= 8',
'Firefox 3.6',
'Firefox ESR',
'Opera 12.1'
];
// CSS tasks
gulp.task('css', function() {
return gulp.src(src.css)
// Compile Sass
.pipe(plugins.if(/.scss/, plugins.sass({ style: 'compressed', noCache: true }))) // jshint ignore:line
// parse CSS and add vendor-prefixed CSS properties
.pipe(plugins.autoprefixer(autoprefixerBrowsers))
// Concatenate all styles
.pipe(plugins.concat('baguetteBox.css'))
// Where to store the finalized CSS
.pipe(gulp.dest(build.css));
});
gulp.task('css-min', function() {
return gulp.src(src.css)
// Compile Sass
.pipe(plugins.if(/.scss/, plugins.sass({ style: 'compressed', noCache: true }))) // jshint ignore:line
// parse CSS and add vendor-prefixed CSS properties
.pipe(plugins.autoprefixer(autoprefixerBrowsers))
// Minify CSS
.pipe(plugins.cssmin())
// Concatenate all styles
.pipe(plugins.concat('baguetteBox.min.css'))
// Where to store the finalized CSS
.pipe(gulp.dest(dist.css));
});
// JS tasks
gulp.task('js', function () {
return gulp.src(src.js)
// Concatenate all JS files into one
.pipe(plugins.concat('baguetteBox.js'))
// Where to store the finalized JS
.pipe(gulp.dest(build.js));
});
gulp.task('js-min', function() {
return gulp.src(src.js)
// Concatenate all JS files into one
.pipe(plugins.concat('baguetteBox.min.js'))
// Minify JS
.pipe(plugins.uglify({ preserveComments: 'some' }))
// Where to store the finalized JS
.pipe(gulp.dest(dist.js));
});
gulp.task('lint', function() {
return gulp.src([src.js, 'gulpfile.js'])
// Run JSHint for syntax errors
.pipe(plugins.jshint())
.pipe(plugins.jshint.reporter('jshint-stylish'))
.pipe(plugins.jshint.reporter('fail'));
});
// Bump to a new version
gulp.task('bump-minor', function () {
return gulp.src(['./bower.json', './package.json'])
.pipe(plugins.bump({ type: 'minor' }))
.pipe(gulp.dest('./'));
});
// Bump to a new version
gulp.task('bump-patch', function () {
return gulp.src(['./bower.json', './package.json'])
.pipe(plugins.bump({ type: 'patch' }))
.pipe(gulp.dest('./'));
});
// Update version number in project files
gulp.task('update-version', function () {
return gulp.src([build.css + '*.css',
build.js + '*.js',
dist.css + '*.css',
dist.js + '*.js'
], {
base: './'
})
.pipe(plugins.injectVersion({
replace: '%%INJECT_VERSION%%',
prepend: {
toString: function() { return ''; }
}
}))
.pipe(gulp.dest('./'));
});
// Watch files for changes
gulp.task('watch', ['browser-sync'], function() {
// Watch Sass files
gulp.watch(src.css, ['css']);
// Watch JS files
gulp.watch(src.js, ['js', 'lint']);
});
// Live browser reload
gulp.task('browser-sync', ['js', 'css'], function () {
var files = [
build.html + '*.html',
build.css + '*.css',
build.js + '*.js'
];
browserSync.init(files, {
server: {
baseDir: './build/'
}
});
});
gulp.task('deploy', function() {
var packageJson = jsonfile.readFileSync('./package.json');
return gulp.src('./build/**/*')
.pipe(plugins.ghPages({
push: false,
message: 'v' + packageJson.version
}));
});
// Default task
gulp.task('default', ['watch']);
gulp.task('release', function() {
runSequence('bump-minor', 'build');
});
gulp.task('patch', function() {
runSequence('bump-patch', 'build');
});
gulp.task('build', function() {
runSequence(['css', 'js', 'css-min', 'js-min'], 'update-version');
});
gulp.task('test', ['build', 'lint']);