This repository has been archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
190 lines (157 loc) · 4.16 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
const { dest, series, src, watch } = require("gulp");
const autoprefixer = require("autoprefixer");
const browserSync = require("browser-sync").create();
const cssnano = require("gulp-cssnano");
const del = require("del");
const eslint = require("gulp-eslint");
const header = require("gulp-header");
const postcss = require("gulp-postcss");
const pump = require("pump");
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const uglify = require("gulp-uglify");
const package = require("./package.json");
const banner = `/*!
*
* Copyright (C) 2018 The Trustees of Indiana University
* SPDX-License-Identifier: BSD-3-Clause
* ${package.name} - @version ${package.version}
*/
`;
// Development server
function watchFiles(callback) {
browserSync.init({
server: {
baseDir: "./docs"
}
});
watch("src/sass/**/*.scss", compileSass);
watch("src/js/**/*.js",series(lintJSWatch, compileJS));
watch("src/index.html", compileHTML);
callback();
}
// Development Server -- No Browser
function headless(callback) {
browserSync.init({
server: {
baseDir: "./docs"
},
open: false
});
watch("src/sass/**/*.scss",{ ignoreInitial: false }, compileSass);
watch("src/js/**/*.js", { ignoreInitial: false }, series(lintJSWatch, compileJS));
watch("src/index.html", { ignoreInitial: false }, compileHTML);
callback();
}
function compileHTML() {
return src("src/index.html")
.pipe(dest("docs/"))
.pipe(browserSync.stream());
}
function compileSass() {
return src("src/sass/**/*.scss")
.pipe(sass({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(dest("docs/css/"))
.pipe(browserSync.stream());
}
function releaseSass() {
return src("src/sass/**/*.scss")
.pipe(sass({ outputStyle: "expanded" }).on("error", sass.logError))
.pipe(dest("dist/css/"));
}
function cleanCSS() {
return del(["dist/css/**/*"]);
}
function minifyCSS() {
return src("dist/css/" + package.name + ".css")
.pipe(cssnano())
.pipe(
rename({
suffix: ".min"
})
)
.pipe(dest("dist/css/"));
}
function prefixCSS() {
return src("dist/css/" + package.name + ".css")
.pipe(postcss([autoprefixer({ browsers: ["last 2 versions"] })]))
.pipe(dest("dist/css/"));
}
function headerCSS(callback) {
src("dist/css/" + package.name + ".css")
.pipe(header(banner, { package: package }))
.pipe(dest("dist/css/"));
src("dist/css/" + package.name + ".min.css")
.pipe(header(banner, { package: package }))
.pipe(dest("dist/css/"));
callback();
}
// This task is used to watch during development only.
function lintJSBuild() {
return src(["src/js/**/*.js", "!node_modules/**"])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
}
function lintJSWatch() {
return src(["src/js/**/*.js", "!node_modules/**"])
.pipe(eslint())
.pipe(eslint.format());
}
function compileJS() {
return src("src/js/**/*.js")
.pipe(dest("docs/js/"))
.pipe(browserSync.stream());
}
function cleanJS() {
return del(["dist/js/**/*"]);
}
function copyJS() {
return src("src/js/**/*.js").pipe(dest("dist/js/"));
}
function copyJS() {
return src("src/js/**/*.js").pipe(dest("dist/js/"));
}
function minifyJS(done) {
pump(
[
src("dist/js/" + package.name + ".js"),
uglify(),
rename({ suffix: ".min" }),
dest("dist/js")
],
done
);
}
function headerJS(callback) {
src("dist/js/" + package.name + ".js")
.pipe(header(banner, { package: package }))
.pipe(dest("dist/js/"));
src("dist/js/" + package.name + ".min.js")
.pipe(header(banner, { package: package }))
.pipe(dest("dist/js/"));
callback();
}
// Deletes everything in the dist/js and dist/css folders
exports.clean = series(
cleanCSS,
cleanJS
);
// Run release tasks
exports.release = series(
cleanCSS,
releaseSass,
prefixCSS,
minifyCSS,
headerCSS,
lintJSBuild,
cleanJS,
copyJS,
minifyJS,
headerJS
);
// Headless dev server
exports.headless = headless;
exports.buildDocs = series(compileHTML, compileSass, lintJSBuild, compileJS);
// Default dev server
exports.default = series(compileHTML, compileSass, lintJSWatch, compileJS, watchFiles);