forked from zachalbert/zachalbert.com_v6-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
103 lines (83 loc) · 2.82 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
"use strict";
var gulp = require('gulp'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
connect = require('gulp-connect'),
minifyCSS = require('gulp-minify-css'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
cp = require('child_process'),
deploy = require('gulp-gh-pages'),
filter = require('gulp-filter'),
mainBowerFiles = require('main-bower-files');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
}
// Build site
gulp.task('jekyll-build', function(done) {
browserSync.notify(messages.jekyllBuild);
return cp.spawn('jekyll', ['build'], {stdio: 'inherit'})
.on('close', done);
});
// Rebuild Jekyll & do page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function() {
browserSync.reload();
});
// Wait for jekyll-build, then launch server
gulp.task('browser-sync', ['styles', 'scripts', 'jekyll-build'], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
// Compile sass
gulp.task('styles', function() {
return gulp.src('_scss/style.scss')
.pipe(sass({
style: 'expanded',
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
.pipe(minifyCSS({ keepBreaks: false }))
.pipe(gulp.dest('_site/css'))
.pipe(gulp.dest('css'))
.pipe(browserSync.reload({stream: true}));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
var bowerPath = 'bower_components';
var jsPaths = [
bowerPath + '/velocity/velocity.js',
bowerPath + '/jquery/dist/*.min.js',
bowerPath + '/floatlabel.js/floatlabels.js',
'_js/**/*.js'
];
return gulp.src(jsPaths)
.pipe(concat('site.js'))
.pipe(rename('site.min.js'))
.pipe(uglify())
.pipe(gulp.dest('js'))
.pipe(browserSync.reload({stream: true}));
});
// Watch task
gulp.task('watch', function() {
gulp.watch('_scss/**/*.scss', ['styles']);
gulp.watch(['_js/*.js', 'bower_components/**/*.js'], ['scripts', 'jekyll-rebuild']);
gulp.watch(['index.html', '_includes/*.html', '_layouts/*.html', '_posts/*', 'thanks/*.html', 'work/*.html', 'images/*'], ['jekyll-rebuild']);
});
// Default
gulp.task('default', ['browser-sync', 'watch']);
// Deploy to github gulp-gh-pages
gulp.task('deploy', ['jekyll-build'], function() {
return gulp.src('./_site/**/*')
.pipe(deploy({
remoteUrl: "git@github.com:zachalbert/zachalbert.github.io.git",
branch: "master"
}));
});