forked from mikeerickson/gulp-behat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
149 lines (120 loc) · 5.35 KB
/
index.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
/*jshint node:true */
'use strict';
var map = require('map-stream'),
gutil = require('gulp-util'),
os = require('os'),
exec = require('child_process').exec;
module.exports = function(command, opt){
var counter = 0;
var skipCmd = '';
// create default opt object if no options supplied
opt = opt || {};
if (typeof opt.paths === 'undefined') { opt.paths = ''; }
if (typeof opt.suite === 'undefined') { opt.suite = ''; }
if (typeof opt.out === 'undefined') { opt.out = ''; }
if (typeof opt.formatSettings === 'undefined') { opt.formatSettings = ''; }
if (typeof opt.lang === 'undefined') { opt.lang = ''; }
if (typeof opt.tags === 'undefined') { opt.tags = ''; }
if (typeof opt.role === 'undefined') { opt.role = ''; }
if (typeof opt.definitions === 'undefined') { opt.definitons = ''; }
if (typeof opt.noSnippets === 'undefined') { opt.noSnippets = true; }
if (typeof opt.rerun === 'undefined') { opt.rerun = false; }
if (typeof opt.colors === 'undefined') { opt.colors = true; }
// Global Options: not specific to Behat */
if (typeof opt.debug === 'undefined') { opt.debug = false; }
if (typeof opt.clear === 'undefined') { opt.clear = false; }
if (typeof opt.flags === 'undefined') { opt.flags = ''; }
if (typeof opt.silent === 'undefined') { opt.silent = false; }
if (typeof opt.development === 'undefined') { opt.development = false; }
// Behat Options: specific to Behat */
if (typeof opt.dryRun === 'undefined') { opt.dryRun = false; } // --format='format'
if (typeof opt.format === 'undefined') { opt.format = ''; } // --format='format'
if (typeof opt.formatSettings === 'undefined') { opt.formatSettings = ''; } // --format='format'
if (typeof opt.features === 'undefined') { opt.features = ''; } // features='features'
if (typeof opt.showTime === 'undefined') { opt.showTime = true; } // --no-time
if (typeof opt.showPaths === 'undefined') { opt.showPaths = true; } // --no-paths
if (typeof opt.multiline === 'undefined') { opt.multiline = true; } // --multiline
if (typeof opt.expand === 'undefined') { opt.expand = true; } // --no-expand
if (typeof opt.definitions === 'undefined') { opt.definitions = '-d'; } // --definitions="=d"
if (typeof opt.name === 'undefined') { opt.name = ''; } // --name
if (typeof opt.tags === 'undefined') { opt.tags = ''; } // --tags
if (typeof opt.strict === 'undefined') { opt.strict = false; } // --strict
if (typeof opt.stopOnFail === 'undefined') { opt.stopOnFail = false; } // --stop-on-failure
if (typeof opt.configFile === 'undefined') { opt.configFile = ''; } // --config='file'
if (typeof opt.profile === 'undefined') { opt.profile = ''; } // --profile='profile'
// Custom Behat Options: specific to Behat Extensions */
if (typeof opt.customOptions !== 'object') { // --someOption=value
opt.customOptions = {};
}
// if path to behat bin not supplied, use default vendor/bin path
if(! command) {
command = './vendor/bin/behat';
if (os.platform() === 'win32') {
command = command.replace(/[/]/g, '\\');
}
} else if (typeof command !== 'string') {
throw new gutil.PluginError('gulp-behat', 'Invalid Behat Binary');
}
return map(function (file, cb) {
if (opt.paths !== '') {
command += ' ' + opt.paths;
}
// construct command
var cmd = opt.clear ? 'clear && ' + command : command;
if (opt.suite !== '') { cmd += ' --suite=' + opt.suite; }
if (opt.out !== '') { cmd += ' --out=' + opt.out; }
if (opt.formatSettings !== '') { cmd += ' --format-settings=' + opt.formatSettings; }
if (opt.format !== '') { cmd += ' --format=' + opt.format; }
if (opt.lang !== '') { cmd += ' --lang=' + opt.lang; }
if (opt.tags !== '') { cmd += ' --tags=' + opt.tags; }
if (opt.role !== '') { cmd += ' --role=' + opt.role; }
if (opt.definitons !== '') { cmd += ' --definitions=' + opt.definitons; }
if (opt.noSnippets) {
cmd += ' --no-snippets --no-interaction';
}
if (opt.rerun) { cmd += ' --rerun'; }
if (opt.colors) { cmd += ' --colors'; }
if (opt.dryRun) { cmd += ' --dry-run'; }
if ( ! opt.showTime ) { cmd += ' --no-time'; }
if ( ! opt.showPaths ) { cmd += ' --no-paths'; }
if ( ! opt.expand ) { cmd += ' --no-expand'; }
if (opt.strict) { cmd += ' --strict'; }
if (opt.stopOnFail) { cmd += ' --stop-on-failure'; }
if (opt.configFile !== '') { cmd += ' --config=' + opt.configFile; }
if (opt.profile !== '') { cmd += ' --profile=' + opt.profile; }
Object.keys(opt.customOptions).forEach(function(key) {
cmd += ' --' + key + '=' + opt.customOptions[key];
});
if (counter === 0) {
counter++;
cmd += skipCmd + ' ' + opt.flags;
cmd.trim(); // clean up any space remnants
if ((opt.debug) || (opt.dryRun)){
if(opt.dryRun) {
gutil.log(gutil.colors.green('\n\n *** Dry Run: ' + cmd + '***\n'));
} else {
gutil.log(gutil.colors.yellow('\n\n *** Debug Cmd: ' + cmd + '***\n'));
}
}
if ( ! opt.development) {
exec(cmd, function (error, stdout, stderr) {
if (stdout) {
stdout = stdout.trim(); // Trim trailing cr-lf
}
if (!opt.silent && stdout) {
gutil.log(stdout);
}
if (!opt.silent && stderr) {
gutil.log(stderr);
}
if (opt.debug && error) {
gutil.log(error);
}
if (opt.notify) {
cb(error, file);
}
});
}
}
});
};