Skip to content

Commit 38e4fd0

Browse files
07souravkundafrancisf
authored andcommitted
remove redundant methods
1 parent b08bb00 commit 38e4fd0

File tree

2 files changed

+9
-49
lines changed

2 files changed

+9
-49
lines changed

lib/Local.js

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Local(){
3434
if(typeof options['onlyCommand'] !== 'undefined')
3535
return;
3636

37-
const binaryPath = this.getBinaryPathSync();
37+
const binaryPath = this.getBinaryPath();
3838
that.binaryPath = binaryPath;
3939
childProcess.exec('echo "" > ' + that.logfile);
4040
that.opcode = 'start';
@@ -236,21 +236,6 @@ function Local(){
236236
}
237237
};
238238

239-
this.getBinaryPathSync = function(){
240-
if(typeof(this.binaryPath) == 'undefined'){
241-
this.binary = new LocalBinary();
242-
var conf = {};
243-
if(this.proxyHost && this.proxyPort){
244-
conf.proxyHost = this.proxyHost;
245-
conf.proxyPort = this.proxyPort;
246-
}
247-
return this.binary.binaryPathSync(conf);
248-
} else {
249-
console.log('BINARY PATH IS DEFINED');
250-
return this.binaryPath;
251-
}
252-
}
253-
254239
this.getBinaryPath = function(callback){
255240
if(typeof(this.binaryPath) == 'undefined'){
256241
this.binary = new LocalBinary();
@@ -259,10 +244,10 @@ function Local(){
259244
conf.proxyHost = this.proxyHost;
260245
conf.proxyPort = this.proxyPort;
261246
}
262-
this.binary.binaryPath(conf, callback);
247+
return callback ? this.binary.binaryPath(conf, callback) : this.binary.binaryPath(conf);
263248
} else {
264249
console.log('BINARY PATH IS DEFINED');
265-
callback(this.binaryPath);
250+
return callback ? callback(this.binaryPath) : this.binaryPath;
266251
}
267252
};
268253

lib/LocalBinary.js

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,7 @@ function LocalBinary(){
3939

4040
this.httpPath = this.getDownloadPath();
4141

42-
this.retryBinaryDownloadSync = function(conf, destParentDir, retries, binaryPath){
43-
var that = this;
44-
if(retries > 0) {
45-
console.log('Retrying Download. Retries left', retries);
46-
try {
47-
const stats = fs.statSync(binaryPath)
48-
fs.unlinkSync(binaryPath);
49-
} catch(er) {}
50-
51-
that.downloadSync(conf, destParentDir, retries - 1)
5242

53-
} else {
54-
console.error('Number of retries to download exceeded.');
55-
}
56-
}
5743

5844
this.retryBinaryDownload = function(conf, destParentDir, callback, retries, binaryPath) {
5945
var that = this;
@@ -63,7 +49,7 @@ function LocalBinary(){
6349
if(err == null) {
6450
fs.unlinkSync(binaryPath);
6551
}
66-
that.download(conf, destParentDir, callback, retries - 1);
52+
return callback ? that.download(conf, destParentDir, callback, retries - 1) : that.downloadSync(conf, destParentDir, retries - 1);
6753
});
6854
} else {
6955
console.error('Number of retries to download exceeded.');
@@ -118,19 +104,19 @@ function LocalBinary(){
118104
}
119105
if(output.includes('failed')){
120106
console.log('failed to download');
121-
that.retryBinaryDownloadSync(conf, destParentDir, retries, binaryPath);
107+
return that.retryBinaryDownload(conf, destParentDir, null, retries, binaryPath);
122108
}else{
123109
if(fs.existsSync(binaryPath)){
124110
fs.chmodSync(binaryPath, '0755')
125111
return binaryPath;
126112
}else{
127113
console.log('failed to download');
128-
that.retryBinaryDownloadSync(conf, destParentDir, retries, binaryPath);
114+
return that.retryBinaryDownload(conf, destParentDir, null, retries, binaryPath);
129115
}
130116
}
131117
} catch(err) {
132118
console.log('Download failed with error', err);
133-
that.retryBinaryDownloadSync(conf, destParentDir, retries, binaryPath);
119+
return that.retryBinaryDownload(conf, destParentDir, null, retries, binaryPath);
134120
}
135121
}
136122

@@ -172,25 +158,14 @@ function LocalBinary(){
172158
});
173159
};
174160

175-
this.binaryPathSync = function(conf){
176-
var destParentDir = this.getAvailableDirs();
177-
var destBinaryName = (this.windows) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal';
178-
var binaryPath = path.join(destParentDir, destBinaryName);
179-
if(this.checkPath(binaryPath, fs.X_OK)){
180-
return binaryPath;
181-
} else {
182-
return this.downloadSync(conf, destParentDir, 5);
183-
}
184-
}
185-
186161
this.binaryPath = function(conf, callback){
187162
var destParentDir = this.getAvailableDirs();
188163
var destBinaryName = (this.windows) ? 'BrowserStackLocal.exe' : 'BrowserStackLocal';
189164
var binaryPath = path.join(destParentDir, destBinaryName);
190165
if(this.checkPath(binaryPath, fs.X_OK)){
191-
callback(binaryPath);
166+
return callback ? callback(binaryPath) : binaryPath;
192167
} else {
193-
this.download(conf, destParentDir, callback, 5);
168+
return callback ? this.download(conf, destParentDir, callback, 5) : this.downloadSync(conf, destParentDir, 5);
194169
}
195170
};
196171

0 commit comments

Comments
 (0)