-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
156 lines (136 loc) · 3.94 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
'use strict';
const $ = require('gulp-load-plugins')();
const del = require('del');
const gulp = require('gulp');
const manifest = require('./package.json');
const path = require('path');
const coverageDir = path.join(__dirname, 'coverage');
const distDir = path.join(__dirname, 'dist');
const docsDir = path.join(__dirname, 'documentation');
const stagingDir = path.join(__dirname, 'staging');
const junitReport = path.join(__dirname, 'junit_report.xml');
/*
* Clean tasks
*/
gulp.task('clean', ['clean-coverage', 'clean-dist', 'clean-docs', 'clean-reports', 'clean-staging', 'clean-zip']);
gulp.task('clean-coverage', function (done) {
del([coverageDir]).then(function () { done(); });
});
gulp.task('clean-dist', function (done) {
del([distDir]).then(function () { done(); });
});
gulp.task('clean-docs', function (done) {
del([docsDir]).then(function () { done(); });
});
gulp.task('clean-reports', function (done) {
del([junitReport]).then(function () { done(); });
});
gulp.task('clean-staging', function (done) {
del([stagingDir]).then(function () { done(); });
});
gulp.task('clean-zip', function (done) {
del(['*.zip']).then(function () { done(); });
});
/*
* build tasks
*/
gulp.task('build', ['clean-dist', 'lint-src'], function () {
return gulp
.src('src/index.js')
.pipe($.plumber())
.pipe($.debug({ title: 'build' }))
.pipe($.sourcemaps.init())
.pipe($.rollup({
sourceMap: true
}))
.pipe($.babel())
.pipe($.rename(manifest.name + '.js'))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest(distDir));
});
gulp.task('prep', ['build', 'docs'], function () {
// TODO Include documentation!
return gulp.src(['dist/' + manifest.name + '.js', 'package.json', 'manifest', 'LICENSE'])
.pipe(gulp.dest(path.join(__dirname, 'staging', 'modules', 'commonjs', manifest.name, manifest.version)));
});
gulp.task('dist', ['prep'], function () {
return gulp.src('staging/**/*')
.pipe($.zip(manifest.name + '-commonjs-' + manifest.version + '.zip'))
.pipe(gulp.dest(__dirname));
});
gulp.task('docs', ['lint-src', 'clean-docs'], function () {
return gulp.src('src')
.pipe($.plumber())
.pipe($.debug({ title: 'docs' }))
.pipe($.esdoc({
// debug: true,
destination: docsDir,
plugins: [
{ name: 'esdoc-es7-plugin' }
],
title: manifest.name
}));
});
/*
* lint tasks
*/
function lint(pattern) {
return gulp.src(pattern)
.pipe($.plumber())
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
}
gulp.task('lint-src', function () {
return lint('src/**/*.js');
});
gulp.task('lint-test', function () {
return lint('test/**/test-*.js');
});
/*
* test tasks
*/
gulp.task('test', ['lint-src', 'lint-test'], function () {
var suite, grep;
var p = process.argv.indexOf('--suite');
if (p !== -1 && p + 1 < process.argv.length) {
suite = process.argv[p + 1];
}
p = process.argv.indexOf('--grep');
if (p !== -1 && p + 1 < process.argv.length) {
grep = process.argv[p + 1];
}
return gulp.src(['src/**/*.js', 'test/**/*.js'])
.pipe($.plumber())
.pipe($.debug({ title: 'build' }))
.pipe($.babel())
.pipe($.injectModules())
.pipe($.filter(suite ? ['test/setup.js'].concat(suite.split(',').map(s => 'test/**/test-' + s + '.js')) : 'test/**/*.js'))
.pipe($.debug({ title: 'test' }))
.pipe($.mocha({ grep: grep }));
});
gulp.task('coverage', ['lint-src', 'lint-test', 'clean-coverage'], function (cb) {
gulp.src('src/**/*.js')
.pipe($.plumber())
.pipe($.debug({ title: 'build' }))
.pipe($.babelIstanbul())
.pipe($.injectModules())
.on('finish', function () {
gulp.src('test/**/*.js')
.pipe($.plumber())
.pipe($.debug({ title: 'test' }))
.pipe($.babel())
.pipe($.injectModules())
.pipe($.mocha({
reporter: 'mocha-jenkins-reporter',
reporterOptions: {
junit_report_name: 'Tests',
junit_report_path: junitReport,
junit_report_stack: 1
}
}))
.pipe($.babelIstanbul.writeReports())
.on('end', cb);
});
});
gulp.task('default', ['build']);