forked from MissingMaps/missingmaps.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
160 lines (135 loc) · 4.4 KB
/
Copy pathgulpfile.js
File metadata and controls
160 lines (135 loc) · 4.4 KB
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
var gulp = require('gulp');
var cp = require('child_process');
var runSequence = require('run-sequence');
var compass = require('gulp-compass');
var uglify = require('gulp-uglifyjs');
var clean = require('gulp-clean');
var browserSync = require('browser-sync');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var cp = require('child_process');
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//-------------------------- Copy tasks --------------------------------------//
//----------------------------------------------------------------------------//
// Copy from the .tmp to _site directory.
// To reduce build times the assets are compiles at the same time as jekyll
// renders the site. Once the rendering has finished the assets are copied.
gulp.task('copy:assets', function(done) {
return gulp.src('.tmp/assets/**')
.pipe(gulp.dest('_site/assets'));
});
////////////////////////////////////////////////////////////////////////////////
//--------------------------- Assets tasks -----------------------------------//
//----------------------------------------------------------------------------//
gulp.task('compass', function() {
return gulp.src('app/assets/styles/*.scss')
.pipe(plumber())
.pipe(compass({
css: '.tmp/assets/styles',
sass: 'app/assets/styles',
style: 'expanded',
sourcemap: true,
require: ['sass-css-importer'],
bundle_exec: true
}))
.on('error', function(err) {
this.emit('end');
})
.pipe(browserSync.reload({stream:true}));
});
gulp.task('compress:main', function() {
// main.min.js
var task = gulp.src([
'app/assets/scripts/*.js',
])
.pipe(plumber());
if (environment == 'development') {
task = task.pipe(concat('main.min.js'));
}
else {
task = task.pipe(uglify('main.min.js', {
outSourceMap: true,
mangle: false
}));
}
return task.pipe(gulp.dest('.tmp/assets/scripts'));
});
// Build the jekyll website.
gulp.task('jekyll', function (done) {
var args = ['exec', 'jekyll', 'build'];
switch (environment) {
case 'development':
args.push('--config=_config.yml,_config-dev.yml');
break;
case 'stage':
args.push('--config=_config.yml,_config-stage.yml');
break;
case 'production':
args.push('--config=_config.yml');
break;
}
return cp.spawn('bundle', args, {stdio: 'inherit'})
.on('close', done);
});
// Build the jekyll website.
// Reload all the browsers.
gulp.task('jekyll:rebuild', ['jekyll'], function () {
browserSync.reload();
});
// Main build task
// Builds the site. Destination --> _site
gulp.task('build', function(done) {
runSequence(['jekyll', 'compress:main', 'compass'], ['copy:assets'], done);
});
// Default task.
gulp.task('default', function(done) {
runSequence('build', done);
});
gulp.task('serve', ['build'], function () {
browserSync({
port: 3000,
server: {
baseDir: ['.tmp', '_site']
}
});
gulp.watch(['./app/assets/fonts/**/*', './app/assets/images/**/*'], function() {
runSequence('jekyll', browserReload);
});
gulp.watch('app/assets/styles/**/*.scss', function() {
runSequence('compass');
});
gulp.watch(['./app/assets/scripts/**/*.js', '!./app/assets/scripts/vendor/**/*'], function() {
runSequence('compress:main', browserReload);
});
gulp.watch(['app/**/*.html', 'app/**/*.md', 'app/**/*.json', 'app/**/*.geojson', '_config*'], function() {
runSequence('jekyll', browserReload);
});
});
var shouldReload = true;
gulp.task('no-reload', function(done) {
shouldReload = false;
runSequence('serve', done);
});
var environment = 'development';
gulp.task('prod', function(done) {
environment = 'production';
runSequence('clean', 'build', done);
});
gulp.task('stage', function(done) {
environment = 'stage';
runSequence('clean', 'build', done);
});
// Removes jekyll's _site folder
gulp.task('clean', function() {
return gulp.src(['_site', '.tmp'], {read: false})
.pipe(clean());
});
////////////////////////////////////////////////////////////////////////////////
//------------------------- Helper functions ---------------------------------//
//----------------------------------------------------------------------------//
function browserReload() {
if (shouldReload) {
browserSync.reload();
}
}