-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gulpfile.js
149 lines (122 loc) · 3.76 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
////////////////////////////////////////////////////////////////////////////////////
// Imports
////////////////////////////////////////////////////////////////////////////////////
'use strict';
var gulp = require('gulp');
var babel = require('gulp-babel');
var mocha = require('gulp-mocha');
var runSequence = require('run-sequence');
var rimraf = require('gulp-rimraf');
var eslint = require('gulp-eslint');
var spawn = require('child_process').spawn;
var browserify = require('gulp-browserify');
var deploy = require('gulp-gh-pages');
var cp = require('child_process');
var jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
var node;
////////////////////////////////////////////////////////////////////////////////////
// Tasks
////////////////////////////////////////////////////////////////////////////////////
gulp.task('build-js', function () {
return gulp.src(['src/javascript/**/*.js', '!src/javascript/conf/config.js'])
.pipe(babel())
.pipe(gulp.dest('build'));
});
gulp.task('build-sources', function (callback) {
runSequence('build-js', callback);
});
gulp.task('copy-assets', function () {
return gulp.src(['src/assets/**/*'])
.pipe(gulp.dest('build/public/'));
});
gulp.task('clean-build', function () {
return gulp.src('build', {read: false})
.pipe(rimraf());
});
// Default gulp task
gulp.task('default', function (callback) {
runSequence('build', callback);
});
gulp.task('eslint', function () {
return gulp.src(['**/*.js', '!node_modules/**', '!build/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('exec', function () {
if (node) node.kill();
node = spawn('node', ['build/main.js'], {stdio: 'inherit'})
node.on('close', function (code) {
if (code === 8) {
gulp.log('Error detected, waiting for changes...');
}
});
});
gulp.task('browserify', function () {
return gulp.src(['build/exports.js'])
.pipe(browserify({
insertGlobals: true,
debug: !gulp.env.production
}))
.pipe(gulp.dest('./build/public/js/'))
});
gulp.task('build', ['clean-build'], function (callback) {
runSequence('build-sources', 'copy-assets', callback);
});
gulp.task('build-for-web', function (callback) {
runSequence('build', 'browserify', callback);
});
/**
* Tests
*/
gulp.task('copy-test-data', function () {
return gulp.src('test/data/**/*')
.pipe(gulp.dest('build/test/data'));
});
gulp.task('build-tests', ['copy-test-data'], function () {
return gulp.src('test/**/*.js')
.pipe(babel())
.pipe(gulp.dest('build/test'));
});
gulp.task('mocha-tests', ['build-tests'], function () {
return gulp.src(['build/test/*Test.js'])
.pipe(mocha({timeout: 5000}))
.once('error', function (err) {
console.log(err);
process.exit(1);
})
.once('end', function () {
process.exit(0);
});
});
gulp.task('launch-tests', function (callback) {
runSequence('build', 'build-tests', 'mocha-tests', callback);
});
/**
* Watch
*/
gulp.task('watch', ['build'], function (callback) {
runSequence('exec', callback);
// Build my sources
gulp.watch(['src/javascript/**/*.js'], ['build-sources']);
// Note: try wrapping in a function if getting an error like `TypeError: Bad argument at TypeError (native) at
// ChildProcess.spawn`
gulp.watch('build/main.js', function () {
runSequence('exec', callback);
});
});
/**
* Build the Jekyll Site
*/
gulp.task('jekyll-clean', function () {
return gulp.src('_site', {read: false})
.pipe(rimraf());
});
gulp.task('jekyll-build', ['jekyll-clean', 'build-for-web'], function (done) {
return cp.spawn(jekyll, ['build'], {stdio: 'inherit'})
.on('close', done);
});
gulp.task('deploy', ['jekyll-build'], function () {
return gulp.src('./build/public/**/*')
.pipe(deploy());
});