This repository has been archived by the owner on Feb 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgulpfile.babel.js
131 lines (112 loc) · 3.16 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* eslint-env node */
import gulp from 'gulp';
import path from 'path';
import del from 'del';
import pkg from './package.json';
import webpackConfig from './webpack.config.babel.js';
import webpack from 'webpack';
import webpackStream from 'webpack-stream';
import WebpackDevServer from 'webpack-dev-server';
import {Server as Karma} from 'karma';
import gutil from 'gulp-util';
import eslint from 'gulp-eslint';
import jscs from 'gulp-jscs';
import header from 'gulp-header';
import esdoc from 'gulp-esdoc';
import esdocConfig from './esdoc.json';
const DIST = 'dist';
const BANNER = [
'/**',
` * @file ${pkg.name}`,
` * @description ${pkg.description}`,
` * @version v${pkg.version}`,
` * @see {@link ${pkg.homepage}}`,
` * @license ${pkg.license}`,
` * @author ${pkg.author.name}`,
` * @copyright ${new Date().getFullYear()} Krux Digital, Inc`,
' */',
''
].join('\n');
const LINTABLE_PATTERN = [
'*.js',
'src/**/*.js',
'test/**/*.js'
];
function build(config) {
return () => webpackStream(config)
.pipe(header(BANNER))
.pipe(gulp.dest(DIST));
}
function test(configName, failOnError = true, karmaOptions = {}) {
return done => new Karma(Object.assign({
configFile: path.resolve(`test/karma-${configName}.config.babel.js`)
}, karmaOptions), err => {
if (err) {
gutil.log('[test]', 'Tests failed');
if (failOnError) {
done(new gutil.PluginError('karma', 'Tests failed'));
} else {
done();
}
} else {
done();
}
}).start();
}
gulp.task('default', ['lint', 'build', 'doc', 'test']);
gulp.task('clean', () => {
return del.sync([`${DIST}/**`]);
});
gulp.task('build', build(webpackConfig));
gulp.task('doc', () => {
return gulp.src('./src')
.pipe(esdoc(esdocConfig));
});
gulp.task('lint', ['lint:eslint', 'lint:jscs']);
gulp.task('lint:eslint', () => {
return gulp.src(LINTABLE_PATTERN)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('lint:jscs', () => {
return gulp.src(LINTABLE_PATTERN)
.pipe(jscs())
.pipe(jscs.reporter());
});
gulp.task('serve', ['build'], done => {
const devConfig = Object.create(webpackConfig);
devConfig.devtool = 'eval';
devConfig.debug = true;
gutil.log('[serve]', `http://localhost:${pkg.config.ports.cdn}/`);
new WebpackDevServer(webpack(devConfig), {
contentBase: DIST,
hot: true,
quiet: false,
stats: {
colors: true
}
}).listen(pkg.config.ports.cdn, 'localhost', (err, stats) => {
if (err) {
done(new gutil.PluginError('webpack', err));
} else {
if (stats) {
gutil.log('[serve]', stats.toString({
colors: true
}));
}
done();
}
});
});
gulp.task('test', test('coverage'));
gulp.task('test:ci', test('ci'));
gulp.task('test:coverage', test('coverage', false));
gulp.task('test:debug', test('nocoverage', true, {singleRun: false}));
gulp.task('test:nocoverage', test('nocoverage', false));
gulp.task('tdd', ['test:nocoverage'], () => {
gulp.watch(['src/**', 'test/**'], ['test:nocoverage']);
});
gulp.task('tdd:coverage', ['test:coverage'], () => {
gulp.watch(['src/**', 'test/**'], ['test:coverage']);
});