-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
128 lines (111 loc) · 2.19 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
'use strict';
const gulp = require('gulp');
const gulpEslint = require('gulp-eslint');
const gulpMocha = require('gulp-mocha');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const browserify = require('browserify');
const del = require('del');
const sourceStream = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const typescript = require('gulp-typescript');
const KarmaServer = require('karma').Server;
const jsFiles = [
'*.js',
'lib/**/*.js',
'test/**/*.js'
];
const tsFiles = [
'*.ts',
'@types/**/*.ts'
];
function lint() {
return gulp.src(jsFiles)
.pipe(gulpEslint())
.pipe(gulpEslint.format())
.pipe(gulpEslint.failAfterError());
}
function testTypes() {
return gulp.src(tsFiles)
.pipe(typescript({
lib: ['es2015']
}));
}
function test(done) {
return gulp.parallel(testNode, testTypes)(done);
}
function testNode() {
return gulp.src('test/node/**/*Spec.js', {read: false})
.pipe(gulpMocha({
reporter: 'spec'
}));
}
function testBrowser(done) {
const karmaConfig = {
browsers: ['Chrome', 'Firefox'],
frameworks: ['mocha'],
reporters: ['progress'],
autoWatch: false,
singleRun: true,
files: [
'dist/hamjest.js',
'test/browser/**/*.js'
]
};
const server = new KarmaServer(karmaConfig, done);
server.start();
}
function buildDist() {
const b = browserify({
entries: './index.js',
standalone: 'hamjest',
debug: true
})
.transform('babelify', {presets: [
[
'@babel/preset-env',
{
targets: {
browsers: require('./package.json').browserslist,
},
loose: false,
// modules: false,
useBuiltIns: 'usage',
corejs: 'core-js@3',
},
]
]});
return b.bundle()
.pipe(sourceStream('hamjest.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist'))
.pipe(uglify())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('./dist'));
}
function clean() {
return del('./dist');
}
function dev(done) {
gulp.watch(jsFiles, gulp.parallel(lint, test));
gulp.watch(tsFiles, testTypes);
done();
}
const build = gulp.series(
gulp.parallel(lint, test),
buildDist,
testBrowser
);
module.exports = {
clean,
build,
lint,
dev,
test,
default: gulp.series(
clean,
build
)
};