forked from robskr/gameforest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
379 lines (343 loc) · 13.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
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
/**
* ---------------------------------------------------------------------------------------
* Gameforest Bootstrap Gaming Theme
* Copyright (c) 2018 yakuthemes.com (https://yakuthemes.com)
*
* @link https://themeforest.net/item/gameforest-responsive-gaming-html-theme/5007730
* @version 5.0.3
* @license https://www.gnu.org/licenses/gpl-3.0.html GPLv3 License
* ---------------------------------------------------------------------------------------
*/
const gulp = require('gulp')
const browserSync = require('browser-sync')
const stylelint = require('gulp-stylelint')
const sass = require('gulp-sass')
const postcss = require('gulp-postcss')
const sourcemaps = require('gulp-sourcemaps')
const iconfont = require('gulp-iconfont')
const imagemin = require('gulp-image')
const iconfontcss = require('gulp-iconfont-css')
const rollup = require('rollup-stream')
const uglify = require('gulp-uglify-es').default
const source = require('vinyl-source-stream')
const eslint = require('gulp-eslint')
const concat = require('gulp-concat')
const fs = require('fs')
const twig = require('gulp-twig')
const prettify = require('gulp-jsbeautifier')
const merge = require('gulp-merge-json')
const rename = require('gulp-rename')
const changed = require('gulp-changed')
const clean = require('gulp-clean')
const sizereport = require('gulp-sizereport')
const cleancss = require('gulp-clean-css');
/**
* ------------------------------------------------------------------------
* PATHS
* ------------------------------------------------------------------------
*/
const path = {
src: {
scss: './src/sass/**/*.scss',
js: './src/js/**/*.js',
svg: './src/svg/*.svg',
json: './src/json/*.json',
img: './src/img/*',
twig: './src/twig/*.twig',
views: './src/twig/views/*.twig'
},
dist: {
css: './dist/css',
js: './dist/js',
svg: './dist/fonts',
icon: './src/fonts',
json: './dist/js',
img: './dist/img',
html: './dist',
plugins: './dist/plugins/*'
}
}
/**
* ------------------------------------------------------------------------
* STYLESHEET
* ------------------------------------------------------------------------
*/
function scss() {
return gulp.src(path.src.scss)
.pipe(stylelint({
failAfterError: false,
reporters: [
{formatter: 'string', console: true}
],
debug: true
}))
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: './node_modules/',
outputStyle: 'expanded'
}))
.pipe(postcss())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(path.dist.css))
}
function scssmin() {
return gulp.src(`${path.dist.css}/theme.css`)
.pipe(cleancss())
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(path.dist.css))
}
/**
* ------------------------------------------------------------------------
* JAVASCRIPT
* ------------------------------------------------------------------------
*/
function lint() {
return gulp.src(path.src.js)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
}
function babel() {
return rollup('./rollup.config.js')
.pipe(source('theme.js'))
.pipe(gulp.dest(path.dist.js))
}
function minify() {
return gulp.src('./dist/js/theme.js')
.pipe(concat('theme.min.js'))
.pipe(uglify())
.pipe(gulp.dest(path.dist.js))
}
function bundle() {
return gulp.src([
'./node_modules/popper.js/dist/umd/popper.min.js',
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/bootstrap/dist/js/bootstrap.min.js',
'./node_modules/owl.carousel/dist/owl.carousel.min.js',
'./node_modules/jquery-sticky/jquery.sticky.js'
])
.pipe(concat('vendor.js'))
.pipe(gulp.dest(path.dist.js))
.pipe(concat('vendor.js'))
.pipe(uglify())
.pipe(gulp.dest(path.dist.js))
}
/**
* ------------------------------------------------------------------------
* IMAGES
* ------------------------------------------------------------------------
*/
function image() {
return gulp.src(path.src.img)
.pipe(changed(path.dist.img))
.pipe(imagemin({
mozjpeg: ['-quality', 90]
}))
.pipe(gulp.dest(path.dist.img))
.pipe(browserSync.stream())
}
/**
* ------------------------------------------------------------------------
* MERGE JSON
* ------------------------------------------------------------------------
*/
function json() {
return gulp.src(path.src.json)
.pipe(merge({
fileName: 'theme.json',
startObj: { env: process.env.NODE_ENV },
}))
.pipe(gulp.dest(path.dist.json))
}
/**
* ------------------------------------------------------------------------
* BUILD HTML
* ------------------------------------------------------------------------
*/
function html() {
return gulp.src(path.src.twig)
.pipe(changed(path.dist.html, {
extension: '.html'
}))
.pipe(twig({
base: './src/twig/views',
data: JSON.parse(fs.readFileSync('./dist/js/theme.json'))
}))
.pipe(prettify({
unformatted: ['span', 'i'],
extra_liners: ' ',
max_preserve_newlines: 0,
eol: process.env.NODE_ENV === 'host' ? '' : '\n',
indent_size: process.env.NODE_ENV === 'host' ? '' : 4,
indent_char: process.env.NODE_ENV === 'host' ? '' : ' ',
indent_with_tabs: process.env.NODE_ENV === 'host' ? false : true
}))
.pipe(gulp.dest(path.dist.html))
.pipe(browserSync.stream())
}
function compile() {
return gulp.src(path.src.twig)
.pipe(twig({
base: './src/twig/views',
data: JSON.parse(fs.readFileSync('./dist/js/theme.json'))
}))
.pipe(prettify({
unformatted: ['span', 'i'],
extra_liners: ' ',
max_preserve_newlines: 0,
eol: process.env.NODE_ENV === 'host' ? '\n' : '\n',
indent_size: process.env.NODE_ENV === 'host' ? '' : 4,
indent_char: process.env.NODE_ENV === 'host' ? '' : ' ',
indent_with_tabs: process.env.NODE_ENV === 'host' ? false : true
}))
.pipe(gulp.dest(path.dist.html))
}
/**
* ------------------------------------------------------------------------
* GENERATE ICON
* ------------------------------------------------------------------------
*/
function svg() {
return gulp.src(path.src.svg)
.pipe(iconfontcss({
fontName: 'nucleo',
path: './src/fonts/icons.sass',
targetPath: '../sass/_icons.scss',
fontPath: '../fonts/',
cssClass: 'ya'
}))
.pipe(iconfont({
centerHorizontally: true,
fontName: 'nucleo',
normalize: true,
fontHeight: 1024,
descent: 127,
formats: ['ttf', 'eot', 'woff', 'svg']
}))
.pipe(gulp.dest(path.dist.icon))
}
function svgcopy() {
return gulp.src(['./src/fonts/*', '!./src/fonts/icons.sass']).pipe(gulp.dest(path.dist.svg))
}
/**
* ------------------------------------------------------------------------
* LOCALHOST
* ------------------------------------------------------------------------
*/
function browser() {
return browserSync.init({
files : [
`${path.dist.css}/theme.css`,
`${path.dist.css}/theme.min.css`,
`${path.dist.js}/theme.bundle.min.js`,
`${path.dist.html}/*.html`
],
notify: false,
server: {
baseDir: './',
routes: {
'/': 'dist'
}
}
})
}
/**
* ------------------------------------------------------------------------
* REPORT
* ------------------------------------------------------------------------
*/
function report() {
return gulp.src(['./dist/css/*.css', './dist/js/*'])
.pipe(sizereport())
}
function reportcss() {
return gulp.src('./dist/css/*.css')
.pipe(sizereport())
}
function reportjs() {
return gulp.src('./dist/js/*')
.pipe(sizereport({
'theme.bundle.min.js': {
maxSize: 89088
},
'theme.bundle.js': {
maxSize: 126976
}
}))
}
/**
* ------------------------------------------------------------------------
* PLUGINS
* ------------------------------------------------------------------------
*/
function clear() {
return gulp.src(path.dist.plugins, {read: false})
.pipe(clean())
}
function bootstrap() { return gulp.src('./node_modules/bootstrap/dist/**/*').pipe(gulp.dest('./dist/plugins/bootstrap')) }
function jquery() { return gulp.src('./node_modules/jquery/dist/**/*').pipe(gulp.dest('./dist/plugins/jquery')) }
function popper() { return gulp.src('./node_modules/popper.js/dist/umd/**/*').pipe(gulp.dest('./dist/plugins/popper')) }
function fontawesome() { return gulp.src(['node_modules/@fortawesome/fontawesome-free/*', 'node_modules/@fortawesome/fontawesome-free/*/*', '!node_modules/@fortawesome/fontawesome-free/js', '!node_modules/@fortawesome/fontawesome-free/js/*', '!node_modules/@fortawesome/fontawesome-free/svgs', '!node_modules/@fortawesome/fontawesome-free/svgs/*', '!node_modules/@fortawesome/fontawesome-free/sprites', '!node_modules/@fortawesome/fontawesome-free/sprites/*', '!node_modules/@fortawesome/fontawesome-free/less', '!node_modules/@fortawesome/fontawesome-free/less/*']).pipe(gulp.dest('./dist/plugins/fontawesome')) }
function ckeditor() { return gulp.src('./node_modules/@ckeditor/ckeditor5-build-classic/build/**/*').pipe(gulp.dest('./dist/plugins/ckeditor')) }
function easypiechart() { return gulp.src('./node_modules/easy-pie-chart/dist/**/*').pipe(gulp.dest('./dist/plugins/easypiechart')) }
function bootstrap_select() { return gulp.src('./node_modules/bootstrap-select/dist/**/*').pipe(gulp.dest('./dist/plugins/bootstrap-select')) }
function flatpickr() { return gulp.src('./node_modules/flatpickr/dist/**/*').pipe(gulp.dest('./dist/plugins/flatpickr')) }
function sticky() { return gulp.src('./node_modules/jquery-sticky/**/*').pipe(gulp.dest('./dist/plugins/jquery-sticky')) }
function datatables() { return gulp.src(['./node_modules/datatables.net-bs4/**/*', './node_modules/datatables.net/**/*']).pipe(gulp.dest('./dist/plugins/datatables')) }
function morris() { return gulp.src(['./node_modules/morris.js/morris.css', './node_modules/morris.js/morris.js', './node_modules/morris.js/morris.min.js']).pipe(gulp.dest('./dist/plugins/morris')) }
function raphael() { return gulp.src(['./node_modules/raphael/raphael.js', './node_modules/raphael/raphael.min.js']).pipe(gulp.dest('./dist/plugins/raphael')) }
function parallax() { return gulp.src('./node_modules/jquery-parallax.js/*').pipe(gulp.dest('./dist/plugins/parallax')) }
function countdown() { return gulp.src('./node_modules/jquery-countdown/dist/*').pipe(gulp.dest('./dist/plugins/jquery-countdown')) }
function nouislider() { return gulp.src('./node_modules/nouislider/distribute/*').pipe(gulp.dest('./dist/plugins/nouislider')) }
function lazysizes() { return gulp.src(['./node_modules/lazysizes/lazysizes.js']).pipe(gulp.dest('./dist/plugins/lazysizes')) }
/**
* ------------------------------------------------------------------------
* BUILD TASK
* ------------------------------------------------------------------------
*/
const build = {
host: gulp.parallel(watch, browser),
sass: gulp.series(scss, scssmin, reportcss),
image: image,
js: gulp.series(babel, minify, lint, reportjs),
bundle: bundle,
html: html,
compile: compile,
report: report,
json: gulp.series(json, compile),
icon: gulp.series(svg, svgcopy),
plugins: gulp.series(clear, bootstrap, jquery, popper, fontawesome, ckeditor, easypiechart, bootstrap_select, flatpickr, sticky, datatables, morris, raphael, parallax, countdown, nouislider, lazysizes)
}
/**
* ------------------------------------------------------------------------
* WATCH FILES
* ------------------------------------------------------------------------
*/
function watch() {
gulp.watch(path.src.twig, {events: ['change', 'unlink']}, build.html)
gulp.watch(path.src.views, {events: ['change', 'unlink']}, build.compile)
gulp.watch(path.src.json, {events: ['change', 'unlink']}, build.json)
gulp.watch(path.src.scss, {events: ['change', 'unlink']}, build.sass)
gulp.watch(path.src.js, {events: ['change', 'unlink']}, build.js)
gulp.watch(path.src.img, build.image)
gulp.watch(path.src.svg, build.icon)
}
/**
* ------------------------------------------------------------------------
* GULP TASKS
* ------------------------------------------------------------------------
*/
gulp.task('icon', build.icon)
gulp.task('html', build.html)
gulp.task('report', build.report)
gulp.task('compile', build.compile)
gulp.task('sass', build.sass)
gulp.task('js', build.js)
gulp.task('bundle', build.bundle)
gulp.task('json', build.json)
gulp.task('image', build.image)
gulp.task('plugins', build.plugins)
gulp.task('host', build.host)
gulp.task('default', gulp.series(build.js, build.bundle, build.icon, build.sass, build.image, build.json))