Skip to content

Commit 2f07b6d

Browse files
committed
Merge pull request #31 from browserstack/jartoBinary
Jar to binary
2 parents 9e2118a + d9505b7 commit 2f07b6d

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

bin/runner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var BrowserStack = require('browserstack'),
55
utils = require('../lib/utils');
66
Server = require('../lib/server').Server;
77
config = require('../lib/config');
8-
Tunnel = require('../lib/tunnel').Tunnel;
8+
Tunnel = require('../lib/local').Tunnel;
99

1010
var serverPort = 8888;
1111
var tunnel;

lib/tunnel.js renamed to lib/local.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
var exec = require('child_process').exec,
22
fs = require('fs'),
33
http = require('http'),
4-
tunnelJar = __dirname + '/BrowserStackTunnel.jar',
4+
windows = (process.platform.match(/win/) != null),
5+
localBinary = __dirname + (windows ? '/BrowserStackTunnel.jar' : '/BrowserStackLocal'),
56
utils = require('./utils'),
67
config = require('./config');
78

8-
var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
9+
var Tunnel = function Tunnel (key, port, uniqueIdentifier, callback, err) {
910
var that = {};
1011

1112
function tunnelLauncher () {
12-
var tunnelCommand = 'java -jar ' + tunnelJar + ' ';
13+
var tunnelCommand = (windows ? 'java -jar ' : '') + localBinary + ' ';
1314
if (config.debug)
1415
tunnelCommand += ' -v ';
1516
tunnelCommand += key + ' ';
1617
tunnelCommand += 'localhost' + ',';
1718
tunnelCommand += port.toString() + ',';
1819
tunnelCommand += '0';
19-
tunnelCommand += (typeof tunnelIdentifier === 'undefined')? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + tunnelIdentifier;
20+
tunnelCommand += (typeof uniqueIdentifier === 'undefined')? ' -force -onlyAutomate' : ' -tunnelIdentifier ' + uniqueIdentifier;
2021

2122
if (typeof callback !== 'function') {
2223
callback = function () {};
2324
}
2425

25-
console.log("Launching tunnel");
26+
console.log("[%s] Launching tunnel", new Date());
2627
var subProcess = exec(tunnelCommand, function (error, stdout, stderr) {
2728
console.log(stderr);
29+
console.log(error);
2830
if (stdout.indexOf('Error') >= 0) {
29-
console.log("Tunnel launching failed");
31+
console.log("[%s] Tunnel launching failed", new Date());
3032
console.log(stdout);
3133
process.exit(1);
3234
}
@@ -38,8 +40,7 @@ var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
3840

3941
setTimeout(function () {
4042
if (!running) {
41-
utils.alertBrowserStack("Tunnel launch timeout",
42-
'Stdout:\n' + data);
43+
utils.alertBrowserStack("Tunnel launch timeout", 'Stdout:\n' + data);
4344
}
4445
}, 30 * 1000);
4546

@@ -52,28 +53,31 @@ var Tunnel = function Tunnel (key, port, tunnelIdentifier, callback, err) {
5253

5354
if (data.indexOf(runMatcher) >= 0) {
5455
running = true;
55-
console.log("Tunnel launched");
56+
console.log("[%s] Tunnel launched", new Date());
5657
callback();
5758
}
5859
});
5960

6061
that.process = subProcess;
6162
}
6263

63-
fs.exists(tunnelJar, function (exists) {
64+
fs.exists(localBinary, function (exists) {
6465
if (exists) {
65-
fs.unlinkSync(tunnelJar);
66+
fs.unlinkSync(localBinary);
67+
// tunnelLauncher();
68+
// return;
6669
}
67-
console.log('Downloading tunnel jar to `%s`', tunnelJar);
70+
console.log('Downloading BrowserStack Local to `%s`', localBinary);
6871

69-
var file = fs.createWriteStream(tunnelJar);
72+
var file = fs.createWriteStream(localBinary);
7073
var request = http.get(
71-
"http://www.browserstack.com/BrowserStackTunnel.jar",
74+
(windows ? "http://www.browserstack.com/BrowserStackTunnel.jar" : ("http://s3.amazonaws.com/browserStack/browserstack-local/BrowserStackLocal-" + process.platform + "-" + process.arch)),
7275
function(response) {
7376
response.pipe(file);
7477

7578
response.on('end', function () {
76-
tunnelLauncher();
79+
fs.chmodSync(localBinary, 0700);
80+
setTimeout(function() {tunnelLauncher();}, 100);
7781
});
7882
}
7983
);

lib/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var alertBrowserStack = function alertBrowserStack (subject, content, params, fn
3535
var urlObject = url.parse(endpoint);
3636

3737
var context = config.alert_context || "Runner alert";
38-
console.log("[%s] %s", context, subject);
38+
console.log("[%s] [%s] %s", new Date(), context, subject);
3939

4040
if (typeof fn !== 'function') {
4141
if (typeof params === 'function') {

0 commit comments

Comments
 (0)