-
Notifications
You must be signed in to change notification settings - Fork 16
/
gulpfile.js
117 lines (100 loc) · 2.7 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
"use strict";
const { src, dest, series, parallel, watch } = require("gulp");
const buffer = require("gulp-buffer");
const browserify = require("browserify");
const concat = require("gulp-concat");
const connect = require("gulp-connect");
const eslint = require("gulp-eslint7");
const header = require("gulp-header");
const log = require("gulplog");
const postcss = require("gulp-postcss");
const sourcemaps = require("gulp-sourcemaps");
const stylelint = require("gulp-stylelint");
const tap = require("gulp-tap");
const terser = require("gulp-terser");
const output =
process.argv.indexOf("--output") != -1
? process.argv[process.argv.indexOf("--output") + 1]
: "build/converted-asciidoc";
function info(cb) {
log.info("Writing to " + output);
cb();
}
function css() {
return src("src/main/css/site.css")
.pipe(
stylelint({
failAfterError: true,
reporters: [{ formatter: "string", console: true }],
})
)
.pipe(sourcemaps.init())
.pipe(postcss())
.pipe(
/* MPL 2.0 requirement */
header(
"/*\n\nSource Available at https://github.com/spring-io/asciidoctor-spring-backend */\n\n\n"
)
)
.pipe(sourcemaps.write("./"))
.pipe(dest(output + "/css"))
.pipe(connect.reload());
}
function fontawesomeCss() {
return src("node_modules/fontawesome-4.7/css/font-awesome.css").pipe(dest(output + "/css"));
}
function fontawesomeFonts() {
return src("node_modules/fontawesome-4.7/fonts/*").pipe(dest(output + "/fonts"));
}
function img() {
return src("src/main/img/*").pipe(dest(output + "/img"));
}
function jsSetup() {
return jsFolder("setup");
}
function jsSite() {
return jsFolder("site");
}
function jsFolder(name) {
return src("src/main/js/" + name + "/*.js", { base: 'src/main/js' })
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
.pipe(tapBrowserify())
.pipe(buffer())
.pipe(initSourcemaps())
.pipe(terser())
.pipe(concat("js/" + name + ".js"))
.pipe(sourcemaps.write("./"))
.pipe(dest(output))
.pipe(connect.reload());
}
function tapBrowserify() {
return tap(function (file) {
file.contents = browserify(file.path, {
debug: true,
})
.plugin("browser-pack-flat/plugin")
.bundle();
});
}
function initSourcemaps() {
return sourcemaps.init({
loadMaps: true,
});
}
function webServer(cb) {
connect.server({
root: output,
livereload: true,
});
cb();
}
function watchFiles(cb) {
watch("src/main/**", build);
cb();
}
const build = series(info, css, fontawesomeCss, fontawesomeFonts, img, jsSetup, jsSite);
exports.default = build;
exports.build = build;
exports.dev = series(build, parallel(webServer, watchFiles));