forked from manavsehgal/opentheme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
118 lines (106 loc) · 3.67 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
// Adapted from https://github.com/shakyShane/jekyll-gulp-sass-browser-sync
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var cp = require('child_process');
// Optimize
var minifyCSS = require('gulp-minify-css');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
// Test
var csslint = require('gulp-csslint');
var jshint = require('gulp-jshint');
var messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll 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 sass, jekyll-build, coffee then launch the Server
*/
gulp.task('browser-sync', ['sass', 'jekyll-build', 'coffee'], function() {
browserSync({
host: '0.0.0.0', // For Cloud9 IDE Previews. Remove for localhost
port: '8080', // For Cloud9 IDE Previews. Remove for browserSync default
server: {
baseDir: '_site'
}
});
});
/**
* Wait for jekyll-build to process liquid markup in JS, then coffee
*/
gulp.task('coffee', ['jekyll-build'], function() {
return gulp.src('_site/coffee/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(gulp.dest('js'))
.pipe(gulp.dest('_site/js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('js'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('_site/js'))
});
/**
* Compile files from _sass into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('sass', function () {
return gulp.src('_sass/main.scss')
.pipe(sass({
includePaths: ['scss'],
style: 'expanded', // Human readable CSS
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('_site/css'))
.pipe(gulp.dest('css'))
// Create using https://github.com/CSSLint/csslint/wiki/Rules-by-ID
// Get defaults from https://github.com/twbs/bootstrap/blob/master/less/.csslintrc
.pipe(csslint('.csslintrc'))
.pipe(csslint.reporter())
.pipe(minifyCSS())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('_site/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('css'));
});
gulp.task('images', function () {
return gulp.src(['_images/*', '_images/*/*'])
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant({ quality: '65-80', speed: 4 })]
}))
.pipe(gulp.dest('img'));
});
/**
* Watch scss files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch('coffee/*.js', ['jekyll-build', 'coffee']);
gulp.watch('_sass/*.scss', ['sass']);
gulp.watch(['index.html', '_layouts/*.html', '_includes/*.html', '_posts/*', '_posts/*/*', '_data/*'], ['jekyll-rebuild']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
gulp.task('img', ['images']);