forked from microsoft/react-native-code-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
302 lines (248 loc) · 9.14 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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
var del = require("del");
var gulp = require("gulp");
var path = require("path");
var child_process = require("child_process");
var Q = require("q");
var runSequence = require("run-sequence");
var testPath = "./test";
var binPath = "./bin";
var tsFiles = "/**/*.ts";
var iOSSimulatorProcessName = "Simulator";
var emulatorReadyCheckDelay = 30 * 1000;
var emulatorMaxReadyAttempts = 5;
/* This message is appended to the compiled JS files to avoid contributions to the compiled sources.*/
var compiledSourceWarningMessage = "\n \
/******************************************************************************************** \n \
THIS FILE HAS BEEN COMPILED FROM TYPESCRIPT SOURCES. \n \
PLEASE DO NOT MODIFY THIS FILE AS YOU WILL LOSE YOUR CHANGES WHEN RECOMPILING. \n \
ALSO, PLEASE DO NOT SUBMIT PULL REQUESTS WITH CHANGES TO THIS FILE. \n \
INSTEAD, EDIT THE TYPESCRIPT SOURCES UNDER THE WWW FOLDER. \n \
FOR MORE INFORMATION, PLEASE SEE CONTRIBUTING.md. \n \
*********************************************************************************************/ \n\n\n";
/* TypeScript compilation parameters */
var tsCompileOptions = {
"noImplicitAny": true,
"noEmitOnError": true,
"target": "ES5",
"module": "commonjs",
"sourceMap": false,
"sortOutput": true,
"removeComments": true
};
function spawnCommand(command, args, callback, silent, detached) {
var options = { maxBuffer: 1024 * 1024 };
if (detached) {
options.detached = true;
options.stdio = ["ignore"];
}
var spawnProcess = child_process.spawn(command, args, options);
if (!silent) spawnProcess.stdout.pipe(process.stdout);
if (!silent) spawnProcess.stderr.pipe(process.stderr);
if (!detached) {
spawnProcess.on('exit', function (code) {
callback && callback(code === 0 ? undefined : "Error code: " + code);
});
}
return spawnProcess;
};
function execCommand(command, args, callback, silent) {
var execProcess = child_process.exec(command + " " + args.join(" "), { maxBuffer: 1024 * 1024 });
if (!silent) execProcess.stdout.pipe(process.stdout);
if (!silent) execProcess.stderr.pipe(process.stderr);
execProcess.on('error', function (error) {
callback && callback(error);
})
execProcess.on('exit', function (code) {
callback && callback(code === 0 ? undefined : "Error code: " + code);
});
return execProcess;
};
function runTests(callback, options) {
var command = "mocha";
var args = ["./bin/test"];
// pass arguments supplied by test tasks
if (options.android) args.push("--android");
if (options.ios) args.push("--ios");
if (options.setup) args.push("--setup");
// pass arguments from command line
// the fourth argument is the first argument after the task name
for (var i = 3; i < process.argv.length; i++) {
if (process.argv[i] === "--report") {
// Set up the mocha junit reporter.
args.push("--reporter");
args.push("mocha-junit-reporter");
// Set the mocha reporter to the correct output file.
args.push("--reporter-options");
var filename = "./test-results.xml";
if (options.android && !options.ios) filename = "./test-android.xml";
else if (options.ios && !options.android) filename = "./test-ios.xml";
args.push("mochaFile=" + filename);
// Delete previous test result file so TFS doesn't read the old file if the tests exit before saving
del(filename);
} else args.push(process.argv[i]);
}
execCommand(command, args, callback);
}
gulp.task("compile", function (callback) {
runSequence("compile-test", callback);
});
gulp.task("compile-test", function () {
var ts = require("gulp-typescript");
var insert = require("gulp-insert");
return gulp.src([testPath + tsFiles])
.pipe(ts(tsCompileOptions))
.pipe(insert.prepend(compiledSourceWarningMessage))
.pipe(gulp.dest(path.join(binPath, testPath)));
});
gulp.task("tslint", function () {
var tslint = require('gulp-tslint');
// Configuration options adapted from TypeScript project:
// https://github.com/Microsoft/TypeScript/blob/master/tslint.json
var config = {
"rules": {
"class-name": true,
"comment-format": [true,
"check-space"
],
"indent": [true,
"spaces"
],
"one-line": [true,
"check-open-brace"
],
"no-unreachable": true,
"no-unused-variable": true,
"no-use-before-declare": true,
"quotemark": [true,
"double"
],
"semicolon": true,
"whitespace": [true,
"check-branch",
"check-operator",
"check-separator",
"check-type"
],
"typedef-whitespace": [true, {
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}]
}
}
return gulp.src([testPath + tsFiles, "!" + testPath + "/typings/*"])
.pipe(tslint({ configuration: config }))
.pipe(tslint.report("verbose"));
});
gulp.task("clean", function () {
return del([binPath + "/**"], { force: true });
});
gulp.task("default", function (callback) {
runSequence("clean", "compile", "tslint", callback);
});
////////////////////////////////////////////////////////////////////////
// Test Tasks //////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// Standalone Tasks
//
// Run the tests without setting up the test projects.
// Don't run these without running a setup task first!
// Run on Android standalone
gulp.task("test-run-android", function (callback) {
var options = {
android: true
};
runTests(callback, options);
});
// Run on iOS standalone
gulp.task("test-run-ios", function (callback) {
var options = {
ios: true,
ui: true,
};
runTests(callback, options);
});
////////////////////////////////////////////////////////////////////////
// Setup Tasks
//
// Sets up the test project directories that the tests use and starts emulators.
// Must run before running a standalone suite of tests!
// Sets up the test projects and starts an Android emulator
gulp.task("test-setup-android", function (callback) {
var options = {
setup: true,
android: true
};
runTests(callback, options);
});
// Sets up the test projects and starts an iOS emulator
gulp.task("test-setup-ios", function (callback) {
var options = {
setup: true,
ios: true
};
runTests(callback, options);
});
// Sets up the test projects and starts both emulators
gulp.task("test-setup-both", function (callback) {
var options = {
setup: true,
android: true,
ios: true
};
runTests(callback, options);
});
// Builds, sets up test projects, and starts the Android emulator
gulp.task("test-setup-build-android", function (callback) {
runSequence("default", "test-setup-android", callback);
});
// Builds, sets up test projects, and starts the iOS emulator
gulp.task("test-setup-build-ios", function (callback) {
runSequence("default", "test-setup-ios", callback);
});
// Builds, sets up test projects, and starts both emulators
gulp.task("test-setup-build-both", function (callback) {
runSequence("default", "test-setup-both", callback);
});
////////////////////////////////////////////////////////////////////////
// Fast Test Tasks
//
// Runs tests but doesn't build or start emulators.
// Run on Android fast
gulp.task("test-android-fast", ["test-setup-android"], function (callback) {
runSequence("test-run-android", callback);
});
// Run on iOS fast
gulp.task("test-ios-fast", ["test-setup-ios"], function (callback) {
runSequence("test-run-ios", callback);
});
////////////////////////////////////////////////////////////////////////
// Fast Composition Test Tasks
//
// Run tests but doesn't build or start emulators.
// Run on iOS fast
gulp.task("test-fast", ["test-setup-both"], function (callback) {
runSequence("test-run-android", "test-run-ios", callback);
});
////////////////////////////////////////////////////////////////////////
// Test Tasks
//
// Run tests, build, and start emulators.
// Run on Android
gulp.task("test-android", ["test-setup-build-android"], function (callback) {
runSequence("test-run-android", callback);
});
// Run on iOS
gulp.task("test-ios", ["test-setup-build-ios"], function (callback) {
runSequence("test-run-ios", callback);
});
////////////////////////////////////////////////////////////////////////
// Composition Test Tasks
//
// Run tests, build, and start emulators.
// Run on Android and iOS
gulp.task("test", ["test-setup-build-both"], function (callback) {
runSequence("test-run-android", "test-run-ios", callback);
});