-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
195 lines (147 loc) · 4.72 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
(function(){
"use strict";
var $ = require('./build/gulp');
var phpFiles = [
'**/*.php',
'!vendor/**/*.php',
'!node_modules/**/*.php'
];
var jsFiles = [
'**/*.js',
'!node_modules/**/*.js',
'!vendor/**/*.js'
];
var versionFiles = [
'**/*',
'!vendor/**/*',
'!node_modules/**/*'
];
var packageJson = {};
$.gulp.task('default', ['lint:js', 'integration'], function(){
return $.php.closeServer(function(){
pass('Build passed');
});
});
$.gulp.task('integration', ['unit', 'server'], function(){
return $.gulp.src('codeception.yml')
.pipe($.codeception('./vendor/bin/codecept', {flags: ' -f -q', notify: true}))
.on('error', function(){
fail('Integration tests failed');
});
});
$.gulp.task('unit', ['psr2'], function(){
return $.gulp.src('phpspec.yml').pipe($.phpspec('./vendor/bin/phpspec', {quiet: true, notify: true}))
.on('error', function(){
fail('Unit tests failed');
});
});
$.gulp.task('psr2', ['lint:php'], function(){
var files = phpFiles.concat([
'!tests/**/*.php'
]) ;
return $.gulp.src(files)
.pipe($.phpcs({
bin: 'vendor/bin/phpcs',
standard: 'PSR2',
errorSeverity: 1,
warningSeverity: 1,
colors: true
}))
.pipe($.phpcs.reporter('log'))
.pipe($.phpcs.reporter('fail'))
.on('error', function(){
fail('PSR-2 failed.');
});
});
$.gulp.task('lint:php', function() {
return $.phplint(phpFiles,
{limit: 1, stdout: false, stderr: false},
function (error) {
if (error) {
fail(['PHP Lint failed', error.message]);
}
});
});
$.gulp.task('lint:js', ['json:package'], function(){
return $.gulp.src(jsFiles)
.pipe($.jshint(new $.JsHintOptions('node')))
.pipe($.jshint.reporter('default'))
.pipe($.jshint.reporter('fail'))
.on('error', function(){
fail('JavasScript Lint failed');
});
});
$.gulp.task('server', function(){
return $.php.server({
port: 8000,
hostname: 'localhost',
router: 'server.php'
});
});
$.gulp.task('json:package', function(callback){
$.readPackage('package.json', $.util.log, true, function(error, data){
if(error){
fail(error);
}
if(!data.version){
fail('No version is specified.');
}
packageJson = data;
callback();
});
});
$.gulp.task('version', ['git:status', 'json:package'], function(){
// usage:
// -v patch, minor, major, prepatch, preminor, premajor, prerelease
// -p alpha beta rc (if pre)
var v = $.args.v || 'patch';
var p = $.args.p || 'beta';
var oldVersion = packageJson.version;
var newVersion = $.semver.inc(oldVersion, v, p);
packageJson.version = newVersion;
$.gulp.src(versionFiles)
.pipe($.replace(new RegExp(oldVersion, 'g'), newVersion))
.pipe($.save())
.on('error', function(){
fail('We could not update the version to ' + newVersion);
});
pass('Version bumped to ' + newVersion);
log('Use git diff to check', 'yellow');
});
$.gulp.task('git:status', function(callback){
$.git.status({quiet: true}, function(error, stdout){
if(error){
fail('Could not run `git status`', false);
}
if(stdout.indexOf('nothing to commit') === -1) {
fail('Git status is not clean!', false);
}
callback();
});
});
function fail(messages, closeServer){
closeServer = closeServer === undefined ? true : closeServer;
if(closeServer) {
return $.php.closeServer(function(){
log(messages, 'red');
process.exit(1);
});
}else{
log(messages, 'red');
process.exit(1);
}
}
function pass(messages){
log(messages, 'green');
}
function log(messages, color)
{
if(messages instanceof Array) {
messages.forEach(function(message){
log(message, color);
});
} else {
$.util.log($.util.colors[color](messages));
}
}
}());