-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathgulpfile.js
134 lines (124 loc) · 3.21 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
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const sass = require('gulp-sass')(require('node-sass'));
const child = require('child_process');
const gutil = require('gulp-util');
const browserSync = require('browser-sync');
const sourcemaps = require('gulp-sourcemaps');
const jekyll = process.platform === 'win32' ? 'jekyll.bat':'jekyll';
// PATHS
const config = {
dist: './_site',
paths: {
styles: {
src: '_src/_sass/**/*.?(s)css'
},
jsFiles: [
'_src/_scripts/jquery-2.1.1.min.js',
'_src/_scripts/jquery.fitvids.js',
'_src/_scripts/ap-components.min.js',
'_src/_scripts/main.js'
],
markupFiles: [
'_src/**/*.md',
'_src/**/*.html'
]
},
messages: {
jekyllBuild: '<span style="color: grey">Running:</span> $ jekyll build'
}
};
/**
* provides command: `jekyll build`
*/
function jekyllBuild() {
return child.spawn( jekyll, ['build'], {stdio: 'inherit'})
}
/**
* style() function takes in `inputs` and
* provides the `output` files.
*
* inputs: '_src/_sass/'
* include files: 'node_modules/susy/sass'
* output: '_src/assets/css/main.css'
*/
function style() {
return gulp.src(config.paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass({
includePaths: ['node_modules/susy/sass'],
onError: browserSync.notify
}))
.pipe(concat('main.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./_src/assets/css'))
.pipe(browserSync.reload({stream:true}));
}
/**
* js() function takes in `inputs` and
* provides the `output` files.
*
* inputs: '_src/_scripts/'
* output: '_src/assets/js/bundle.min.js'
*/
function js() {
return gulp.src(config.paths.jsFiles)
.pipe(concat('bundle.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./_src/assets/js'));
}
/**
* This function serves the static files and
* provides the tooling necessary to debugging
* generally exposed at
* --------------------------------------
* UI: http://localhost:3001
* UI External: http://localhost:3001
* --------------------------------------
* while, the website files will be served at
* --------------------------------------
* Local: http://localhost:3000
* External: http://192.168.1.100:3000
* --------------------------------------
*
* @param {*} done
*/
function browserSyncServe(done) {
browserSync.init({
server: {
baseDir: config.dist,
serveStaticOptions: {
extensions: ['html']
}
}
})
done();
}
/**
* This function reloads the browser with
* new changes saved
*
* @param {*} done
*/
function browserSyncReload(done) {
browserSync.reload();
done();
}
/**
* watch() method takes
* a path string,
* an array of path strings,
* an array of glob strings as globs
* on the filesystem.
*/
function watch() {
gulp.watch(config.paths.styles.src, style)
gulp.watch(config.paths.jsFiles, js)
gulp.watch(config.paths.markupFiles,
gulp.series(jekyllBuild, browserSyncReload));
}
// Build
gulp.task('build', gulp.series(style, js, jekyllBuild))
// Build and serve (with incremental) for development
gulp.task('default', gulp.series(style, js, jekyllBuild, browserSyncServe, watch))