-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
199 lines (163 loc) · 4.88 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
/*
* Copyright©2021, Regents of the University of California
* http://creativecommons.org/licenses/BSD
*/
// ##### Gulp Tasks #####
var { src, dest, watch, series, parallel } = require('gulp');
var sass = require('gulp-sass')(require('node-sass'));
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var server = browserSync.create();
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cleanCSS = require('gulp-clean-css');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var modernizr = require('gulp-modernizr');
var stylelint = require('stylelint');
var jshint = require('gulp-jshint');
var lbInclude = require('gulp-lb-include');
var ssi = require('browsersync-ssi');
var postcss = require('gulp-postcss');
var assets = require('postcss-assets');
var ghPages = require('gulp-gh-pages');
// Public Tasks:
exports.default = parallel(scss, start, watcher);
// exports.build = series(clean, fonts, scsslint_legacy, scsslint, jslint, scss_legacy, scss, assemble, minifyCss, copyimages, fonts);
exports.build = series(clean, fonts, jslint, scss_legacy, scss, assemble, minifyCss, copyimages, fonts, copyCSS);
exports.upload = githubpages;
exports.modernizr = runmodernizr;
// Process scss to css, add sourcemaps, inline font & image files into css:
sass.compiler = require('node-sass');
function scss(cb) {
return src('dev/scss/*.scss', { sourcemaps: true })
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(postcss([assets({
loadPaths: ['fonts/', 'images/']
})]))
.pipe(dest('dev/css', { sourcemaps: 'sourcemaps' }))
.pipe(browserSync.stream());
cb();
}
function scss_legacy(cb) {
return src('dev/legacy-scss/*.scss', { sourcemaps: true })
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(dest('dev/legacy-scss/css', { sourcemaps: 'sourcemaps' }))
.pipe(browserSync.stream());
cb();
}
// Watch scss, html, and js and reload browser if any changes:
function watcher(cb) {
watch('dev/scss/*.scss', series(scss, refresh, scsslint));
watch('dev/js/*.js', series(jslint, refresh));
watch('dev/**/*.html', refresh);
cb();
}
function refresh(cb) {
server.reload()
cb();
}
function start(cb) {
server.init({
open: false,
reloadOnRestart: true,
server: {
baseDir: 'dev',
middleware: ssi({
baseDir: __dirname + '/dev',
ext: '.html',
version: '1.4.0'
})
}
})
cb();
}
// Minify and uglify css and js from paths within useref comment tags in html:
function assemble(cb) {
return src(['dev/**/*.html', '!dev/includes/*', 'dev/css/*.css'])
.pipe(gulpIf('*.js', uglify()))
.pipe(useref())
.pipe(lbInclude()) // parse <!--#include file="" --> statements
.pipe(dest('ui_library'))
cb();
}
function minifyCss(cb) {
return src(['dev/css/*.css'])
.pipe(cleanCSS({debug: true, level: 2}, (details) => {
console.log(`${details.name}: ${details.stats.originalSize}`);
console.log(`${details.name}: ${details.stats.minifiedSize}`);
}))
.pipe(dest('ui_library'))
cb();
}
// Compress images and copy from dev/images/ into dev/ui_library/images/:
function copyimages(cb) {
return src('dev/images/**/*.+(png|jpg|jpeg|gif|svg)')
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(dest('ui_library/images'))
cb();
}
// Copy the minified css to the place it actually needs to go in order to function
function copyCSS(cb) {
return src('ui_library/css/main2.min.css')
.pipe(dest('static_src/stylesheets'));
cb();
}
// Copy font files from dev/fonts/ into dev/ui_library/fonts/:
function fonts(cb) {
return src('dev/fonts/**/*')
.pipe(dest('ui_library/fonts'))
cb();
}
// Delete ui_library directory at start of build process:
function clean(cb) {
return del('ui_library');
cb();
}
// Lint Sass:
function scsslint(cb) {
return src(['dev/scss/*.scss', '!dev/scss/vendor/*.scss'])
.pipe(stylelint({
reporters: [
{formatter: 'string', console: true}
]
}));
cb();
}
function scsslint_legacy(cb) {
return src(['dev/legacy-scss/*.scss', '!dev/legacy-scss/vendor/*.scss'])
.pipe(stylelint({
reporters: [
{formatter: 'string', console: true}
]
}));
cb();
}
// Lint JavaScript:
function jslint(cb) {
return src(['dev/js/**/*.js', '!dev/js/vendor/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('default'))
cb();
}
// Upload ui_library build to GitHub Pages:
function githubpages(cb) {
return src('./ui_library/**/*')
.pipe(ghPages())
cb();
}
// Run "gulp modernizr" to build a custom modernizr file based off of classes found in CSS:
function runmodernizr(cb) {
return src('dev/css/main2.css') // where modernizr will look for classes
.pipe(modernizr({
options: ['setClasses'],
dest: 'dev/js/modernizr-custombuild.js'
}))
cb();
}