-
Notifications
You must be signed in to change notification settings - Fork 129
/
gulpfile.js
137 lines (114 loc) · 3.78 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
// Load plugins
var gulp = require('gulp'),
gutil = require('gulp-util'),
watch = require('gulp-watch'),
prefix = require('gulp-autoprefixer'),
minifyCSS = require('gulp-minify-css'),
sass = require('gulp-sass'),
less = require('gulp-less'),
stylus = require('gulp-stylus'),
csslint = require('gulp-csslint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
shell = require('gulp-shell'),
rename = require('gulp-rename'),
size = require('gulp-size'),
browserSync = require('browser-sync'),
browserReload = browserSync.reload,
preProcessor = 'sass';
// Task to generate all source files with proper color table
gulp.task('generate', shell.task([
'node ./generate_color_table.js'
]));
// Task to minify all css files in the css directory
gulp.task('minify-css', function(){
gulp.src('./css/pesticide.css')
.pipe(minifyCSS())
.pipe(size({gzip: true, showFiles: true, title:'minified css'}))
.pipe(rename('pesticide.min.css'))
.pipe(gulp.dest('./css/'));
});
// Task to compile the bookmarklet version of Pesticide
gulp.task('minify-js', function() {
gulp.src('./js/pesticide.js')
.pipe(uglify())
.pipe(concat('pesticide.min.js'))
.pipe(gulp.dest('./js/'));
});
// Use csslint without box-sizing or compatible vendor prefixes (these
// don't seem to be kept up to date on what to yell about)
gulp.task('csslint', function(){
gulp.src('./css/*.css')
.pipe(csslint({
'compatible-vendor-prefixes': false,
'box-sizing': false,
'important': false,
'known-properties': false
}))
.pipe(csslint.reporter());
});
// Initialize browser-sync which starts a static server also allows for
// browsers to reload on filesave
gulp.task('browser-sync', function() {
browserSync.init(null, {
server: {
baseDir: "./"
}
});
});
// Function to call for reloading browsers
gulp.task('bs-reload', function () {
browserSync.reload();
});
// Task that compiles scss files down to good old css
gulp.task('sass', function(){
gulp.src('./sass/pesticide.scss')
.pipe(watch(function(files) {
return files.pipe(sass())
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'unminified css'}))
.pipe(size({gzip: true, showFiles: true, title:'unminified css'}))
.pipe(gulp.dest('./css/'))
}));
});
// Task that compiles less files down to good old css
gulp.task('less', function () {
gulp.src('./less/pesticide.less')
.pipe(watch(function(files) {
return files.pipe(less())
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'unminified css'}))
.pipe(size({gzip: true, showFiles: true, title:'unminified css'}))
.pipe(gulp.dest('./css/'))
}));
});
// Task that compiles stylus files down to good old css
gulp.task('stylus', function () {
gulp.src('./stylus/*.styl')
.pipe(watch(function(files) {
return files.pipe(stylus())
.pipe(prefix())
.pipe(size({gzip: false, showFiles: true, title:'unminified css'}))
.pipe(size({gzip: true, showFiles: true, title:'unminified css'}))
.pipe(gulp.dest('./css/'))
}));
});
/*
DEFAULT TASK
• Process sass and lints outputted css
• Outputted css is run through autoprefixer
• Runs jshint on all js files in ./js/
• Sends updates to any files in directory to browser for
automatic reloading
*/
gulp.task('default', function(){
var preProcessorExtensions = {
'sass': '.scss',
'less': '.less',
'stylus': '.stylus'
};
gulp.run(preProcessor, 'csslint');
gulp.watch(['*.html', './' + preProcessor + '/*' + preProcessorExtensions[preProcessor]], function(event) {
gulp.run(preProcessor, 'csslint', 'bs-reload');
});
});