forked from nerdlab-be/cityhacks-2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
261 lines (236 loc) · 5.55 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
'use strict';
// ---
// Setup: load plugins and define config variables
// ---
// Plugins
const gulp = require("gulp");
const cp = require("child_process");
const shell = require('gulp-shell')
const gnf = require("gulp-npm-files");
const browsersync = require("browser-sync").create();
const del = require("del");
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const postcss = require("gulp-postcss");
const autoprefixer = require("autoprefixer");
const cssnano = require("cssnano");
const cheerio = require("gulp-cheerio");
const svgSymbols = require("gulp-svg-symbols");
const concat = require("gulp-concat");
const uglify = require("gulp-uglify");
// Config
const config = {
browsersync: {
server: {
baseDir: '_site',
reloadDelay: 2000,
debounce: 200,
notify: true,
ghostMode: {
clicks: true,
location: true,
forms: true,
scroll: false
}
}
},
icons: {
title: '%f icon',
svgAttrs: {
class: 'c-icon-set',
},
templates: ['default-svg']
},
cheerio: {
run: function ($) {
$('[fill]').removeAttr('fill');
},
parserOptions: { xmlMode: true }
},
autoprefixer: {
browsers: [
'last 2 version',
'> 2%',
'ie >= 9',
'ios >= 8',
'android >= 4'
]
},
jsConcat: 'scripts.js'
};
// Paths
const paths = {
vendor: './_vendor/',
scssSrc: './assets/_scss/**/*.scss',
cssSrc: './assets/css/',
cssDist: './_site/assets/css/',
jsSrc: [
'./_vendor/jquery/dist/jquery.slim.js',
'./_vendor/svgxuse/svgxuse.js',
'./assets/js/_scripts/*.js'
],
jsDist: './assets/js/',
jsJekyllDist: './_site/assets/js/',
iconsSrc: './_artwork/icons/*.svg',
iconsDist: './assets/img/svg/',
cssWatch: './assets/_scss/**/*.scss',
jsWatch: './assets/js/_scripts/**/*.js',
iconsWatch: './_artwork/icons/*.svg',
imageWatch: './assets/img/**/*',
siteWatch: [
'./assets/img/**/*.png',
'./assets/img/**/*.jpg',
'./assets/img/**/*.svg',
'./**/*.html',
'./_pages/**/*.markdown',
'./_posts/**/*.markdown',
'./_data/**/*.yml',
'./_config.yml',
'!_site/**/*.*'
]
}
// Install
// ---
// Copy dependencies from `node_modules` to $paths.vendor
function copyNpmDependencies() {
return gulp.src(gnf(), {base:'./'})
.pipe(gulp.dest(paths.vendor));
}
// Move `$paths.vendor/node_modules/**/*` to `$paths.vendor/**/*`
function copyVendorDependencies() {
return gulp.src(paths.vendor + 'node_modules/**/*')
.pipe(gulp.dest(paths.vendor));
}
// Delete `$paths.vendor/node_modules`
function dependencies() {
return del([paths.vendor + 'node_modules/']);
}
// BrowserSync
// ---
function browserSync(done) {
browsersync.init(config.browsersync);
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
browsersync.reload();
done();
}
// Jekyll
// ---
// Incremental build
function jekyll() {
return cp.spawn("bundle", ["exec", "jekyll", "build", "--incremental"], { stdio: "inherit" });
}
// Production build
function jekyllBuild() {
return cp.spawn("bundle", ["exec", "jekyll", "build"], { stdio: "inherit" });
}
// Clean
// ---
// Clean site folder
function clean() {
return del(["./_site/"]);
}
// Icons
// ---
// Convert multiple svg's to one symbol file
// https://css-tricks.com/svg-symbol-good-choice-icons/
function icons() {
return gulp.src(paths.iconsSrc)
.pipe(cheerio(config.cheerio))
.pipe(svgSymbols(config.icons))
.pipe(gulp.dest(paths.iconsDist))
.pipe(browsersync.stream());
}
// CSS
// ---
function css() {
return gulp
.src(paths.scssSrc)
.pipe(sass({ outputStyle: "expanded" }))
.pipe(postcss([autoprefixer(config.autoprefixer)]))
.pipe(gulp.dest(paths.cssSrc))
.pipe(gulp.dest(paths.cssDist))
.pipe(browsersync.stream());
}
function cssProduction() {
return gulp
.src(paths.scssSrc)
.pipe(sass())
.pipe(rename({ suffix: ".min" }))
.pipe(postcss([autoprefixer(config.autoprefixer), cssnano()]))
.pipe(gulp.dest(paths.cssSrc))
.pipe(gulp.dest(paths.cssDist));
}
// JS
// ---
// Transpile, concatenate and minify scripts
function scripts() {
return gulp
.src(paths.jsSrc)
.pipe(concat(config.jsConcat))
.pipe(gulp.dest(paths.jsDist))
.pipe(gulp.dest(paths.jsJekyllDist))
.pipe(browsersync.stream())
}
function scriptsProduction() {
return gulp
.src(paths.jsSrc)
.pipe(concat(config.jsConcat))
.pipe(uglify())
.pipe(rename({ suffix: ".min" }))
.pipe(gulp.dest(paths.jsDist))
.pipe(gulp.dest(paths.jsJekyllDist));
}
// Watch files
// ---
function watchFiles() {
gulp.watch(paths.cssWatch, css);
gulp.watch(paths.jsWatch, scripts);
gulp.watch(paths.jsWatch, scripts);
gulp.watch(paths.iconsWatch, icons);
gulp.watch(
paths.siteWatch,
gulp.series(jekyll, browserSyncReload)
);
}
// Tasks
// ---
gulp.task("install", gulp.series(copyNpmDependencies, copyVendorDependencies, dependencies));
gulp.task("jekyll", jekyll);
gulp.task("jekyllBuild", jekyllBuild);
gulp.task("icons", icons);
gulp.task("css", css);
gulp.task("cssProduction", cssProduction);
gulp.task("scripts", scripts);
gulp.task("scriptsProduction", scriptsProduction);
gulp.task("clean", clean);
// Default
gulp.task(
"default",
gulp.series(
"install",
clean,
gulp.parallel(css, scripts,icons),
jekyll
)
);
// Build
gulp.task(
"build",
gulp.series(
"install",
clean,
gulp.parallel(cssProduction, scriptsProduction,icons),
jekyllBuild
)
);
// Watch
gulp.task(
"watch",
gulp.series(
"default",
gulp.parallel(watchFiles, browserSync)
)
);