-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
171 lines (151 loc) · 4.38 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
const gulp = require('gulp')
const browserSync = require('browser-sync')
const concat = require('gulp-concat')
const plumber = require('gulp-plumber')
const uglify = require('gulp-uglify')
const babel = require('gulp-babel')
const sass = require('gulp-sass')
const runSequence = require('run-sequence')
const { exec } = require('child_process')
const svgSymbols = require('gulp-svg-symbols')
const svgMin = require('gulp-svgmin')
const rename = require('gulp-rename')
const imagemin = require('gulp-imagemin')
const fs = require('fs-extra')
/**
* Use hexo to generate files
* We had some problems with the hexo's API so now
* we're going with child_process's spawn
*/
gulp.task('hexo', function (cb) {
const command = 'hexo generate'
exec(command, (err, stdout, stderr) => {
if (err) {
return cb(err)
}
console.log(stdout)
console.log(stderr)
browserSync.reload()
cb()
})
})
/**
* Process JS files
* Match files from the theme folder
* concat them, transpile to ES5
* and uglify them
*/
gulp.task('process-js', function () {
return gulp
.src([
'./themes/backendbrasil/assets/*.js',
'./themes/backendbrasil/assets/**/*.js'
])
.pipe(plumber())
.pipe(concat('all.min.js'))
.pipe(babel({
presets: ['@babel/env']
}))
.pipe(uglify())
.pipe(gulp.dest('public'))
})
gulp.task('js', ['process-js'], function (cb) {
browserSync.reload()
cb()
})
/**
* Process main file from the theme folder
*/
gulp.task('process-css', function () {
return gulp
.src([
'./themes/backendbrasil/assets/main.scss',
'./public/css/*.css'
])
.pipe(plumber())
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(gulp.dest('public'))
})
gulp.task('css', ['process-css'], function (cb) {
browserSync.reload()
cb()
})
gulp.task('favicon', function () {
const exts = '{jpg,gif,png,svg,ico}';
return gulp
.src([
`./themes/backendbrasil/assets/img/favicon/*.${exts}`
])
.pipe(plumber())
.pipe(gulp.dest('./public/img/favicon/'))
})
gulp.task('images', function () {
const exts = '{jpg,gif,png,svg}';
return gulp
.src([
`./themes/backendbrasil/assets/*.${exts}`,
`./themes/backendbrasil/assets/img/*.${exts}`
])
.pipe(plumber())
.pipe(imagemin())
.pipe(gulp.dest('./public/img/'))
})
gulp.task('icons', function () {
return gulp.src('./themes/backendbrasil/assets/icons/*.svg')
.pipe(plumber())
.pipe(svgMin({
plugins: [
{ removeViewBox: false },
{ removeAttrs: { attrs: 'fill' } }
]
}))
.pipe(svgSymbols({
templates: ['default-svg'],
svgAttrs: {
class: 'svg-icon-lib',
'aria-hidden': true
}
}))
.pipe(rename('icons.hbs'))
.pipe(gulp.dest('./themes/backendbrasil/layout/partials'))
})
gulp.task('server', function () {
browserSync.init({
server: {
baseDir: './public'
}
})
// Handlebars Files
gulp.watch('./themes/backendbrasil/layout/*.hbs', ['hexo'])
gulp.watch('./themes/backendbrasil/layout/**/*.hbs', ['hexo'])
gulp.watch('./themes/backendbrasil/source/*', ['hexo'])
gulp.watch('./themes/backendbrasil/source/**/*', ['hexo'])
gulp.watch('./themes/backendbrasil/helper/*', ['hexo'])
gulp.watch('./themes/backendbrasil/languages/*', ['hexo'])
gulp.watch('./themes/backendbrasil/*.yml', ['hexo'])
gulp.watch('./source/*', ['hexo'])
gulp.watch('./source/**/*', ['hexo'])
gulp.watch('./scaffolds/*', ['hexo'])
gulp.watch('./scaffolds/**/*', ['hexo'])
// SCSS Files
gulp.watch('./themes/backendbrasil/assets/*.scss', ['css'])
gulp.watch('./themes/backendbrasil/assets/**/*.scss', ['css'])
// Image Files
gulp.watch('./themes/backendbrasil/assets/*.{jpg,gif,png,svg}', ['images'])
gulp.watch('./themes/backendbrasil/assets/img/*.{jpg,gif,png,svg}', ['images'])
// Icons
gulp.watch('./themes/backendbrasil/assets/icons/*.svg', ['icons'])
// JS Files
gulp.watch('./themes/backendbrasil/assets/*.js', ['js'])
gulp.watch('./themes/backendbrasil/assets/**/*.js', ['js'])
})
gulp.task('clear-trash', function (cb) {
fs.remove('./public/css', cb)
})
gulp.task('build', (cb) => {
runSequence('icons', 'hexo', 'process-js', 'process-css', 'images', 'favicon', cb)
})
gulp.task('sequential-server', () => {
runSequence('icons', 'hexo', 'js', 'css', 'images', 'favicon', 'server')
})
gulp.task('default', ['sequential-server'])