forked from paypal/paypal-checkout-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
84 lines (68 loc) · 2.39 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
let gulp = require('gulp');
let webpackStream = require('webpack-stream');
let gulpEslint = require('gulp-eslint');
let gulpFlowtype = require('gulp-flowtype');
let webpack = require('webpack');
let karma = require('karma');
let yargs = require('yargs');
let webpackConfig = require('./webpack.conf');
let del = require('del');
gulp.task('test', ['lint', 'typecheck', 'karma']);
gulp.task('build', ['test', 'webpack']);
Object.keys(webpackConfig.webpack_tasks).forEach(name => {
gulp.task(`webpack-${name.replace(/_/g, '-')}`, () => {
let task = webpackConfig.webpack_tasks[name];
return gulp.src(task.src)
.pipe(webpackStream(task.cfg, webpack))
.pipe(gulp.dest(task.out));
});
});
gulp.task('webpack', Object.keys(webpackConfig.webpack_tasks).map(name => `webpack-${name.replace(/_/g, '-')}`));
gulp.task('typecheck', [ 'lint' ], function() {
return gulp.src([ 'src/**/*.js', 'test/**/*.js' ])
.pipe(gulpFlowtype({
abort: true
}))
});
gulp.task('lint', ['lint-src', 'lint-test']);
gulp.task('lint-src', function() {
return gulp.src([ 'src/**/*.js' ]).pipe(gulpEslint({
fix: Boolean(yargs.argv['fix'])
}))
.pipe(gulpEslint.format())
.pipe(gulpEslint.failAfterError())
});
gulp.task('lint-test', function() {
return gulp.src([ 'test/{tests,windows}/**/*.js' ]).pipe(gulpEslint({
fix: Boolean(yargs.argv['fix'])
}))
.pipe(gulpEslint.format())
.pipe(gulpEslint.failAfterError())
});
gulp.task('karma', function (done) {
if(yargs.argv['clear-cache']) {
del.sync(['node_modules/.cache/babel-loader', 'node_modules/.cache/phantomjs']);
}
let server = new karma.Server({
configFile: __dirname + '/karma.conf.js',
singleRun: !(yargs.argv.debug || yargs.argv['keep-open']),
client: {
captureConsole: Boolean(yargs.argv['capture-console']),
mocha: {
timeout : process.env.TRAVIS ? 60 * 1000 : 10 * 1000,
bail: true
}
}
});
server.on('browser_error', function (browser, err) {
console.log('Karma Run Failed: ' + err.message);
throw err;
});
server.on('run_complete', function (browsers, results) {
if (results.failed) {
return done(new Error('Karma: Tests Failed'));
}
done();
});
server.start();
});