@@ -52,27 +52,16 @@ function downloadTunnel (url, tunnelLocation, callback) {
5252 } )
5353}
5454
55- function run ( options , callback ) {
56- if ( ! fs . existsSync ( tunnelLocation ) ) {
57- return callback ( new Error ( `Tunnel jar file is not present in ${ tunnelLocation } ` ) )
58- }
59-
60- const checkJava = spawn ( 'java' )
61- checkJava . on ( 'error' , err => {
62- return callback ( new Error ( `Java might not be installed, necessary to use testingbot-tunnel ${ err . message } ` ) )
63- } )
64-
65- const onReady = function ( ) {
66- started = true
67- logger ( 'Tunnel is ready' )
68- callback ( null , activeTunnel )
69- }
70-
55+ function createArgs ( options ) {
7156 const args = [ ]
7257
7358 args . push ( '-jar' )
7459 args . push ( tunnelLocation )
7560
61+ const optionMapping = {
62+ 'tunnelIdentifier' : 'tunnel-identifier'
63+ }
64+
7665 if ( options . apiKey ) {
7766 args . push ( options . apiKey )
7867 }
@@ -86,25 +75,36 @@ function run (options, callback) {
8675 continue
8776 }
8877
89- if ( options [ option ] ) {
90- args . push ( `--${ option } ` )
78+ const optionName = optionMapping [ option ] || option
79+
80+ if ( options [ option ] && typeof ( options [ option ] ) === 'string' ) {
81+ args . push ( `--${ optionName } ` )
9182 args . push ( options [ option ] )
92- } else {
93- args . push ( `--${ option } ` )
83+ } else if ( options [ option ] ) {
84+ args . push ( `--${ optionName } ` )
9485 }
9586 }
9687
97- const readyFile = path . join ( os . tmpdir ( ) , 'testingbot.ready' )
98- try {
99- if ( fs . statSync ( readyFile ) . isFile ( ) ) {
100- logger ( 'Tunnel Readyfile already exists, removing' )
101- fs . unlinkSync ( readyFile )
102- }
103- } catch ( ignore ) { }
88+ return args
89+ }
10490
105- args . push ( `-f` )
106- args . push ( readyFile )
91+ function run ( options , callback ) {
92+ if ( ! fs . existsSync ( tunnelLocation ) ) {
93+ return callback ( new Error ( `Tunnel jar file is not present in ${ tunnelLocation } ` ) )
94+ }
95+
96+ const checkJava = spawn ( 'java' )
97+ checkJava . on ( 'error' , err => {
98+ return callback ( new Error ( `Java might not be installed, necessary to use testingbot-tunnel ${ err . message } ` ) )
99+ } )
100+
101+ const onReady = function ( ) {
102+ started = true
103+ logger ( 'Tunnel is ready' )
104+ callback ( null , activeTunnel )
105+ }
107106
107+ const readyFile = path . join ( os . tmpdir ( ) , 'testingbot.ready' )
108108 const readyFileChecker = setInterval ( ( ) => {
109109 fs . stat ( readyFile , ( error , stat ) => {
110110 if ( ! error ) {
@@ -114,6 +114,18 @@ function run (options, callback) {
114114 } )
115115 } , 800 )
116116
117+ const args = createArgs ( options )
118+
119+ try {
120+ if ( fs . statSync ( readyFile ) . isFile ( ) ) {
121+ logger ( 'Tunnel Readyfile already exists, removing' )
122+ fs . unlinkSync ( readyFile )
123+ }
124+ } catch ( ignore ) { }
125+
126+ args . push ( `-f` )
127+ args . push ( readyFile )
128+
117129 if ( options . verbose ) {
118130 logger ( 'Starting tunnel with options' , args )
119131 }
@@ -199,3 +211,4 @@ function downloadAndRun (options, callback) {
199211
200212module . exports = downloadAndRun
201213module . exports . kill = killTunnel
214+ module . exports . createArgs = createArgs
0 commit comments