-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·183 lines (153 loc) · 5.38 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
const gulp = require('gulp');
const browserSync = require('browser-sync');
const sass = require('gulp-sass');
const prefix = require('gulp-autoprefixer');
const cp = require('child_process');
const run = require('gulp-run');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify-es').default;
const htmlmin = require('gulp-htmlmin');
const rev = require('gulp-rev');
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
const messages = {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
};
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-build', function (done) {
//browserSync.notify(messages.jekyllBuild);
var shellCommand = 'bundle exec jekyll build';
return gulp.src('')
.pipe(run(shellCommand));
});
gulp.task('jekyll-watch', function (done) {
browserSync.notify(messages.jekyllBuild);
var shellCommand = 'bundle exec jekyll build';
return gulp.src('')
.pipe(run(shellCommand));
});
gulp.task('jekyll-docker', function (done) {
//browserSync.notify(messages.jekyllBuild);
return cp.spawn( jekyll , ['serve', '--host=0.0.0.0'], {stdio: 'inherit'})
.on('close', done)
});
/**
* Rebuild Jekyll & do page reload
*/
gulp.task('jekyll-rebuild', ['jekyll-watch'], function () {
browserSync.reload();
});
/**
* Wait for jekyll-build, then launch the Server
*/
gulp.task('browser-sync', ['jekyll-watch', 'sass-fast', 'scripts', 'page-scripts', 'critical',], function() {
browserSync({
server: {
baseDir: '_site'
}
});
});
/**
* Bundles JS
*/
gulp.task('scripts', function(){
return gulp.src([
'src/js/vendor/fetch.js',
'src/js/vendor/es6-promise.min.js',
'src/js/objects/**/*.js'
])
.pipe(concat('bundle.js'))
.pipe(uglify())
// .pipe(gulp.dest('static-assets/js'));
.pipe(gulp.dest('static-assets/js'));
});
/**
* Page Specific JS
*/
gulp.task("page-scripts", function () {
return gulp.src("src/js/page/**/*.js")
.pipe(uglify(/* options */))
.pipe(gulp.dest('static-assets/js'));
});
/**
* Bootstrap
*/
gulp.task('boot-css', function() {
return gulp.src(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'])
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(gulp.dest("static-assets/bootstrap/css"))
});
gulp.task('boot-js', function() {
return gulp.src(['node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js'])
.pipe(gulp.dest("static-assets/bootstrap/js"))
});
/**
* Minify HTML
*/
gulp.task('minify', function() {
return gulp.src('_site/index.html')
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(gulp.dest('_site'));
});
/**
* Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('sass-fast', function () {
return gulp.src('src/sass/*.scss')
.pipe(sass({
outputStyle: 'compressed',
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 3 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('static-assets/css'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('_site/static-assets/css'));
});
/**
* Compile files from _scss into both _site/css (for live injecting) and site (for future jekyll builds)
*/
gulp.task('critical', function () {
return gulp.src('src/sass/critical/*.scss')
.pipe(sass({
outputStyle: 'compressed',
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 3 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('_includes/critical'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('_includes/critical'));
});
//Versioned Assets
gulp.task('prod-assets-css', function () {
return gulp.src('static-assets/css/*.css')
.pipe(rev())
.pipe(gulp.dest('static-assets/dist'));
});
gulp.task('prod-assets-js', function () {
return gulp.src('static-assets/js/home.js')
.pipe(rev())
.pipe(gulp.dest('static-assets/dist'));
});
gulp.task('prod-assets', ['prod-assets-css', 'prod-assets-js']);
//Watch Tasks
gulp.task('watch', function () {
gulp.watch('src/**/*.scss', ['sass-fast', 'critical']);
gulp.watch('src/js/**/*.js', ['scripts', 'page-scripts']);
gulp.watch(['*.html','pages/**/*.html','src/js/**/*.js', 'src/sass/**/*.scss', '_layouts/*.html', '_includes/*.html', 'service-worker.js'], ['jekyll-rebuild']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the jekyll site, launch BrowserSync & watch files.
*/
gulp.task('default', ['scripts', 'page-scripts', 'critical', 'sass-fast', 'browser-sync', 'watch']);
/**
* Gulp task to build with Bootstrap
* data/about.yml should have bootstrap: true set or nothing will show up the way you want it to.
*/
gulp.task('bootstrapper', ['boot-css', 'boot-js', 'browser-sync', 'watch']);
gulp.task('boot-build', ['boot-css', 'boot-js','scripts', 'page-scripts', 'critical', 'sass-fast', 'jekyll-build']);