forked from digitalbiblesociety/browserbible-3
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gulpfile.js
223 lines (219 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Include Gulp
*
* @type {Object}
*/
var gulp = require('gulp');
/**
* Include Gulp JSHint
*
* @type {Object}
*/
var jshint = require('gulp-jshint');
/**
* Include Gulp mocha
*
* @type {Object}
*/
var mocha = require('gulp-mocha');
/**
* The Mocha reporter using node-notify
*
* @type {Object}
*/
var notifierReporter = require('mocha-notifier-reporter');
/**
* The plumber for allowing errors to pass through
*
* @type {Object}
*/
var plumber = require('gulp-plumber');
/**
* Notify the user
*
* @type {Object}
*/
var notify = require('gulp-notify');
/**
* Path library
*
* @type {Object}
*/
var path = require('path');
/**
* Run a Child Process
*
* @type {Object}
*/
var exec = require('child_process').exec;
/**
* The location of the uw grab bibles scripts
*
* @type {String}
*/
var grabBiblesScript = path.join('./tools', 'unfolding-word', 'uw-grab-bibles.js');
/**
* The location of the bible generation script
*
* @type {String}
*/
var generateScript = path.join('./tools', 'generate.js');
/**
* The location of the creating index script
*
* @type {String}
*/
var createIndexScript = path.join('./tools', 'create_texts_index.js');
/**
* Are we watching for code changes?
*
* @type {Boolean}
*/
var watching = false;
/**
* An array of files to watch and run lint on
*
* @type {Array}
*/
var sources = [
'./gulpfile.js',
'./tools/unfolding-word/**/*.js',
'./tests/**/*.js'
];
/**
* An array of file locations for the test files to be run
*
* @type {Array}
*/
var testSources = ['./tests/**/*.js'];
/**
* Handle Mocha Errors
*
* @param {Object} err The error object
*
* @author Johnathan Pulos <[email protected]>
*/
function handleMochaError(err) {
console.log(err.toString());
if (!watching) {
process.exit(1);
}
this.emit('end');
}
function handleLintError(err) {
console.log(err.toString());
this.emit('end');
}
/**
* Offer some helpful hints
*/
gulp.task('help', function() {
console.log('-----------------------');
console.log('lint - Runs jshint on the tests, and all code in the tools/unfolding-word directories.');
console.log('test - Runs the mocha tests files in the test directory.');
console.log('uw:build - Builds the website by grabbing the latest Bibles, converting them to HTML, and setting them up in the correct directory. (Combines uw:grab-bibles & uw:build-bibles)');
console.log('uw:grab-bibles - Grabs the latest Bible from unfoldingWord, and stores them in the input directory.');
console.log('uw:build-bibles - Builds all the Bibles in the input directory, and sets them up in the correct directory.');
console.log('watch - Watches for code changes in the tests & tools/unfolding-word directories. Then triggers the lint and test tasks.');
console.log('-----------------------');
});
/**
* Build the site
*
* @author Johnathan Pulos <[email protected]>
*/
gulp.task('uw:build', function() {
console.log('Grabbing the latest Bibles from unfoldingWord.');
executeScript('node ' + grabBiblesScript, function() {
console.log('All the Bibles have been downloaded.');
console.log('Building all the available Bibles.');
executeScript('node ' + generateScript + ' -a', function() {
console.log('Adding an index for all the Bibles.');
executeScript('node ' + createIndexScript, function() {
console.log('The index was created.');
console.log('The build was completed');
});
});
});
});
/**
* Grab the current UW Bibles
*
* @author Johnathan Pulos <[email protected]>
*/
gulp.task('uw:grab-bibles', function() {
console.log('Grabbing the latest Bibles from unfoldingWord.');
executeScript('node ' + grabBiblesScript, function() {
console.log('All the Bibles have been downloaded.');
});
});
/**
* Build the Bibles
*
* @author Johnathan Pulos <[email protected]>
*/
gulp.task('uw:build-bibles', function() {
console.log('Building all the available Bibles.');
executeScript('node ' + generateScript + ' -a', function() {
console.log('Adding an index for all the Bibles.');
executeScript('node ' + createIndexScript, function() {
console.log('The index was created');
});
});
});
/**
* Add a linting task
*
* @author Johnathan Pulos <[email protected]>
*/
gulp.task('lint', function() {
return gulp
.src(sources)
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.on('error', notify.onError({message: 'Linting Failed!'}))
.on('error', handleLintError);
});
/**
* Add a task for running the tests
*
* @author Johnathan Pulos <[email protected]>
*/
gulp.task('test', function() {
return gulp
.src(testSources)
.pipe(mocha({reporter: notifierReporter.decorate('spec')}))
.on('error', handleMochaError);
});
/**
* Setup the watch task
*/
gulp.task('watch', function() {
watching = true;
gulp.watch(sources, function() {
gulp.run('lint', 'test');
});
});
/**
* Run and execute a script
*
* @param {String} the script to run
* @return {Void}
* @access private
*/
function executeScript(script, callback) {
var child = exec(script);
child.stdout.on('data', function(data) {
console.log(data);
});
child.stderr.on('data', function(data) {
console.log(data);
});
child.on('close', function(code) {
if (callback) {
callback();
}
});
}