This repository has been archived by the owner on Nov 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
104 lines (87 loc) · 2.06 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
import gulp from 'gulp';
import babel from 'gulp-babel';
import env from 'gulp-env';
import mocha from 'gulp-mocha';
import eslint from 'gulp-eslint';
import del from 'del';
import plumber from 'gulp-plumber';
import yargs from 'yargs';
const config = {
paths: {
js: {
src: 'src/**/*.js',
dist: 'dist/'
},
test: {
src: 'test/**/*.js',
dist: 'test-dist/',
run: 'test-dist/**/*.js'
}
}
};
let envConfig;
try {
envConfig = require('./.env.json');
const timestamp = Date.now();
for (const key in envConfig) {
if (!key) continue;
envConfig[key] = envConfig[key]
.replace(/\$\{timestamp\}/g, timestamp);
}
} catch (error) {
if (error instanceof SyntaxError) throw error;
envConfig = {};
}
gulp.task('clean', () =>
del([config.paths.js.dist, config.paths.test.dist])
);
gulp.task('build', ['clean', 'babel-src', 'babel-test']);
gulp.task('babel-src', ['lint-src'], () =>
gulp.src(config.paths.js.src)
.pipe(babel())
.pipe(gulp.dest(config.paths.js.dist))
);
gulp.task('babel-test', ['lint-test'], () =>
gulp.src(config.paths.test.src)
.pipe(babel())
.pipe(gulp.dest(config.paths.test.dist))
);
gulp.task('lint-src', () =>
gulp.src(config.paths.js.src)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('lint-test', () =>
gulp.src(config.paths.test.src)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('watch', () => {
envConfig.WATCH_MODE = true;
return gulp.watch(
[
config.paths.js.src,
config.paths.test.src
],
['build', 'test']
);
});
gulp.task('test', ['build'], () => {
const envs = env.set(envConfig);
return gulp.src([config.paths.test.run], { read: false })
.pipe(plumber({
errorHandler(error) {
if (!envConfig.WATCH_MODE) throw error;
}
}))
.pipe(envs)
.pipe(mocha({
bail: true,
reporter: 'spec',
grep: yargs.argv['mocha-grep']
}))
.pipe(envs.reset);
});
gulp.task('default', ['build', 'test']);