@@ -52,27 +52,16 @@ function downloadTunnel (url, tunnelLocation, callback) {
52
52
} )
53
53
}
54
54
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 ) {
71
56
const args = [ ]
72
57
73
58
args . push ( '-jar' )
74
59
args . push ( tunnelLocation )
75
60
61
+ const optionMapping = {
62
+ 'tunnelIdentifier' : 'tunnel-identifier'
63
+ }
64
+
76
65
if ( options . apiKey ) {
77
66
args . push ( options . apiKey )
78
67
}
@@ -86,25 +75,36 @@ function run (options, callback) {
86
75
continue
87
76
}
88
77
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 } ` )
91
82
args . push ( options [ option ] )
92
- } else {
93
- args . push ( `--${ option } ` )
83
+ } else if ( options [ option ] ) {
84
+ args . push ( `--${ optionName } ` )
94
85
}
95
86
}
96
87
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
+ }
104
90
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
+ }
107
106
107
+ const readyFile = path . join ( os . tmpdir ( ) , 'testingbot.ready' )
108
108
const readyFileChecker = setInterval ( ( ) => {
109
109
fs . stat ( readyFile , ( error , stat ) => {
110
110
if ( ! error ) {
@@ -114,6 +114,18 @@ function run (options, callback) {
114
114
} )
115
115
} , 800 )
116
116
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
+
117
129
if ( options . verbose ) {
118
130
logger ( 'Starting tunnel with options' , args )
119
131
}
@@ -199,3 +211,4 @@ function downloadAndRun (options, callback) {
199
211
200
212
module . exports = downloadAndRun
201
213
module . exports . kill = killTunnel
214
+ module . exports . createArgs = createArgs
0 commit comments