-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
116 lines (86 loc) · 2.99 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
/* eslint-disable require-jsdoc */
const gulp = require("gulp");
const eslint = require("gulp-eslint-new");
const jest = require("gulp-jest").default;
const rename = require("gulp-rename");
const rollup = require("rollup");
const shell = require("gulp-shell");
const sourcemaps = require("gulp-sourcemaps");
const terser = require("gulp-terser");
const jestBaseConfig = require("./jest.config.js");
const pkg = require("./package.json");
const intro = [
"/**",
"* @overview " + pkg.name + " - " + pkg.description,
"* @author " + pkg.author.name + " <" + pkg.author.email + ">",
"* @version " + pkg.version,
"* @module lamb",
"* @license " + pkg.license,
"*/"
].join("\n");
const commonOptions = {
banner: intro,
exports: "named",
freeze: false,
name: "lamb",
sourcemap: false,
strict: true
};
const esOptions = Object.assign({}, commonOptions, {
file: "dist/lamb.mjs",
format: "esm"
});
const umdOptions = Object.assign({}, commonOptions, {
file: "dist/lamb.js",
format: "umd"
});
/* env */
gulp.task("set-test-env", cb => {
process.env.NODE_ENV = "test";
return cb();
});
/* build */
const builder = opts => () => rollup.rollup({ input: "src/index.js" }).then(bundle => bundle.write(opts));
const minifier = isES => () => gulp.src(`dist/lamb${isES ? ".mjs" : ".js"}`)
.pipe(sourcemaps.init())
.pipe(terser({ mangle: { module: isES }, output: { comments: "some" } }))
.pipe(rename({ extname: isES ? ".min.mjs" : ".min.js" }))
.pipe(sourcemaps.write("."))
.pipe(gulp.dest("dist"));
gulp.task("bump", shell.task("bump package.json package-lock.json"));
gulp.task("build:es", gulp.series(builder(esOptions), minifier(true)));
gulp.task("build:umd", gulp.series(builder(umdOptions), minifier(false)));
gulp.task("build", gulp.parallel("build:es", "build:umd"));
gulp.task("dist", gulp.series("bump", "build"));
/* lint */
const lintWith = settings => () => gulp.src(settings.inputs)
.pipe(eslint(settings.configPath))
.pipe(eslint.format())
.pipe(eslint.failAfterError());
gulp.task("lint:code", lintWith({
configPath: ".eslintrc.json",
inputs: ["./src/**/*.js", "!./src/**/__{tests,mocks}__/**"]
}));
gulp.task("lint:tests", lintWith({
configPath: ".eslintrc.test.json",
inputs: ["./*.js", "./src/**/__{tests,mocks}__/**/*.js"]
}));
gulp.task("lint", gulp.series("lint:code", "lint:tests"));
/* test */
const testWith = extraSettings => gulp.series(
"set-test-env",
() => gulp.src("./src", { read: false }).pipe(
jest(Object.assign({}, jestBaseConfig, extraSettings))
)
);
gulp.task("test", testWith({}));
gulp.task("test:coverage", testWith({ collectCoverage: true }));
gulp.task("test:verbose", testWith({ verbose: true }));
gulp.task("test:watch", gulp.series(
"set-test-env",
async () => gulp.src("./src", { read: false }).pipe(
jest(Object.assign({}, jestBaseConfig, { watch: true }))
)
));
/* default */
gulp.task("default", gulp.series("lint", "test:coverage"));