-
Notifications
You must be signed in to change notification settings - Fork 72
/
gulpfile.js
107 lines (94 loc) · 2.25 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
var fs = require("fs");
var gulp = require("gulp");
var exit = require("gulp-exit");
var browserify = require("browserify");
var watchify = require("watchify");
var babelify = require("babelify");
var source = require("vinyl-source-stream");
var buffer = require("vinyl-buffer");
var sourcemaps = require("gulp-sourcemaps");
var concat = require("gulp-concat");
var rename = require("gulp-rename");
var minify = require("gulp-babel-minify");
var jsdoc = require("gulp-jsdoc3");
var webpack = require("webpack-stream");
function compile(watch) {
var bundler = watchify(
browserify("./app.js", {
debug: true
}).transform(babelify, {
presets: [
[
"env",
{
targets: {
chrome: "65"
}
}
]
],
sourceMaps: true
})
);
function rebundle() {
return bundler
.bundle()
.on("error", function(err) {
console.error(err);
this.emit("end");
})
.pipe(source("build.js"))
.pipe(buffer())
.pipe(rename("smiles-drawer.js"))
.pipe(
sourcemaps.init({
loadMaps: true
})
)
.pipe(gulp.dest("./dist/"))
.pipe(
minify({
mangle: false
})
)
.pipe(rename("smiles-drawer.min.js"))
.pipe(sourcemaps.write("./"))
.pipe(gulp.dest("./dist"));
}
if (watch) {
bundler.on("update", function() {
console.log("-> bundling...");
rebundle();
});
rebundle();
} else {
rebundle().pipe(exit());
}
}
function watch() {
return compile(true);
}
gulp.task("build", function() {
return new Promise(function(resolve, reject) {
compile();
resolve();
});
});
gulp.task("watch", function() {
return new Promise(function(resolve, reject) {
watch();
resolve();
});
});
gulp.task("doc", function(cb) {
return new Promise(function(resolve, reject) {
var config = require("./jsdocConfig.json");
gulp
.src(["README.md", "./src/*.js"], {
read: false
})
.pipe(jsdoc(config, cb));
resolve();
});
});
gulp.task("default", gulp.series(gulp.parallel("build", "doc")));