-
Notifications
You must be signed in to change notification settings - Fork 21
/
gulpfile.babel.js
116 lines (100 loc) · 2.79 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
import del from 'del';
import gulp from 'gulp';
import babel from 'gulp-babel';
import eslint from 'gulp-eslint';
import uglify from 'gulp-uglify';
import concat from 'gulp-concat';
import nodeunit from 'gulp-nodeunit';
import istanbul from 'gulp-istanbul';
const srcFolder = './src';
const distFolder = './dist';
const HTMLCSFolder = './node_modules/html_codesniffer';
gulp.task('clean', () =>
del(['dist', 'reports', 'test/*.xml']));
gulp.task('lint', () =>
gulp
.src([
`${srcFolder}/*.js`,
'!node_modules/**'
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('babel', () =>
gulp
.src(`${srcFolder}/**/*.js`)
.pipe(babel({
presets: ['es2015']
}))
// eslint-disable-next-line
.on('error', console.error.bind(console))
.pipe(gulp.dest(distFolder))
);
gulp.task('compressHTMLCS', () =>
gulp
.src([
`${HTMLCSFolder}/Contrib/Build/umd-header.js`,
`${HTMLCSFolder}/Standards/**/*.js`,
`${HTMLCSFolder}/HTMLCS.js`,
`${HTMLCSFolder}/HTMLCS.Util.js`,
`${HTMLCSFolder}/Contrib/Build/umd-footer.js`,
`${distFolder}/client/runner.js`
])
.pipe(concat('HTMLCS.min.js'))
.pipe(uglify())
.pipe(gulp.dest(distFolder))
);
gulp.task('pre-test', () =>
gulp.src(['dist/**/*.js'])
.pipe(istanbul())
.pipe(istanbul.hookRequire())
);
gulp.task('nodeunit', gulp.series('pre-test', () =>
gulp
.src(['test/**/*.test.js', 'dist/**/*.spec.js'])
.pipe(nodeunit({
reporter: 'junit',
reporterOptions: {
output: 'test/xmlResults'
}
}))
.on('error',(err) => {
process.exit.bind(process, 1);
// eslint-disable-next-line
console.error(err);
})
.pipe(istanbul.writeReports({
dir: './test/coverage',
reporters: ['lcov']
}))
.pipe(istanbul.enforceThresholds({ thresholds: { global: 75 } }))
.pipe(gulp.dest('test/coverage'))
));
gulp.task('developTests', () =>
gulp
.src('dist/**/*.spec.js')
.pipe(nodeunit())
.on('error',(err) => {
process.exit.bind(process, 1);
// eslint-disable-next-line
console.error(err);
})
);
gulp.task('babel:watch', () =>
gulp.watch(`${srcFolder}/**/*.js`, ['lint', 'babel'])
);
gulp.task('compress:watch', () =>
gulp.watch(`${distFolder}/runner.js`, ['compressHTMLCS'])
);
gulp.task('test:watch', () =>
gulp.watch('test/*.js', ['nodeunit'])
);
gulp.task('test:watch', () =>
gulp.watch('dist/**/*.spec.js', ['developTests'])
);
gulp.task('watch', gulp.parallel('babel:watch', 'compress:watch', 'test:watch'));
// Actual tasks
gulp.task('test', gulp.series('clean', 'lint', 'babel', 'compressHTMLCS', 'nodeunit'));
gulp.task('build', gulp.parallel('lint', 'compressHTMLCS', 'babel'));
gulp.task('default', gulp.parallel('build', 'watch'));