forked from Turbo87/sidebar-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
83 lines (72 loc) · 2.12 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
var gulp = require('gulp');
var clean = require('gulp-clean');
var csslint = require('gulp-csslint');
var jshint = require('gulp-jshint');
var cleanCSS = require('gulp-clean-css');
var sass = require('gulp-sass');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var zip = require('gulp-zip');
var pkg = require('./package.json');
var basename = pkg.name + '-' + pkg.version;
// SASS compilation
gulp.task('sass', function() {
return gulp.src('scss/*sidebar.scss')
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest('css'));
});
// Lint JS + CSS
gulp.task('lint:js', function() {
return gulp.src('js/*sidebar.js')
.pipe(jshint())
.pipe(jshint.reporter());
});
gulp.task('lint:css', gulp.series('sass', function() {
return gulp.src('css/*sidebar.css')
.pipe(csslint({
'adjoining-classes': false,
'order-alphabetical': false,
'box-sizing': false,
'fallback-colors': false,
'important': false,
'regex-selectors': false,
}))
.pipe(csslint.formatter());
}));
gulp.task('lint', gulp.parallel('lint:js', 'lint:css'));
// Minify JS + CSS
gulp.task('minify:js', function() {
return gulp.src('js/*sidebar.js')
.pipe(rename({ suffix: '.min' }))
.pipe(uglify())
.pipe(gulp.dest('js'));
});
gulp.task('minify:css', gulp.series('sass', function() {
return gulp.src('css/*sidebar.css')
.pipe(rename({ suffix: '.min' }))
.pipe(cleanCSS({level: 2}))
.pipe(gulp.dest('css'));
}));
gulp.task('minify', gulp.parallel('minify:js', 'minify:css'));
// Package for distribution
gulp.task('zip', gulp.series('minify', function() {
return gulp.src([
'README.md',
'LICENSE',
'css/*-sidebar.min.css',
'js/*-sidebar.min.js',
])
.pipe(rename(function (path) {
path.dirname = '';
}))
.pipe(zip(basename + '.zip'))
.pipe(gulp.dest('dist'));
}));
// Watch JS + CSS Files
gulp.task('watch', gulp.series('lint', 'minify', function() {
gulp.watch('js/*.js', ['lint:js', 'minify:js']);
gulp.watch('scss/*.scss', ['lint:css', 'minify:css']);
}));
// Default
gulp.task('default', gulp.series('lint', 'minify'));