-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
452 lines (416 loc) · 12.6 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
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
'use strict';
const { src, dest, watch, series } = require('gulp');
const log = require('fancy-log');
const colors = require('ansi-colors');
const browserSync = require('browser-sync').create();
const sass = require('gulp-sass')(require('sass'));
const bourbon = require('node-bourbon').includePaths;
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const del = require('del');
const panini = require('panini');
const uglify = require('gulp-uglify-es').default;
const sourcemaps = require('gulp-sourcemaps');
const imagemin = require('gulp-imagemin');
const prettyHtml = require('gulp-pretty-html');
const sassLint = require('gulp-sass-lint');
const htmllint = require('gulp-htmllint');
const jshint = require('gulp-jshint');
const newer = require('gulp-newer');
const autoprefixer = require('gulp-autoprefixer');
const accessibility = require('gulp-accessibility');
const babel = require('gulp-babel');
const nodepath = 'node_modules/';
const assetspath = 'assets/';
const fs = require('fs');
const webpack = require('webpack-stream');
const named = require('vinyl-named')
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin');
// File paths
const files = {
scssPath: 'app/scss/**/*.scss',
jsPath: 'app/js/**/*.js'
}
// ------------ SETUP TASKS -------------
// Copy Bulma filed into Bulma development folder
function setupBulma() {
console.log('---------------COPYING BULMA FILES---------------');
return src([nodepath + 'bulma/*.sass', nodepath + 'bulma/**/*.sass'])
.pipe(dest('src/assets/sass/'));
}
// ------------ DEVELOPMENT TASKS -------------
// COMPILE SCSS INTO CSS
function compileSCSS() {
console.log('---------------COMPILING SCSS---------------');
return src(['src/assets/scss/core.scss'])
.pipe(sass({
outputStyle: 'compressed',
sourceComments: 'map',
sourceMap: 'scss',
includePaths: bourbon
}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(dest('dist/assets/css'))
.pipe(browserSync.stream());
}
// USING PANINI, TEMPLATE, PAGE AND PARTIAL FILES ARE COMBINED TO FORM HTML MARKUP
function compileHTML() {
console.log('---------------COMPILING HTML WITH PANINI---------------');
panini.refresh();
return src('src/pages/**/*.html')
.pipe(panini({
root: 'src/pages/',
layouts: 'src/layouts/',
/*pageLayouts: {
//All pages inside src/pages/blog will use the blog.html layout
'blog': 'blog'
}*/
partials: 'src/partials/',
helpers: 'src/helpers/',
data: 'src/data/'
}))
.pipe(dest('dist'))
.pipe(browserSync.stream());
}
// COPY CUSTOM JS
function compileJS() {
console.log('---------------COMPILE CUSTOM JS---------------');
let webpackConfig = {
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
}
}
})
]
},
module:{
rules: [
{
use: {
loader: 'babel-loader'
}
}
]
}
}
return src([
'src/assets/js/main.js',
'src/assets/js/components/lightbox.js',
'src/assets/js/pages/feed.js',
'src/assets/js/pages/profile-friends.js',
'src/assets/js/pages/login.js',
'src/assets/js/components/compose.js',
'src/assets/js/components/autocompletes.js',
//'src/assets/js/components/webcam.js',
'src/assets/js/components/widgets.js',
'src/assets/js/components/elements.js',
//'src/assets/js/components/modal-uploader.js',
'src/assets/js/navigation/navbar-options.js',
'src/assets/js/touch.js',
//'src/assets/js/tour.js',
//'src/assets/js/pages/chat.js',
//'src/assets/js/pages/events.js',
//'src/assets/js/pages/explorer.js',
//'src/assets/js/pages/stories.js',
//'src/assets/js/pages/friends.js',
//'src/assets/js/pages/inbox.js',
//'src/assets/js/pages/landing.js',
//'src/assets/js/pages/news.js',
//'src/assets/js/pages/map.js',
'src/assets/js/pages/profile.js',
//'src/assets/js/pages/questions.js',
//'src/assets/js/pages/shop.js',
//'src/assets/js/pages/signup.js',
'src/assets/js/pages/signup-v2.js',
//'src/assets/js/pages/settings.js',
//'src/assets/js/pages/videos.js',
])
.pipe(named())
.pipe(webpack(webpackConfig))
.pipe(uglify())
.pipe(dest('dist/assets/js/'))
.pipe(browserSync.stream());
}
// RESET PANINI'S CACHE OF LAYOUTS AND PARTIALS
function resetPages(done) {
console.log('---------------CLEARING PANINI CACHE---------------');
panini.refresh();
done();
}
// SASS LINT
function scssLint() {
console.log('---------------SASS LINTING---------------');
return src('src/assets/scss/**/*.scss')
.pipe(sassLint({
configFile: '.scss-lint.yml'
}))
.pipe(sassLint.format())
.pipe(sassLint.failOnError());
}
// HTML LINTER
function htmlLint() {
console.log('---------------HTML LINTING---------------');
return src('dist/*.html')
.pipe(htmllint({}, htmllintReporter));
}
function htmllintReporter(filepath, issues) {
if (issues.length > 0) {
issues.forEach(function (issue) {
log(colors.cyan('[gulp-htmllint] ') + colors.white(filepath + ' [' + issue.line + ']: ') + colors.red('(' + issue.code + ') ' + issue.msg));
});
process.exitCode = 1;
} else {
console.log('---------------NO HTML LINT ERROR---------------');
}
}
// JS LINTER
function jsLint() {
return src('src/assets/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
}
// WATCH FILES
function watchFiles() {
watch('src/**/*.html', compileHTML);
watch(['src/assets/scss/**/*', 'src/assets/scss/**/*'], compileSCSS);
watch('src/assets/js/**/*.js', compileJS);
watch('src/assets/img/**/*', copyImages);
}
// BROWSER SYNC
function browserSyncInit(done) {
console.log('---------------BROWSER SYNC---------------');
browserSync.init({
server: './dist'
});
return done();
}
// ------------ OPTIMIZATION TASKS -------------
// COPIES AND MINIFY IMAGE TO DIST
function minifyImages() {
console.log('---------------OPTIMIZING IMAGES---------------');
return src('src/assets/img/**/*.+(png|jpg|jpeg|gif|svg|mp4|webm|ogg)')
.pipe(newer('dist/assets/img/'))
.pipe(imagemin([
imagemin.gifsicle({ optimizationLevel: 3, interlaced: true }),
imagemin.mozjpeg({ quality: 85 }),
imagemin.optipng({ optimizationLevel: 3 }),
imagemin.svgo()
], {
verbose: true
}))
.pipe(dest('dist/assets/img/'))
.pipe(browserSync.stream());
}
// COPIES IMAGE TO DIST
function copyImages() {
console.log('---------------OPTIMIZING IMAGES---------------');
return src('src/assets/img/**/*')
.pipe(newer('dist/assets/img/'))
.pipe(dest('dist/assets/img/'))
.pipe(browserSync.stream());
}
// PLACES FONT FILES IN THE DIST FOLDER
function copyFont() {
console.log('---------------COPYING FONTS INTO DIST FOLDER---------------');
return src([
'src/assets/font/**/*',
])
.pipe(dest('dist/assets/fonts'))
.pipe(browserSync.stream());
}
// PLACES DATA FILES IN THE DIST FOLDER
function copyData() {
console.log('---------------COPYING DATA INTO DIST FOLDER---------------');
return src([
'src/data/**/*',
])
.pipe(dest('dist/assets/data'))
.pipe(browserSync.stream());
}
// CONCATENATE JS PLUGINS
function concatPlugins() {
console.log('---------------CONCATENATE JS PLUGINS---------------');
return src([
nodepath + 'jquery/dist/jquery.min.js',
nodepath + 'feather-icons/dist/feather.min.js',
nodepath + 'lozad/dist/lozad.min.js',
nodepath + 'vivid-icons/dist/vivid-icons.min.js',
nodepath + 'slick-carousel/slick/slick.min.js',
nodepath + 'emojionearea/dist/emojionearea.min.js',
nodepath + 'webui-popover/dist/jquery.webui-popover.min.js',
nodepath + 'easy-autocomplete/dist/jquery.easy-autocomplete.min.js',
nodepath + 'dropzone/dist/min/dropzone.min.js',
nodepath + '@fengyuanchen/datepicker/dist/datepicker.min.js',
nodepath + 'izitoast/dist/js/iziToast.min.js',
nodepath + 'quill/dist/quill.min.js',
nodepath + 'croppie/croppie.min.js',
nodepath + 'cropperjs/dist/cropper.min.js',
nodepath + 'dropzone/dist/min/dropzone.min.js',
nodepath + 'modal-video/js/jquery-modal-video.min.js',
nodepath + 'plyr/dist/plyr.min.js',
nodepath + 'hammerjs/hammer.min.js',
nodepath + 'scrollreveal/dist/scrollreveal.min.js',
nodepath + 'hopscotch/dist/js/hopscotch.min.js',
nodepath + 'glider-js/glider.min.js',
//Additional static js assets
'src/assets/vendor/js/**/*.js',
])
.pipe(concat('app.js'))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(dest('dist/assets/js'))
.pipe(browserSync.stream());
}
// CONCATENATE CSS PLUGINS
function concatCssPlugins() {
console.log('---------------CONCATENATE CSS PLUGINS---------------');
return src([
//nodepath + 'slick-carousel/slick/slick.css',
//nodepath + 'slick-carousel/slick/slick-theme.css',
nodepath + 'emojionearea/dist/emojionearea.min.css',
nodepath + 'webui-popover/dist/jquery.webui-popover.min.css',
nodepath + 'easy-autocomplete/dist/easy-autocomplete.min.css',
nodepath + 'izitoast/dist/css/iziToast.min.css',
nodepath + 'quill/dist/quill.core.css',
nodepath + 'quill/dist/quill.bubble.css',
nodepath + 'croppie/croppie.css',
nodepath + 'plyr/dist/plyr.css',
nodepath + 'dropzone/dist/min/dropzone.min.css',
nodepath + 'cropperjs/dist/cropper.min.css',
nodepath + 'hopscotch/dist/css/hopscotch.min.css',
nodepath + 'glider-js/glider.min.css',
//Additional static css assets
'src/assets/vendor/css/**/*.css',
])
.pipe(sourcemaps.init())
.pipe(concat('app.css'))
.pipe(sourcemaps.write('./'))
.pipe(dest('dist/assets/css'))
.pipe(browserSync.stream());
}
// COPY JS VENDOR FILES
function jsVendor() {
console.log('---------------COPY JAVASCRIPT VENDOR FILES INTO DIST---------------');
return src([
'src/assets/vendor/js/*',
])
.pipe(dest('dist/assets/vendor/js'))
.pipe(browserSync.stream());
}
// COPY CSS VENDOR FILES
function cssVendor() {
console.log('---------------COPY CSS VENDOR FILES INTO DIST---------------');
return src([
'src/assets/vendor/css/*',
])
.pipe(dest('dist/assets/vendor/css'))
.pipe(browserSync.stream());
}
// PRETTIFY HTML FILES
function prettyHTML() {
console.log('---------------HTML PRETTIFY---------------');
return src('dist/*.html')
.pipe(prettyHtml({
indent_size: 4,
indent_char: ' ',
unformatted: ['code', 'pre', 'em', 'strong', 'span', 'i', 'b', 'br']
}))
.pipe(dest('dist'));
}
// DELETE DIST FOLDER
function cleanDist(done) {
console.log('---------------REMOVING OLD FILES FROM DIST---------------');
del.sync('dist');
return done();
}
// ACCESSIBILITY CHECK
function HTMLAccessibility() {
return src('dist/*.html')
.pipe(accessibility({
force: true
}))
.on('error', console.log)
.pipe(accessibility.report({
reportType: 'txt'
}))
.pipe(rename({
extname: '.txt'
}))
.pipe(dest('accessibility-reports'));
}
function writeConfigs(done) {
let babelRc = {
presets: ['env'],
plugins: [['inline-replace-variables', {
__API_HOST__: process.env.API_HOST ? process.env.API_HOST : 'http://localhost:8080',
__BUCKET_PATH__: process.env.BUCKET_PATH ? process.env.BUCKET_PATH : ''
}]]
}
let dataJson = {
bucket_path: '',
cache_bust: new Date().valueOf()
};
if (process.env.PROJECT) {
babelRc.plugins = [['inline-replace-variables', {
__API_HOST__: process.env.APP_HOST,
__BUCKET_PATH__: `/frontend-${process.env.PROJECT}`
}]]
dataJson.bucket_path = `/frontend-${process.env.PROJECT}/`;
}
fs.writeFileSync('.babelrc', JSON.stringify(babelRc));
fs.writeFileSync('src/data/deploy.json', JSON.stringify(dataJson));
return done();
}
// RUN ALL LINTERS
exports.linters = series(htmlLint, scssLint, jsLint);
// RUN ACCESSIILITY CHECK
exports.accessibility = HTMLAccessibility;
//SETUP
exports.setup = series(setupBulma);
// DEV
exports.dev = series(
cleanDist,
writeConfigs,
copyFont,
copyData,
jsVendor,
cssVendor,
copyImages,
compileHTML,
concatPlugins,
concatCssPlugins,
compileJS,
resetPages,
prettyHTML,
compileSCSS,
browserSyncInit,
watchFiles
);
// BUILD
exports.build = series(
cleanDist,
writeConfigs,
copyFont,
copyData,
jsVendor,
cssVendor,
compileHTML,
concatPlugins,
concatCssPlugins,
compileJS,
minifyImages,
compileSCSS
);
exports.compile = series(
cleanDist,
writeConfigs,
compileJS
)