-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
103 lines (88 loc) · 2.85 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
const path = require('path');
const gulp = require('gulp');
const babelify = require('babelify');
const browserify = require('browserify');
const watchify = require('watchify');
const source = require('vinyl-source-stream');
const karma = require('karma').server;
const isparta = require('isparta');
const babel = require('babel/register');
const plugins = require('gulp-load-plugins')();
function unitTests() {
return gulp.src(['tests/config/setup.js', 'tests/unit/**/*.js'])
.pipe(plugins.mocha({
reporter: 'spec',
compilers: {js: babel}
}));
}
gulp.task('lint', function () {
return gulp.src(['src/**/*.js', 'tests/**/*.js'])
.pipe(plugins.eslint())
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failAfterError())
.pipe(plugins.jscs());
});
gulp.task('coverage', function (done) {
gulp.src(['src/**/*.js'])
.pipe(plugins.istanbul({
instrumenter: isparta.Instrumenter,
includeUntested: true
}))
.pipe(plugins.istanbul.hookRequire())
.on('finish', function () {
unitTests()
.pipe(plugins.istanbul.writeReports())
.pipe(plugins.istanbul.enforceThresholds({thresholds: {global: 100}}))
.on('end', done);
});
});
gulp.task('test:unit', function () {
return unitTests();
});
gulp.task('test:integration', function (done) {
karma.start({
configFile: path.join(__dirname, '/tests/config/karma.conf.js'),
singleRun: true
}, done);
});
gulp.task('browserify', function () {
return buildScript(false);
});
gulp.task('compile', function () {
return gulp.src('dist/lib-build.js')
.pipe(plugins.uglify())
.pipe(plugins.rename({extname: '.min.js'}))
.pipe(gulp.dest('dist'));
});
gulp.task('build', plugins.sequence('browserify', 'compile'));
gulp.task('test', plugins.sequence('coverage', 'build', 'test:integration'));
gulp.task('default', plugins.sequence('lint', 'test'));
gulp.task('watch', function () {
buildScript(true);
});
function handleErrors() {
var args = Array.prototype.slice.call(arguments);
console.log("Error: ", args[0].loc, args[0].filename);
this.emit('end');
}
function buildScript(watch) {
var props = {
entries: './build.js',
debug: true,
transform: [babelify]
};
// watchify() if watch requested, otherwise run browserify() once
var bundler = watch ? watchify(browserify(props), {poll: true}) : browserify(props);
function rebundle() {
var stream = bundler.bundle();
return stream
.on('error', handleErrors)
.pipe(source('lib-build.js'))
.pipe(gulp.dest('dist'));
}
bundler.on('update', function () {
rebundle();
plugins.util.log('Rebundle...');
});
return rebundle();
}