-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
119 lines (102 loc) · 3.46 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
const path = require("path");
const merge = require("merge2");
const gulp = require("gulp");
const gulpif = require("gulp-if");
const util = require("gulp-util");
const clean = require("gulp-clean");
const ts = require("gulp-typescript");
const babel = require("gulp-babel");
const sourcemaps = require("gulp-sourcemaps");
const jasmine = require("gulp-jasmine");
const shell = require('gulp-shell')
const SpecReporter = require('jasmine-spec-reporter').SpecReporter;
// TODO: jslint
const outDir = path.join(__dirname, "lib"),
tmpDir = path.join(__dirname, "tmp"),
specsDir = path.join(__dirname, "spec"),
srcDir = path.join(__dirname, "src");
let tsProject, tsReporter;
const buildConfig = {
// Disables the clean process
dirty: !!util.env.dirty,
// Disabled new builds
fast: !!util.env.fast,
sourcemaps: !!util.env.sourcemaps,
cover: !!util.env.cover
}
// Cover requires sourcemaps
if (buildConfig.cover) buildConfig.sourcemaps = true;
if (buildConfig.dirty) {
console.log("> Dirty build");
}
if (buildConfig.fast) {
console.log("> Fast build");
}
if (buildConfig.sourcemaps) {
console.log("> Sourcemaps enabled");
}
if (buildConfig.cover) {
console.log("> Code coverage enabled");
}
gulp.task("clean:lib", () => {
return gulp.src(outDir, { read: false, allowEmpty: true })
.pipe(gulpif(!buildConfig.dirty, clean()));
});
gulp.task("clean:tmp", () => {
return gulp.src(tmpDir, { read: false, allowEmpty: true })
.pipe(gulpif(!buildConfig.dirty, clean()));
});
gulp.task("clean", gulp.parallel("clean:lib", "clean:tmp"));
gulp.task("build", gulp.series("clean", () => {
if (buildConfig.fast) {
return Promise.resolve();
}
if (!tsProject) {
tsProject = ts.createProject(
"tsconfig.json",
require(path.join(srcDir, "tsconfig.json")).compilerOptions);
tsReporter = ts.reporter.fullReporter();
}
const build = tsProject.src()
.pipe(gulpif(buildConfig.sourcemaps, sourcemaps.init()))
.pipe(tsProject(tsReporter));
return merge([
build.js
.pipe(babel())
.pipe(gulpif(buildConfig.sourcemaps, sourcemaps.write("./", {
mapSources: (sourcePath, file) => {
return path.resolve(outDir, sourcePath);
}
})))
.pipe(gulp.dest(outDir)),
build.dts
.pipe(gulp.dest(outDir))
]);
}));
gulp.task("watch", gulp.series("build", function watch(_) {
buildConfig.dirty = true;
buildConfig.fast = false;
gulp.watch(path.join(srcDir, "**/*"), { mode: "poll" }, gulp.series("build"));
}));
gulp.task("test:cover", shell.task("nyc -c false gulp test --dirty --fast"));
gulp.task("test", gulp.series("build", buildConfig.cover ? gulp.series("test:cover") : function test() {
const config = require(path.join(specsDir, "support/jasmine.json"));
const reporter = new SpecReporter({
spec: {
displayPending: true,
displayDuration: true,
displaySuccessful: true,
displayFailed: true,
displayErrorMessages: true,
displayStacktrace: true
}
});
// TODO: Load glob from spec/support/jasmine.json (config)
return gulp.src(path.join(specsDir, "**/*.spec.js"))
.pipe(jasmine({
config: config,
reporter: reporter
}));
}));
gulp.task("dev", gulp.series("watch"));
gulp.task("default", gulp.series("build"));