This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
157 lines (128 loc) · 3.69 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
// ##### Gulp Tasks #####
var { src, dest, watch, series, parallel } = require('gulp');
var sass = require('gulp-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 minifyCSS = require('gulp-clean-css');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var modernizr = require('gulp-modernizr');
var runSequence = require('run-sequence');
var stylelint = require('gulp-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, jslint, scss, assemble, copyimages);
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();
}
// 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/*'])
.pipe(gulpIf('*.css', minifyCSS()))
.pipe(gulpIf('*.js', uglify()))
.pipe(useref())
.pipe(lbInclude()) // parse <!--#include file="" --> statements
.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 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();
}
// 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();
}