forked from GDGPorto/gdgporto.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
121 lines (98 loc) · 3.49 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
'use strict';
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
// htmlmin = require('gulp-htmlmin'),
browserSync = require('browser-sync').create(),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
ghPages = require('gulp-gh-pages'),
sass = require('gulp-sass'),
cp = require('child_process'),
env = require('minimist')(process.argv.slice(2)),
bourbon = require('node-bourbon').includePaths,
path = require('path');
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);
});
// gulp.task('minify-html', function() {
// return gulp.src('_site/**/*.html')
// .pipe(htmlmin({collapseWhitespace: true}))
// .pipe(gulp.dest('_site'));
// });
// * Rebuild Jekyll & do page reload
gulp.task('jekyll-rebuild', ['jekyll-build'], function () {
browserSync.reload();
});
// * Wait for jekyll-build, then launch the Server
gulp.task('browser-sync', ['jekyll-build'], function() {
browserSync.init({
server: {
baseDir: '_site'
},
port: 4000
});
});
gulp.task('sass', function () {
gulp.src('_src/sass/main.scss')
.pipe(plumber())
.pipe(sass({
includePaths: ['styles'].concat(bourbon)
}).on('error', sass.logError))
.pipe(gulp.dest('_site/assets/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('assets/css/'));
});
// * Javascript Task
gulp.task('js', function(){
return gulp.src((env.p) ? '_src/js/**.js' : ['_src/js/**/*.js', '!_src/js/analytics.js'])
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest('assets/js/'));
});
// * JSON Task
gulp.task('json', function(){
return gulp.src('_src/json/**/*.json')
.pipe(plumber())
.pipe(gulp.dest('assets/json/'))
.pipe(gulp.dest('_site/assets/json/'))
});
// * Imagemin Task
gulp.task('imagemin', function() {
return gulp.src('_src/img/**/*.{jpg,png,gif}')
.pipe(plumber())
.pipe(gulp.dest('assets/img/'));
});
// * Apply assets Task
// gulp.task('apply-assets', function(){
// return gulp.src('assets/**/*')
// .pipe(plumber())
// .pipe(gulp.dest('_site/assets/'))
// });
/**
* Watch stylus files for changes & recompile
* Watch html/md files, run jekyll & reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch('_src/js/**/*.js', ['js']);
gulp.watch('_src/json/**/*.json', ['json']);
gulp.watch('_src/img/**/*.{jpg,png,gif}', ['imagemin']);
gulp.watch('_src/sass/**/*.scss', ['sass']);
gulp.watch(['*.html','index.html', '_includes/*.html', '_layouts/*.html', '_posts/*', '**/*.md', '**/*.html'], ['jekyll-rebuild'/*, 'minify-html'*/]);
});
gulp.task('deploy', function() {
return gulp.src('./_site/**/*')
.pipe(ghPages());
});
gulp.task('build', ['badge', 'js', 'json', 'sass']);
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['js', 'json', 'sass', 'browser-sync'/*, 'minify-html'*/, 'watch']);