-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
102 lines (84 loc) · 2.44 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
'use strict';
var browserify = require('browserify')
, gulp = require('gulp')
, image = require('gulp-image')
, inject = require('gulp-inject')
, jshint = require('gulp-jshint')
, less = require('gulp-less')
, mocha = require('gulp-mocha')
, nodemon = require('nodemon')
, rimraf = require('rimraf')
, source = require('vinyl-source-stream')
, sourcemaps = require('gulp-sourcemaps')
, util = require('gulp-util')
;
var nodemonInstance;
gulp.task('lint', function () {
return gulp
.src(['client/**/*.js', 'server/**/*.js', 'tests/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('test', function () {
return gulp.src('tests/**/*.js', {read: false})
.pipe(mocha({reporter: 'dot'}));
});
gulp.task('browserify', function() {
return browserify('./client/main.js')
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest('build/'));
});
gulp.task('less', function () {
return gulp
.src('./**/*.less', { cwd: 'client/less/' })
.pipe(sourcemaps.init())
.pipe(less())
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/css'));
});
gulp.task('image', function () {
return gulp
.src('client/images/*')
.pipe(image())
.pipe(gulp.dest('build/images/'));
});
gulp.task('js', ['lint'], function () {
return gulp
.src('client/js/*.js')
.pipe(gulp.dest('build/js/'));
});
gulp.task('html', ['browserify', 'less', 'js'], function () {
var sources = gulp.src(['./**/*.js', './**/*.css'], { cwd: 'build/' });
return gulp
.src('client/**/*.html')
.pipe(inject(sources))
.pipe(gulp.dest('build/'))
;
});
gulp.task('build', ['lint', 'browserify', 'less', 'image', 'js', 'html', 'test']);
gulp.task('serve', ['lint'], function (cb) {
if (!nodemonInstance) {
nodemonInstance = nodemon({
script: './server/main.js',
ignore: ['*'] // disable default watch
}).on('log', function (log) {
util.log(log.colour);
}).once('start', cb);
} else {
nodemonInstance
.once('start', cb)
.emit('restart');
}
});
gulp.task('watch', ['build', 'serve'], function(cb) {
gulp.watch('client/**/*.js', ['lint', 'browserify', 'js', 'html']);
gulp.watch('server/**/*.js', ['lint', 'test', 'serve']);
gulp.watch('client/less/*.less', ['less']);
gulp.watch('client/images/*', ['image']);
gulp.watch('client/**/*.html', ['html']);
return cb();
});
gulp.task('clean', function (cb) {
rimraf('build/', cb);
});