-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
305 lines (272 loc) · 8.89 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
'use strict';
const {src, dest, watch, series, parallel } = require('gulp');
const log = require('fancy-log');
const colors = require('ansi-colors');
const browserSync = require('browser-sync').create();
const sass = require('gulp-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 removeCode = require('gulp-remove-code');
const removeLog = require('gulp-remove-logging');
const prettyHtml = require('gulp-pretty-html');
const sassLint = require('gulp-sass-lint');
const htmllint = require('gulp-htmllint');
const jshint = require('gulp-jshint');
const htmlreplace = require('gulp-html-replace');
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/';
// 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 BULMA SASS INTO CSS
function compileSASS() {
console.log('---------------COMPILING BULMA SASS---------------');
return src(['src/assets/sass/bulma.sass'])
.pipe(sass({
outputStyle: 'compressed',
sourceComments: 'map',
sourceMap: 'sass',
includePaths: bourbon
}).on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(dest('dist/assets/css'))
.pipe(browserSync.stream());
}
// 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('last 2 versions'))
.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---------------');
return src([
'src/assets/js/functions.js',
'src/assets/js/main.js',
])
.pipe(babel())
.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 copyImages() {
console.log('---------------OPTIMIZING IMAGES---------------');
return src('src/assets/img/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(newer('dist/assets/img/'))
//.pipe(imagemin())
.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 + 'slick-carousel/slick/slick.min.js',
nodepath + 'scrollreveal/dist/scrollreveal.min.js',
nodepath + 'waypoints/lib/jquery.waypoints.min.js',
nodepath + 'waypoints/lib/shortcuts/sticky.min.js',
nodepath + 'jquery.counterup/jquery.counterup.min.js',
//Additional static js assets
'src/assets/vendor/js/**/*.js',
])
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.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',
//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'));
}
// 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, copyFont, copyData, jsVendor, cssVendor, copyImages, compileHTML, concatPlugins, concatCssPlugins, compileJS, resetPages, prettyHTML, compileSASS, compileSCSS, browserSyncInit, watchFiles);