-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathgulpfile.js
More file actions
302 lines (265 loc) · 7.02 KB
/
gulpfile.js
File metadata and controls
302 lines (265 loc) · 7.02 KB
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
Copyright 2020 Appvia Ltd <info@appvia.io>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
"use strict";
// Load plugins
import nodemon from 'nodemon';
import babel from 'gulp-babel';
import cleanCSS from "gulp-clean-css";
import { deleteAsync } from 'del';
import { exec } from 'child_process';
import { src, dest, watch, series, parallel } from "gulp";
import header from "gulp-header";
import plumber from "gulp-plumber";
import rename from "gulp-rename";
import gulpSass from 'gulp-sass';
import * as s from 'sass';
const sass = gulpSass(s);
import uglify from "gulp-uglify";
// Load package.json for banner
import pkg from './package.json' assert { type: "json" };
// Set the banner content
const banner = ['/*!\n',
' * <%= pkg.title %> v<%= pkg.version %> (<%= pkg.homepage %>)\n',
' * Copyright 2019-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
' * Licensed under <%= pkg.license %> (https://github.com/appvia/<%= pkg.name %>/blob/master/LICENSE)\n',
' */\n',
'\n'
].join('');
// Clean vendor
function clean() {
return new Promise((done) => {
deleteAsync('./compiled/vendor/');
done();
});
}
// ==== vendor ====
// Risk Rules Config
function riskRules() {
return new Promise((done) => {
src('../config/rules.yaml')
.pipe(dest('./compiled/data/config'))
.on('end', done);
});
}
// Bootstrap JS
function bootstrapJS() {
return new Promise((done) => {
src('./node_modules/bootstrap/dist/js/*')
.pipe(dest('./compiled/vendor/bootstrap/js'))
.on('end', done);
});
}
export { bootstrapJS };
// Bootstrap SCSS
function bootstrapSCSS() {
return new Promise((done) => {
src('./node_modules/bootstrap/scss/**/*')
.pipe(dest('./compiled/vendor/bootstrap/scss'))
.on('end', done);
});
}
export { bootstrapSCSS };
// Bootstrap Treeview JS/CSS
function bootstrapTreeview() {
return new Promise((done) => {
src('./node_modules/patternfly-bootstrap-treeview/dist/**/*')
.pipe(dest('./compiled/vendor/bootstrap-treeview'))
.on('end', done);
});
}
// Prism JS
function prismjsJS() {
return new Promise((done) => {
src('./node_modules/prismjs/components/**/*')
.pipe(dest('./compiled/vendor/prismjs/js'))
.on('end', done);
});
}
// Prism CSS
function prismjsCSS() {
return new Promise((done) => {
src('./node_modules/prismjs/themes/**/*')
.pipe(dest('./compiled/vendor/prismjs/css'))
.on('end', done);
});
}
// ChartJS
function chartJS() {
return new Promise((done) => {
src('./node_modules/chart.js/dist/*.js')
.pipe(dest('./compiled/vendor/chart.js'))
.on('end', done);
});
}
// Font Awesome
function fontAwesome() {
return new Promise((done) => {
src('./node_modules/@fortawesome/**/*')
.pipe(dest('./compiled/vendor'))
.on('end', done);
});
}
// jQuery Easing
function jqueryEasing() {
return new Promise((done) => {
src('./node_modules/jquery.easing/*.js')
.pipe(dest('./compiled/vendor/jquery-easing'))
.on('end', done);
});
}
// jQuery
function jquery() {
return new Promise((done) => {
src([
'./node_modules/jquery/dist/*',
'!./node_modules/jquery/dist/core.js'
])
.pipe(dest('./compiled/vendor/jquery'))
.on('end', done);
});
}
// Stickyfill
function stickyfillJS() {
return new Promise((done) => {
src('./node_modules/stickyfilljs/dist/stickyfill.min.js')
.pipe(dest('./compiled/vendor/stickyfilljs'))
.on('end', done);
});
}
// vis-network
function visNetworkJS() {
return new Promise((done) => {
src('./node_modules/vis-network/standalone/umd/*')
.pipe(dest('./compiled/vendor/vis-network'))
.on('end', done);
});
}
// vue.js
function vueJS() {
return new Promise((done) => {
src('./node_modules/vue/dist/vue.global.*')
.pipe(dest('./compiled/vendor/vue'))
.on('end', done);
});
}
// Bring third party dependencies from node_modules into vendor directory
function modules() {
return Promise.all([
riskRules(), // RISK RULES CONFIG
bootstrapJS(),
bootstrapSCSS(),
bootstrapTreeview(),
prismjsJS(),
prismjsCSS(),
chartJS(),
fontAwesome(),
jquery(),
jqueryEasing(),
stickyfillJS(),
visNetworkJS(),
vueJS()
]);
}
// CSS task
function css() {
return src([
"./src/scss/**/*.scss"
])
.pipe(plumber({
errorHandler: function (err) {
console.error('Error!', err.message); // Log errors
this.emit('end'); // Prevent Gulp from crashing
}
}))
.pipe(sass({
outputStyle: "expanded",
includePaths: "./node_modules",
}))
.on("error", sass.logError)
.pipe(header(banner, {
pkg: pkg
}))
.pipe(dest("./compiled/css"))
.pipe(rename({
suffix: ".min"
}))
.pipe(cleanCSS())
.pipe(dest("./compiled/css"))
}
// JS task
function js() {
return src([
'./src/js/*.js',
'!./src/js/*.min.js',
])
.pipe(plumber())
.pipe(babel({
presets: ['@babel/preset-env']
}))
.pipe(uglify())
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(dest('./compiled/js'));
}
// Watch files
function watchFiles(done) {
async () => {
watch("./src/scss/**/*", css);
watch(["./src/js/**/*", "!./src/js/**/*.min.js"], js);
watch("./src/html/**/*.html", compileHtml);
}
done();
}
// Compile HTML
function compileHtml(done) {
return new Promise((done) => {
return exec('bundle exec jekyll build -s src/html -d ./tmp && cp ./tmp/*.html ./compiled && rm -rf ./tmp', function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
done();
});
});
}
function develop(done) {
var stream = nodemon({
script: './dashboard.js',
watch: ['./src'], // watch source changes
ext: 'html js css yaml json', // watched files extensions
done: done
})
stream
.on('restart', function () {
// rebuild js, css and html
js();
css();
compileHtml();
console.log('---------')
console.log('- Changes detected and application restarted! Refresh your browser to see changes.')
console.log('---------')
})
.on('crash', function () {
console.error('Application has crashed!\n')
stream.emit('restart', 10) // restart the server in 10 seconds
})
}
// Define complex tasks
const vendor = series(clean, modules);
const build = series(vendor, parallel(css, js));
const release = series(build, compileHtml);
const watcher = series(release, develop);
export { clean, css, js, vendor, build, compileHtml, watcher as watch, release };
export default build;