-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathgulpfile.js
76 lines (61 loc) · 1.71 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
const gulp = require("gulp");
const eslint = require("gulp-eslint");
const compiler = require("webpack");
const webpack = require("webpack-stream");
const watch = require("gulp-watch");
const karma = require("karma");
const parseConfig = karma.config.parseConfig;
const KarmaServer = karma.Server;
const webpackConfig = require("./webpack.config.js");
const source = ["src/**/*.js"];
const test = source.concat(["test/**/*.spec.js"]);
gulp.task("pack", function () {
return gulp
.src("src/index.js")
.pipe(
webpack(webpackConfig, compiler, function (_err, _stats) {
/* Use stats to do more things if needed */
})
)
.pipe(gulp.dest("build/"));
});
gulp.task("lint", function () {
return (
gulp
// Define the source files
.src("src/**/*.js")
.pipe(eslint({}))
// Output the results in the console
.pipe(eslint.format())
);
});
gulp.task("karma", function (done) {
parseConfig(
__dirname + "/karma.conf.js",
{ files: test, singleRun: true },
{ promiseConfig: true, throwErrors: true }
).then(
(karmaConfig) => {
new KarmaServer(karmaConfig, done).start();
},
(_rejectReason) => {}
);
});
gulp.task("watch-karma", function () {
return gulp.src(test).pipe(
karma({
configFile: "karma.conf.js",
action: "watch",
})
);
});
gulp.task("watch-build-watch", function () {
watch(source, gulp.series("build"));
});
// Main tasks
const buildTask = gulp.series("pack");
gulp.task("default", buildTask);
gulp.task("build", buildTask);
gulp.task("test", gulp.series("build", "karma"));
gulp.task("watch-build", gulp.series("build", "watch-build-watch"));
gulp.task("watch", gulp.series("watch-build", "watch-karma"));