/
gulpfile.js
177 lines (160 loc) · 3.97 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
const gulp = require('gulp');
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const prefix = require('gulp-autoprefixer');
const minifycss = require('gulp-minify-css');
const rename = require('gulp-rename');
const cp = require('child_process');
const deploy = require('gulp-gh-pages');
const scsslint = require('gulp-scss-lint');
const imagemin = require('gulp-imagemin');
const pngquant = require('imagemin-pngquant');
const ngrok = require('ngrok');
const psi = require('psi');
let site = '';
const portVal = 3020;
const messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll Site
*/
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
gulp.task('jekyll-build', function(done) {
browserSync.notify(messages.jekyllBuild);
cp.spawn(jekyll, ['build'], {
stdio: 'inherit'
})
.on('close', done);
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', gulp.series('jekyll-build', function(done) {
browserSync.reload();
done();
}));
/**
* Compile files from _scss into both css and _includes
*/
gulp.task('sass', function() {
return gulp.src('_scss/main.scss')
.pipe(sass())
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {
cascade: true
}))
.pipe(minifycss())
.pipe(rename('main.min.css'))
.pipe(gulp.dest('css'))
.pipe(gulp.dest('_includes'))
.pipe(browserSync.reload({
stream: true
}));
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browser-sync', gulp.series('sass', 'jekyll-build', function(done) {
browserSync({
server: {
baseDir: '_site'
}
}, done);
}));
/**
* Deploy to Gh-Pages
*/
gulp.task('deploy', gulp.series('jekyll-build', function() {
return gulp.src('./_site/**/*')
.pipe(deploy());
}));
/**
* Minify Images
*/
gulp.task('imagemin', function() {
return gulp.src('images/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}],
use: [pngquant()]
}))
.pipe(gulp.dest('_site/images'));
});
/**
* Lint .scss
*/
gulp.task('scss-lint', function() {
return gulp.src('_scss/**/*.scss')
.pipe(scsslint({
'bundleExec': true,
'config': 'lint-config.yml'
}));
});
/**
* Page Speed Insights
*/
gulp.task('psi-desktop', function(done) {
psi({
nokey: 'true',
url: site,
strategy: 'desktop',
}, done);
});
gulp.task('psi-mobile', function(done) {
psi({
nokey: 'true',
url: site,
strategy: 'mobile',
}, done);
});
/**
* ngrok for the url
*/
gulp.task('ngrok-url', function(done) {
ngrok.connect(portVal, function(err, url) {
site = url;
console.log('serving your tunnel from: ' + site);
done();
});
});
/**
* Wait for jekyll-build, then launch the Server with port 3020
*/
gulp.task('browser-sync-psi', gulp.series('jekyll-build', function(done) {
browserSync({
port: portVal,
open: false,
server: {
baseDir: '_site',
}
}, done);
}));
gulp.task('psi-seq', gulp.series(
'browser-sync-psi',
'ngrok-url',
'psi-desktop',
'psi-mobile'
));
gulp.task('psi', gulp.series('psi-seq', function(done) {
console.log('Woohoo! Check out your page speed scores!')
process.exit();
done();
}));
/**
* Watch scss files for changes & recompile AND lint :)
* Watch html/md files, run jekyll & reload BrowserSync
* Minify images too
*/
gulp.task('watch', function() {
gulp.watch('_scss/**/*.scss', gulp.series('sass', 'jekyll-build'));
gulp.watch(['index.html', 'archive.html', '_layouts/*.html', '_includes/*.html', '_posts/**/*', 'archive/*', 'diffeedemo/*', 'speaking/*', 'about/*'], gulp.series('jekyll-rebuild'));
gulp.watch('images/*', gulp.series('imagemin'));
gulp.watch('js/*.js', gulp.series('jekyll-build'));
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', gulp.series('browser-sync', 'watch'));