29
29
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
30
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
*/
32
+
32
33
'use strict' ;
33
- var fs = require ( 'fs' ) ;
34
34
35
- var async = require ( 'async' ) ;
36
- var debug = require ( 'debug' ) ( 'selenium-download:chromedriver:download' ) ;
37
- var fsExtra = require ( 'fs.extra' ) ;
38
- var AdmZip = require ( 'adm-zip' ) ;
39
- var _ = require ( 'lodash' ) ;
35
+ const fs = require ( 'fs' ) ;
36
+
37
+ const async = require ( 'async' ) ;
38
+ const debug = require ( 'debug' ) ( 'selenium-download:chromedriver:download' ) ;
39
+ const fsExtra = require ( 'fs.extra' ) ;
40
+ const AdmZip = require ( 'adm-zip' ) ;
41
+ const _ = require ( 'lodash' ) ;
40
42
41
- var downloadFile = require ( '../download' ) ;
42
- var validate = require ( '../checksum' ) ;
43
+ const downloadFile = require ( '../download' ) ;
44
+ const validate = require ( '../checksum' ) ;
43
45
44
- var copy = fsExtra . copy ;
45
- var move = fsExtra . move ;
46
+ const copy = fsExtra . copy ;
47
+ const move = fsExtra . move ;
46
48
47
- var extension = process . platform === 'win32' ? '.exe' : '' ;
49
+ const extension = process . platform === 'win32' ? '.exe' : '' ;
48
50
49
51
function unzip ( tempPath , filePath , callback ) {
50
- var tempFilePath = filePath + ' .tmp' ;
52
+ const tempFilePath = ` ${ filePath } .tmp` ;
51
53
52
54
function onMoved ( error ) {
53
- var zip ;
54
55
if ( error != null ) {
55
56
return callback ( error ) ;
56
57
}
57
- zip = new AdmZip ( tempFilePath ) ;
58
+ const zip = new AdmZip ( tempFilePath ) ;
58
59
zip . extractAllTo ( tempPath ) ;
59
60
fs . unlinkSync ( tempFilePath ) ;
60
61
return callback ( ) ;
@@ -64,7 +65,7 @@ function unzip(tempPath, filePath, callback) {
64
65
}
65
66
66
67
function isValidExecutable ( filename ) {
67
- var stat ;
68
+ let stat ;
68
69
try {
69
70
stat = fs . statSync ( filename ) ;
70
71
} catch ( err ) {
@@ -91,13 +92,13 @@ function copyReplace(source, dest, callback) {
91
92
}
92
93
93
94
function downloadChromeDriver ( binPath , tempPath , version , url , callback ) {
94
- var chromedriverPath = binPath + ' /chromedriver' ;
95
+ const chromedriverPath = ` ${ binPath } /chromedriver` ;
95
96
if ( isValidExecutable ( chromedriverPath ) ) {
96
97
debug ( 'already downloaded' , chromedriverPath ) ;
97
98
return callback ( ) ;
98
99
}
99
- var tempFileName = ' chromedriver_' + version ;
100
- var tempFilePath = tempPath + '/' + tempFileName ;
100
+ const tempFileName = ` chromedriver_${ version } ` ;
101
+ const tempFilePath = ` ${ tempPath } / ${ tempFileName } ` ;
101
102
102
103
function makeExecutable ( error ) {
103
104
if ( error != null ) {
@@ -115,13 +116,16 @@ function downloadChromeDriver(binPath, tempPath, version, url, callback) {
115
116
debug ( 'tmp file' , tempFilePath ) ;
116
117
debug ( 'target file' , chromedriverPath ) ;
117
118
118
- var unzippedFilePath = tempPath + '/chromedriver' + extension ;
119
- return async . waterfall ( [
120
- _ . partial ( downloadFile , url , tempPath , tempFileName ) ,
121
- _ . partial ( validate , tempFilePath ) ,
122
- _ . partial ( unzip , tempPath , tempFilePath ) ,
123
- _ . partial ( move , unzippedFilePath , tempFilePath ) ,
124
- _ . partial ( copyReplace , tempFilePath , chromedriverPath )
125
- ] , makeExecutable ) ;
119
+ const unzippedFilePath = `${ tempPath } /chromedriver${ extension } ` ;
120
+ return async . waterfall (
121
+ [
122
+ _ . partial ( downloadFile , url , tempPath , tempFileName ) ,
123
+ _ . partial ( validate , tempFilePath ) ,
124
+ _ . partial ( unzip , tempPath , tempFilePath ) ,
125
+ _ . partial ( move , unzippedFilePath , tempFilePath ) ,
126
+ _ . partial ( copyReplace , tempFilePath , chromedriverPath ) ,
127
+ ] ,
128
+ makeExecutable
129
+ ) ;
126
130
}
127
131
module . exports = downloadChromeDriver ;
0 commit comments