-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgulpfile.js
148 lines (125 loc) · 3.37 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
'use strict';
var args = require('yargs').argv;
var config = require('./gulp.config')();
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({
lazy: true
});
var child_process = require('child_process');
// port defined in the environment takes precedence over the default port
var port = process.env.PORT || config.defaultPort;
/**
* yargs variables can be passed on the command line to alter the behavior.
* For example
* gulp vet --verbose
* will print the names of files that are in the pipe
*/
/**
* List the available gulp tasks
*/
gulp.task('help', $.taskListing);
gulp.task('default', ['help']);
/**
* vet the code and create coverage report
* @return {Stream}
*/
gulp.task('vet', function() {
log('Analyzing source with JSHint and JSCS');
return gulp
.src(config.alljs)
.pipe($.if(args.verbose, $.print()))
.pipe($.jshint())
.pipe($.jshint.reporter('jshint-stylish', {verbose: true}))
.pipe($.jshint.reporter('fail'))
.pipe($.jscs());
});
/**
* Run Cucumber tests
* @return {Stream}
*/
gulp.task('cucumber', function() {
var args = [
'./node_modules/cucumber/bin/cucumber.js',
config.features,
'--require',
config.steps,
'--format',
'pretty'
];
var cucumber = child_process.spawn('node', args);
cucumber.stdout.on('data', function(data) {
process.stdout.write(data);
});
cucumber.stderr.on('data', function(data) {
process.stdout.write(data);
});
});
/**
* Run the tests
* @return {Stream}
*/
gulp.task('test', ['vet', 'cucumber'], function() {
});
/**
* Run tests whenever source or test files change
* @return {Stream}
*/
gulp.task('autotest', ['test'], function() {
var watcher = gulp.watch(config.testDependencies, ['test']);
watcher.on('change', function(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tests...');
});
});
/**
* Start the server
* --debug-brk or --debug
*/
gulp.task('serve', function() {
var debug = args.debug || args.debugBrk;
var exec;
var nodeOptions = {
script: config.nodeServer,
delayTime: 1,
env: {
'PORT': port
},
watch: [config.server]
};
if (debug) {
log('Running node-inspector. Browse to http://localhost:8080/debug?port=5858');
exec = require('child_process').exec;
exec('node-inspector');
nodeOptions.nodeArgs = ['--debug=5858'];
}
return $.nodemon(nodeOptions)
.on('restart', ['vet'], function(ev) {
log('*** nodemon restarted');
log('files changed:\n' + ev);
})
.on('start', function() {
log('*** nodemon started');
})
.on('crash', function() {
log('*** nodemon crashed: script crashed for some reason');
})
.on('exit', function() {
log('*** nodemon exited cleanly');
});
});
/**
* Log a message or series of messages using chalk's blue color.
* Can pass in a string, object or array.
*/
function log(msg) {
if (typeof msg === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
}
else {
$.util.log($.util.colors.blue(msg));
}
}
module.exports = gulp;