forked from jbmusso/gremlin-javascript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.babel.js
89 lines (74 loc) · 1.97 KB
/
Gulpfile.babel.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
'use strict';
import gulp from 'gulp';
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import buffer from 'gulp-buffer';
import uglify from 'gulp-uglify';
import size from 'gulp-size';
import rename from 'gulp-rename';
import mocha from 'gulp-mocha';
var karma = require('karma').server;
var args = require('yargs').argv;
function printError(error) {
console.error('\nError:', error.plugin);
console.error(error.message);
}
function printEvent(event) {
console.log('File', event.type +':', event.path);
}
var bundler;
function getBundler() {
if (!bundler) {
bundler = browserify('./index.js', {
debug: true,
standalone: 'gremlin'
});
}
return bundler;
}
gulp.task('build', () => {
return getBundler()
.transform(babelify)
.bundle()
.on('error', function(err) { console.log('Error: ' + err.message); })
.pipe(source('./gremlin.js'))
.pipe(gulp.dest('./'))
.pipe(buffer())
.pipe(size({ showFiles: true }))
.pipe(uglify())
.pipe(rename('gremlin.min.js'))
.pipe(size({ showFiles: true }))
.pipe(gulp.dest('./'));
});
gulp.task('test', ['test:node', 'test:browsers']);
gulp.task('test:node', () => {
return gulp.src('test/**/*')
.pipe(mocha({
reporter: 'spec',
bail: !!args.bail
}))
.on('error', printError);
});
gulp.task('test:browsers', (done) => {
const karmaCommonConf = {
browsers: ['Chrome', 'Firefox', 'Safari'],
frameworks: ['mocha', 'chai', 'browserify'],
preprocessors: {
'test/*': ['browserify']
},
files: [
'test/**/*.js'
],
browserify: {
watch: true // Watches dependencies only (Karma watches the tests)
}
};
karma.start(karmaCommonConf, done);
});
gulp.task('watch', function() {
gulp.watch(['src/**/*', 'test/**/*', 'index.js'], ['test-node'])
.on('change', printEvent);
});
gulp.task('default', ['build']);
gulp.task('dev', ['test', 'watch']);