This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.babel.js
98 lines (84 loc) · 2.29 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
import del from "del";
import electronConnect from "electron-connect";
import gulp from "gulp";
import runSequence from "run-sequence";
import buffer from "vinyl-buffer";
import plugins from "gulp-load-plugins";
let $ = plugins();
const DEBUG = process.env.NODE_ENV !== "production";
const SRC_DIR = "src/";
const DIST_DIR = "dist/";
gulp.task("dist", callback => {
return runSequence.use(gulp)(
"clean",
"copy",
["compile:js", "compile:html"],
callback
);
});
gulp.task("clean", () => {
return del([
DIST_DIR + "**/*"
]);
});
gulp.task("copy", () => {
let target = [
SRC_DIR + "css/**/*",
SRC_DIR + "fonts/**/*",
SRC_DIR + "images/**/*"
];
return gulp.src(target, { base: SRC_DIR })
.pipe(gulp.dest(DIST_DIR));
});
gulp.task("compile:html", () => {
return gulp.src([SRC_DIR + "*.html"])
.pipe($.if(!DEBUG, $.useref()))
.pipe(gulp.dest(DIST_DIR));
});
let watching = false;
gulp.task("enable-watch-mode", () => {
watching = true;
});
gulp.task("compile:main", () => {
gulp.src(SRC_DIR + "main.js")
.pipe($.plumber())
.pipe($.babel())
.pipe($.if(DEBUG, $.uglify({ compress: true })))
.pipe(gulp.dest(DIST_DIR));
});
gulp.task("compile:js", $.watchify((watchify) => {
["index.js"].forEach((f) => {
gulp.src(SRC_DIR + f)
.pipe($.plumber())
.pipe(watchify({
watch: watching,
debug: DEBUG,
transform: ["babelify", "envify"]
}))
.pipe(buffer())
.pipe($.sourcemaps.init({ loadMaps: true }))
.pipe($.if(DEBUG, $.uglify({ compress: true })))
.pipe($.if(DEBUG, $.sourcemaps.write()))
.pipe(gulp.dest(DIST_DIR));
});
}));
gulp.task("watchify",
["enable-watch-mode", "compile:js", "compile:main", "copy", "compile:html"]);
gulp.task("watch", ["watchify"], function () {
gulp.watch(SRC_DIR + "**/*.html", ["copy", "compile:html"]);
gulp.watch(SRC_DIR + "**/*.css", ["copy"]);
});
gulp.task("server", ["watch"], () => {
let electronServer = electronConnect.server.create();
electronServer.start();
gulp.watch([
DIST_DIR + "**/*.html",
DIST_DIR + "**/*.js"
], electronServer.reload);
});
gulp.task("eslint", () => {
return gulp.src([SRC_DIR + "**/*.js"])
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
});