-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
92 lines (74 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
80
81
82
83
84
85
86
87
88
89
90
91
92
const _ = require('lodash');
const KarmaServer = require('karma').Server;
const gulp = require('gulp');
const shell = require('gulp-shell');
const gutil = require('gulp-util');
const path = require('path');
const cmdArgs = require('minimist')(process.argv.slice(2));
gulp.task('eslint', () => {
const eslint = require('gulp-eslint');
const friendlyFormatter = require('eslint-friendly-formatter');
return gulp.src([
'*.js',
'client/*.js',
'client/src/**/*.js',
'server/**/*.js',
'e2e/**/*.js'
])
.pipe(eslint())
.pipe(eslint.format(friendlyFormatter))
.pipe(eslint.failAfterError());
});
gulp.task('htmlhint', () => {
const htmlhint = require('gulp-htmlhint');
gulp.src('client/src/**/*.html')
.pipe(htmlhint({
'doctype-first': false,
'tag-self-close': true
}))
.pipe(htmlhint.reporter('htmlhint-stylish'));
});
gulp.task('lint', ['eslint', 'htmlhint']);
function buildKarmaServer(config) {
config = _.extend({}, {
configFile: path.join(__dirname, 'client', 'karma.config.js')
}, config);
if (cmdArgs.browsers) {
_.extend(config, {
browsers: cmdArgs.browsers.split(',')
});
}
return new KarmaServer(config);
}
gulp.task('test', (done) => {
const server = buildKarmaServer({ singleRun: true });
server.on('run_complete', (browsers, results) => {
const { failed } = results;
if (failed > 0) {
const message = failed > 1 ? 'Tests' : 'Test';
done(new gutil.PluginError('karma', {
message: [failed, message, 'failed'].join(' ')
}));
} else {
done();
}
});
server.start();
});
gulp.task('tdd', () => {
const server = buildKarmaServer({ singleRun: false });
server.start();
});
gulp.task('server:test', shell.task(
'node_modules/.bin/istanbul cover --dir artifacts/server/coverage ' +
'node_modules/.bin/_mocha -- --reporter dot server/**/*.spec.js'
));
gulp.task('default', (done) => {
const runSequence = require('run-sequence');
runSequence(
'lint',
'server:test',
'test',
done
);
});