-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
79 lines (66 loc) · 2.03 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
'use strict';
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
watch = require('gulp-watch'),
jshint = require('gulp-jshint'),
livereload = require('gulp-livereload'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
watchify = require('watchify');
var production = process.env.NODE_ENV === 'production';
function handleError() {
return function(err) {
console.log(err);
};
}
function scripts(watch) {
var bundler, rebundle;
bundler = browserify('./public/js/app.js', {
basedir: __dirname,
debug: !production,
cache: {}, // required for watchify
packageCache: {}, // required for watchify
fullPaths: watch // required to be true only for watchify
});
if(watch) {
bundler = watchify(bundler);
}
rebundle = function() {
var stream = bundler.bundle();
stream.on('error', handleError());
stream = stream.pipe(source('bundle.js'));
return stream.pipe(gulp.dest('./public/js'));
};
bundler.on('update', rebundle);
return rebundle();
}
//register nodemon task
gulp.task('nodemon', function () {
nodemon({ script: './bin/www', env: { 'NODE_ENV': 'development' }})
.on('restart');
});
// Rerun the task when a file changes
gulp.task('watch', function() {
var server = livereload();
gulp.src(['*.js','routes/*.js', 'public/*.js'], { read: true })
.pipe(watch({ emit: 'all' }))
.pipe(jshint())
.pipe(jshint.reporter('default'));
gulp.watch(['*.js','routes/*.js', 'views/**/*.*', 'public/**/*.*']).on('change', function(file) {
server.changed(file.path);
});
});
//lint js files
gulp.task('lint', function() {
gulp.src(['*.js','routes/*.js', 'public/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
gulp.task('scripts', function() {
return scripts(false);
});
gulp.task('watchScripts', function() {
return scripts(true);
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['lint','nodemon', 'watch', 'watchScripts']);