-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
181 lines (158 loc) · 4.3 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
// -------------------------------------
// Task: Display Tasks
// gulp -T Print the task dependency tree
// gulp --tasks-simple Print a list of gulp task names
// -------------------------------------
var gulp = require('gulp');
var gutil = require('gulp-util');
var _execute = require('child_process').exec;
var async = require('async');
var _template = require('lodash.template');
var phpunit = require('gulp-phpunit');
var path = require('path');
var execute = function(command, options, callback) {
if (!options) {
options = {};
}
options.maxBuffer = 1024 * 1000; // byte
var template = _template(command);
command = template(options);
if (!options.silent) {
gutil.log(gutil.colors.green(command));
}
if (!options.dryRun) {
var process = _execute(command, options, callback || undefined);
process.stdout.on('data', function (data) {
gutil.log(data.slice(0, -1)); // remove trailing \n
});
process.stderr.on('data', function (data) {
gutil.log(gutil.colors.yellow(data.slice(0, -1))); // remove trailing \n
});
} else {
callback(null);
}
};
// region test
// -------------------------------------
// Task: test-php-run
// -------------------------------------
gulp.task('test-php-run', function() {
var src = 'test/phpunit.xml';
var params = require('yargs')
.option('debug', {
demand: false,
describe: 'flag to run phpunit with debug',
type: 'boolean' })
.option('coverage', {
demand: false,
describe: 'flag to run phpunit with code coverage',
type: 'boolean' })
.argv;
var options = {
dryRun: false,
debug: false,
logJunit: 'PhpUnitTests.xml'
};
if (params.debug) {
options.debug = true;
delete options.logJunit;
}
if (params.coverage) {
options.coverageHtml = 'test/CodeCoverage';
}
gutil.log("##teamcity[importData type='junit' path='PhpUnitTests.xml']");
return gulp.src(src)
.pipe(phpunit('src/vendor/bin/phpunit', options));
});
gulp.task('test-php-run').description = 'run hgresume Unit tests';
// endregion test
// region build
// -------------------------------------
// Task: Build Composer for production
// -------------------------------------
gulp.task('build-composer', function (cb) {
var options = {
dryRun: false,
silent: false,
cwd: './src'
};
execute(
'composer install --no-dev',
options,
cb
);
});
// -------------------------------------
// Task: Change Ownership
// -------------------------------------
gulp.task('build-chown', function (cb) {
execute(
'sudo chown -R root:www-data contrib src',
null,
cb
);
});
gulp.task('build-chown').description =
'Change ownership before rsync';
// -------------------------------------
// Task: Build (General)
// -------------------------------------
gulp.task('build',
gulp.series(
'build-composer',
'build-chown')
);
// -------------------------------------
// Task: Build Upload to destination
// -------------------------------------
gulp.task('build-upload', function (cb) {
var params = require('yargs')
.option('dest', {
demand: true,
type: 'string' })
.option('uploadCredentials', {
demand: true,
type: 'string' })
.option('branch', {
demand: true,
type: 'string' })
.argv;
var options = {
dryRun: false,
silent: false,
rsh: '--rsh="ssh -v -i ' + params.uploadCredentials + '"',
src: 'contrib/',
dest: params.dest
};
// Redmine Resumable.
// Leave api/ directory intact!
execute(
'rsync -progzlt --chmod=Dug=rwx,Fug=rw,o-rwx ' +
'--delete-during --stats --rsync-path="sudo rsync" <%= rsh %> ' +
'--exclude=api ' +
'<%= src %> <%= dest %>',
options,
cb
);
// api/[branch name]
options.src = 'src/';
options.dest = path.join(params.dest, 'api', params.branch);
execute(
'rsync -progzlt --chmod=Dug=rwx,Fug=rw,o-rwx ' +
'--delete-during --stats --rsync-path="sudo rsync" <%= rsh %> ' +
'<%= src %> <%= dest %>',
options,
cb
);
});
// -------------------------------------
// Task: Build and Upload to destination
// -------------------------------------
gulp.task('build-and-upload',
gulp.series(
'build',
'build-upload'
)
);
// endregion build
gulp.task('default', gulp.series('test-php-run'));