-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
159 lines (136 loc) · 5.47 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserSync = require('browser-sync').create();
var del = require('del');
var cp = require('child_process');
var uncss = require('gulp-uncss');
var minifycss = require('gulp-minify-css');
var rename = require('gulp-rename');
var sourcemaps = require('gulp-sourcemaps');
var runSequence = require('run-sequence');
var sass = require('gulp-sass');
var jshint = require("gulp-jshint");
var uglify = require('gulp-uglify');
var purifycss = require('gulp-purifycss');
gulp.task("copy_npm_deps", /* ["clean"],*/ function() {
var npm_dependencies = {
"jquery/dist/jquery*.{js,map}": "./js",
"bootstrap/dist/js/bootstrap*.{js,map}": "./js",
"bootstrap-sass/assets/stylesheets/bootstrap/**/*.*": "./_sass/bootstrap",
"bootstrap-sass/assets/stylesheets/_bootstrap.scss": "./_sass/",
"font-awesome/fonts/*.*": "./fonts",
"font-awesome/scss/*.*": "./_sass/font-awesome/",
};
for (var depPath in npm_dependencies) {
let npm_path = "node_modules"
gulp.src(npm_path + '/' + depPath)
.pipe(gulp.dest(npm_dependencies[depPath]));
}
});
//https://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js
function getIPAddress() {
var interfaces = require('os').networkInterfaces();
for (var devName in interfaces) {
var iface = interfaces[devName];
for (var i = 0; i < iface.length; i++) {
var alias = iface[i];
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal)
return alias.address;
}
}
return '0.0.0.0';
}
gulp.task('clean', function() {
return del(['_site']);
return del(['.sass-cache']);
});
/**
* Build the Dev Jekyll Site
*/
gulp.task('jekyll-build-dev', function(callback) {
return cp.spawn('bundle', ['exec', 'jekyll build --config ./_config.yml,./_config-dev.yml'], { stdio: 'inherit' })
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);
});
/**
* Build the Release Jekyll Site
*/
gulp.task('jekyll-build-release', function(callback) {
var procEnv = process.env;
procEnv.JEKYLL_ENV = 'production';
return cp.spawn('bundle', ['exec', 'jekyll build --config ./_config.yml'], { stdio: 'inherit', env:procEnv })
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);
});
/**
* Set browserSync to auto-refresh site.
* BrowserSync works in proxy mode forwarding jekyll internal web-server to hostname:3000
* and injecting it auto-update java-script.
*/
gulp.task('jekyll-serve-dev', function(callback) {
browserSync.init({
open: false,
host: getIPAddress(),
proxy: 'http://localhost:4000/',
});
return cp.spawn('bundle', ['exec', 'jekyll serve --skip-initial-build --host localhost --port 4000 --no-watch'], { stdio: 'inherit' }) // Adding incremental reduces build time.
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);
});
gulp.task('jekyll-serve-release', function(callback) {
return cp.spawn('bundle', ['exec', 'jekyll serve --skip-initial-build --host '+ getIPAddress() + ' --port 3000 --no-watch'], { stdio: 'inherit' }) // Adding incremental reduces build time.
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);
});
/**
* Watch for file changes and trigger jekyl build / refresh
*/
gulp.task('jekyll-watch', function() {
gulp.watch('_sass/*.scss', function() { runSequence('styles-dev') });
// gulp.watch('scripts/*.js', function() { runSequence('scripts-dev') });
gulp.watch(['*.md', '*.html', '_layouts/*.*', '_includes/*.*', '_posts/*.*', 'tags/*.*' ],
function() { runSequence('jekyll-build-dev'); });
gulp.watch(['_site/**/*.*'], function() { browserSync.reload(); });
});
gulp.task('styles-dev', function(callback) {
del('_site/css/core.css');
return cp.spawn('bundle', ['exec', 'sass ./_sass/_main.scss ./_site/css/main.css'], { stdio: 'inherit' }) // Adding incremental reduces build time.
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);
});
gulp.task('styles-release', ['jekyll-build-release'], function(callback) {
return gulp.src('_site/css/main.css')
// .pipe(uncss({
// html: ['_site/*.html', '_site/**/*.html']
// }))
.pipe(purifycss(
['_site/*.html', '_site/**/*.html']
))
.pipe(minifycss())
.pipe(rename('main.min.css'))
.pipe(gulp.dest('_site/css/'))
.pipe(gulp.dest('./css/'))
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);
});
gulp.task('scripts-release', function(callback) {
return gulp.src('_site/scripts/main.js')
.pipe(jshint())
.pipe(jshint.reporter("default"))
.pipe(uglify())
.pipe(rename('main.min.js'))
.pipe(gulp.dest('./scripts'))
.pipe(gulp.dest('_site/scripts'))
.on('error', (error) => gutil.log(gutil.colors.red(error.message)))
.on('close', callback);;
});
gulp.task('dev', function() {
return runSequence('jekyll-build-dev',
'styles-dev',
['jekyll-watch', 'jekyll-serve-dev']
);
});
gulp.task('release', function(callback) {
runSequence('clean', 'styles-release', 'scripts-release', 'jekyll-serve-release', callback);
});
gulp.task('default', ['dev'])