-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
65 lines (53 loc) · 1.69 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var mocha = require('gulp-mocha');
var eslint = require('gulp-eslint');
var rebuildDB = require('./dummyData/index');
function compile(watch) {
var bundler = watchify(browserify('./server/client/index.js', { debug: true }).transform(babelify));
function rebundle() {
// rebuildDB();
bundler.bundle()
.on('error', function(err) { console.error(err); this.emit('end'); })
.pipe(source('index.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./server/client/public/scripts'));
}
if (watch) {
bundler.on('update', function() {
console.log('[' + new Date().toTimeString().split(' ')[0] + '] -> bundling...');
rebundle();
});
}
rebundle();
}
function watch() {
return compile(true);
};
gulp.task('bundle', function() { return compile(); });
gulp.task('watch', function() { return watch(); });
gulp.task('default', ['watch']);
gulp.task('mocha', function () {
return gulp.src('./specs/serverspecs/**/*.spec.js')
.pipe(mocha({reporter: 'spec'}))
.once('end', function () {
process.exit();
});
});
gulp.task('lint', function () {
return gulp.src(['server/**/*.js', '!server/client/public/scripts/index.js'])
.pipe(eslint())
.pipe(eslint.format())
// .pipe(eslint.failOnError());
});
gulp.task('test', ['mocha', 'lint']);
gulp.task('cleanDB', function(){
rebuildDB();
});