This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
gulpfile.js
181 lines (146 loc) · 4.31 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
// Ah, Big Gulp's eh? Welp, see ya later.
var gulp = require('gulp'),
gutil = require('gulp-util'),
c = require('chalk'),
clean = require('gulp-clean'),
imagemin = require('gulp-imagemin'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
map = require('map-stream'),
notify = require('gulp-notify'),
autoprefixer = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
scsslint = require('gulp-scsslint'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename'),
livereload = require('gulp-livereload'),
lr = require('tiny-lr'),
server = lr();
// Directories
var SRC = 'public/assets',
DIST = 'public/dist';
// SCSS Linting, Compiling and Minification
var scssLintReporter = function(file) {
if ( !file.scsslint.success ) {
gutil.beep();
notify().write({ message: file.scsslint.errorCount + ' error in scss' });
// Loop through the warnings/errors and spit them out
file.scsslint.results.forEach(function(result) {
var msg =
c.cyan(file.path) + ':' +
c.red(result.line) + ' ' +
('error' === result.severity ? c.red('[E]') : c.cyan('[W]')) + ' ' +
result.reason;
gutil.log(msg);
});
} else {
notify().write({ message: 'SCSS Linted' });
gulp.start('styles');
}
};
gulp.task('scss-lint', function() {
gulp.src(SRC + '/styles/app.scss')
.pipe(scsslint({
'config': '.scss-lint.yml'
}))
.pipe(scsslint.reporter(scssLintReporter));
});
gulp.task('styles', function(){
gulp.src(SRC + '/styles/app.scss')
.pipe(
sass({
outputStyle: 'expanded',
debugInfo: true,
lineNumbers: true,
errLogToConsole: true,
onSuccess: function(){
notify().write({ message: "SCSS Compiled successfully!" });
},
onError: function(err) {
gutil.beep();
notify().write(err);
}
})
)
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe( gulp.dest(DIST + '/styles') )
.pipe(livereload(server));
});
// JS files we'll be using
var JS = [
SRC + '/js/**/*!(app)*.js',
SRC + '/js/app.js'
];
// Custom JS Hint Reporter
var jsHintReporter = map(function(file) {
if ( !file.jshint.success ) {
gutil.beep();
notify().write({ message: file.jshint.errorCount + ' error in js' });
// Loop through the warnings/errors and spit them out
file.jshint.results.forEach(function(err) {
if (err) {
var msg =
c.cyan(file.path) + ':' +
c.red(err.line) + ' ' +
('error' === err.severity ? c.red('[E]') : c.cyan('[W]')) + ' ' +
err.reason;
gutil.log(msg);
}
});
} else {
notify().write({ message: 'SCSS Linted' });
gulp.start('styles');
}
});
// JS Lint
gulp.task("js-lint", function() {
gulp.src( JS )
.pipe(jshint())
.pipe(jsHintReporter);
});
// JS Scripts
gulp.task("scripts", function() {
gulp.src( JS )
.pipe(concat('main.js'))
.pipe(gulp.dest(DIST + '/js'))
.pipe(rename('main.min.js'))
.pipe(uglify())
.pipe(gulp.dest(DIST + '/js'));
});
// Image Minification
gulp.task('image-min', function () {
return gulp.src( SRC + '/images/**/*')
.pipe(imagemin())
.pipe(gulp.dest( DIST + '/images' ))
.pipe(notify('Images compressed'));
});
// Fonts
gulp.task('fonts', function() {
gulp.src(SRC + '/fonts/**/*')
.pipe(gulp.dest(DIST + '/fonts'));
});
// Clean dist directory for rebuild
gulp.task('clean', function() {
return gulp.src(DIST, {read: false})
.pipe(clean());
});
// Do the creep, ahhhhhhh! (http://youtu.be/tLPZmPaHme0?t=7s)
gulp.task('watch', function() {
// Listen on port 35729
server.listen(35729, function (err) {
if (err) {
return console.log(err);
}
// Watch .scss files
gulp.watch(SRC + '/styles/**/*.scss', ['scss-lint', 'styles']);
// Watch .js files to lint and build
gulp.watch(SRC + '/js/*.js', ['js-lint', 'scripts']);
// Watch image files
gulp.watch( SRC + '/images/**/*', ['image-min']);
});
});
// Gulp Default Task
gulp.task('default', ['scss-lint', 'js-lint', 'scripts', 'fonts', 'image-min', 'watch']);