forked from MissingMaps/partners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
190 lines (162 loc) · 5.43 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
184
185
186
187
188
189
190
var gulp = require('gulp');
var cp = require('child_process');
var runSequence = require('run-sequence').use(gulp);
var autoprefixer = require('gulp-autoprefixer');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var clean = require('gulp-clean');
var browserSync = require('browser-sync');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var babel = require('gulp-babel');
/* ------------------------------------------------------------------------------
-------------------------- 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 -------------------------------------
----------------------------------------------------------------------------*/
var sassInput = 'app/assets/styles/*.scss';
var sassOptions = {
includePaths: ['node_modules/foundation-sites/scss','node_modules/font-awesome/scss','.tmp/assets/styles' ],
errLogToConsole: true,
outputStyle: 'expanded'
};
var autoprefixerOptions = {
browsers: ['last 2 versions', 'ie >= 9', 'and_chr >= 2.3']
};
gulp.task('sass', function() {
return gulp.src(sassInput)
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass(sassOptions).on('error', sass.logError))
.pipe(autoprefixer(autoprefixerOptions))
.pipe(sourcemaps.write('.'))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest('.tmp/assets/styles'));
});
gulp.task('compress:main', function () {
// main.min.js
var task = gulp.src([
'app/assets/scripts/*.js'
])
.pipe(babel({
presets: ['es2015']
}))
.pipe(concat('main.min.js')); //hotfix
// 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'));
});
gulp.task('compress:vendor', function () {
// vendor.min.js
var task = gulp.src([
'app/assets/scripts/vendor/*.js'
])
.pipe(concat('vendor.min.js')); //hotfix
// if (environment === 'development') {
// task = task.pipe(concat('vendor.min.js'));
// } else {
// task = task.pipe(uglify('vendor.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);
});
// Copies fonts
gulp.task('fonts', function () {
return gulp.src('app/assets/fonts/**/*')
.pipe(gulp.dest('.tmp/assets/styles/fonts'));
});
// 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', 'compress:vendor', 'sass', 'fonts'], ['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', 'build', browserReload);
});
gulp.watch('app/assets/styles/**/*.scss', function () {
runSequence('sass');
});
gulp.watch(['./app/assets/scripts/**/*.js', '!./app/assets/scripts/vendor/**/*'], function () {
runSequence('compress:main', 'compress:vendor', 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();
}
}