-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
155 lines (133 loc) · 3.81 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
// gulpfile.js
// Initialize modules
const gulp = require('gulp');
// Importing all the Gulp-related packages we want to use
const concat = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass');
//const browserSync = require('browser-sync');
//const server = browserSync.create();
const child = require('child_process');
const gutil = require('gulp-util');
const sassGlob = require('gulp-sass-glob');
const webpack = require('webpack-stream');
// File paths
const files = {
scssPath: '_includes/beatrice/**/*.scss',
embedScssPath: 'embeds/scss/*.scss',
jsPath: '_includes/beatrice/**/*.js',
js3rdPartyPath: 'third_party/**'
}
// Sass task: compiles the style.scss file into style.css
function scssTask(){
return gulp.src(files.scssPath)
.pipe(sourcemaps.init()) // initialize sourcemaps first
.pipe(sassGlob())
.pipe(sass({
includePaths: ['node_modules'],
outputStyle: 'compressed'
}))
.pipe(sourcemaps.write('.')) // write sourcemaps file in current directory
.pipe(gulp.dest('assets/css')); // put final CSS in assets folder
}
function scssTaskToSiteFolder(){
return gulp.src(files.scssPath)
.pipe(sourcemaps.init()) // initialize sourcemaps first
.pipe(sassGlob())
.pipe(sass({
includePaths: ['node_modules'],
outputStyle: 'compressed'
}))
.pipe(sourcemaps.write('.')) // write sourcemaps file in current directory
.pipe(gulp.dest('_site/assets/css')); // put final CSS in assets folder
}
// JS task: compiles JS files into main.js
function jsTaskToSiteFolder(){
return gulp.src(files.jsPath)
.pipe(webpack())
.pipe(concat('main.js'))
.pipe(gulp.dest('_site/assets/js')); // put final JS in assets folder
}
// JS task: compiles JS files into main.js
function jsTask(){
return gulp.src(files.jsPath)
.pipe(webpack())
.pipe(concat('main.js'))
.pipe(gulp.dest('assets/js')); // put final JS in assets folder
}
function js3rdPartyTask(){
return gulp.src(files.js3rdPartyPath)
.pipe( gulp.dest('assets/js') ); // put final 3rd party JS in assets folder
}
// Watch task: watch SCSS and JS files for changes
// If any change, run scss and js tasks simultaneously
function watchTask(){
gulp.watch([files.scssPath, files.jsPath], gulp.series(scssTask, jsTask, jekyllBuild));
gulp.watch(
[
'./_layouts/**/*',
'./_pages/**/*',
'./_posts/**/*'
], gulp.series(jekyllBuild))
}
function watchTaskLite(done) {
gulp.watch([files.scssPath, files.jsPath], gulp.series(scssTaskToSiteFolder, jsTaskToSiteFolder));
done()
}
const jekyllLogger = (buffer) => {
buffer.toString()
.split(/\n/)
.forEach((message) => gutil.log('Jekyll: ' + message));
};
function jekyll(done) {
const jekyll = child.spawn('bundle', ['exec',
'jekyll',
'serve'
]);
jekyll.stdout.on('data', jekyllLogger);
jekyll.stderr.on('data', jekyllLogger);
done();
};
function jekyllBuild(done) {
const jekyll = child.spawn('bundle', ['exec',
'jekyll',
'build',
]);
jekyll.stdout.on('data', jekyllLogger);
jekyll.stderr.on('data', jekyllLogger);
done();
};
function jekyllWatch(done) {
const jekyll = child.spawn('bundle', ['exec',
'jekyll',
'serve',
'--incremental',
'--watch'
]);
jekyll.stdout.on('data', jekyllLogger);
jekyll.stderr.on('data', jekyllLogger);
done();
};
// Export the default Gulp task so it can be run
// Runs the scss and js tasks simultaneously
// then runs cacheBust, then watch task
exports.default = gulp.series(
scssTask,
jsTask,
js3rdPartyTask,
jekyll,
watchTask
);
exports.build = gulp.series(
scssTask,
jsTask,
js3rdPartyTask,
jekyllBuild
)
exports.develop = gulp.series(
scssTask,
jsTask,
js3rdPartyTask,
watchTaskLite,
jekyllWatch,
)