-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
152 lines (102 loc) · 2.72 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
var
// GULP
gulp = require('gulp'),
// PLUGINS
autoprefixer = require('gulp-autoprefixer'),
gutil = require('gulp-util'),
include = require('gulp-include'),
jshint = require('gulp-jshint'),
minifyhtml = require('gulp-minify-html'),
notify = require('gulp-notify'),
sass = require('gulp-sass'),
stylish = require('jshint-stylish'),
uglify = require('gulp-uglify'),
// ENVIRONMENT VARIABLES
environment_vars = {
dev: {
sass: {
outputStyle: 'expanded'
}
},
prod: {
sass: {
outputStyle: 'compressed'
}
}
},
dirs = {
assets: './dist/assets/',
dist: './dist/',
src: './src/'
},
ENV = environment_vars.prod
;
/**
* Error Report handling
*
* @source https://github.com/mikaelbr/gulp-notify/issues/81#issuecomment-100422179
*/
var reportError = function( error ) {
var lineNumber = ( error.lineNumber ) ? 'LINE ' + error.lineNumber + ' -- ' : '',
report = '',
chalk = gutil.colors.white.bgRed;
notify( {
title: 'Task Failed [' + error.plugin + ']',
message: lineNumber + 'See console.',
sound: 'Frog' // See: https://github.com/mikaelbr/node-notifier#all-notification-options-with-their-defaults
} ).write( error );
// Inspect the error object
//console.log(error);
// Easy error reporting
//console.log(error.toString());
// Pretty error reporting
report += chalk( 'TASK:' ) + ' [' + error.plugin + ']\n';
report += chalk( 'PROB:' ) + ' ' + error.message + '\n';
if ( error.lineNumber ) { report += chalk( 'LINE:' ) + ' ' + error.lineNumber + '\n'; }
if ( error.fileName ) { report += chalk( 'FILE:' ) + ' ' + error.fileName + '\n'; }
console.error( report );
// Prevent the 'watch' task from stopping
if( error.plugin === 'gulp-sass' ) {
this.emit( 'end' );
}
};
gulp.task( 'html', function() {
return gulp.src( dirs.src + '*.html' )
.pipe( minifyhtml( ) )
.pipe( gulp.dest( dirs.dist ) )
;
} );
gulp.task( 'js', function() {
return gulp.src([
dirs.src + 'js/*.js',
'!' + dirs.src + 'js/vendor/*.js'
])
.pipe( jshint('.jshintrc') )
.pipe( jshint.reporter( stylish ) )
.pipe( jshint.reporter('fail') )
.on( 'error', reportError )
.pipe( include() )
.pipe( uglify() )
.pipe( gulp.dest( dirs.assets + 'js' ) )
;
});
/**
* Compile SCSS
*/
gulp.task( 'scss', function() {
return gulp.src( [
dirs.src + 'scss/*.scss',
'!' + dirs.src + 'scss/_*.scss'
] )
.pipe( sass( ENV.sass ) )
.on( 'error', reportError )
.pipe( autoprefixer( { browsers: [ 'last 2 Chrome versions' ] } ) )
.pipe( gulp.dest( dirs.assets + 'css' ) )
;
} );
// watch
gulp.task( 'watch', function () {
gulp.watch( dirs.src + '*.html', ['html'] );
gulp.watch( dirs.src + 'js/*.js', ['js'] );
gulp.watch( dirs.src + 'scss/*.scss', ['scss'] );
} );