@@ -24,10 +24,10 @@ if (!fs.existsSync(CLI_CACHE_PATH)) {
2424}
2525
2626const GITHUB_API_URL = 'https://api.github.com/repos/akamai/sandbox-client/releases/latest' ;
27- const SANDBOX_CLI_HOME = path . join ( CLI_CACHE_PATH , '/ sandbox-cli/ ' ) ;
28- const DOWNLOAD_DIR = path . join ( SANDBOX_CLI_HOME , '/ downloads/ ' ) ;
29- const SANDBOXES_DIR = path . join ( SANDBOX_CLI_HOME , '/ sandboxes/ ' ) ;
30- const DATASTORE_FILE_PATH = path . join ( SANDBOX_CLI_HOME + '.datastore' ) ;
27+ const SANDBOX_CLI_HOME = path . join ( CLI_CACHE_PATH , 'sandbox-cli' ) ;
28+ const DOWNLOAD_DIR = path . join ( SANDBOX_CLI_HOME , 'downloads' ) ;
29+ const SANDBOXES_DIR = path . join ( SANDBOX_CLI_HOME , 'sandboxes' ) ;
30+ const DATASTORE_FILE_PATH = path . join ( SANDBOX_CLI_HOME , '.datastore' ) ;
3131
3232let cachedGithubResponse : any | null = null ;
3333
@@ -82,7 +82,7 @@ async function findLatestJar(): Promise<{ path: string; version: string } | null
8282 'sandbox-client-*-RELEASE' ,
8383 'lib' ,
8484 'sandbox-client-*-RELEASE.jar'
85- ) ;
85+ ) . replace ( / \\ / g , '/' ) ;
8686
8787 const matches = await glob ( pattern ) ;
8888 if ( matches . length === 0 ) return null ;
@@ -151,11 +151,18 @@ export async function downloadClient() {
151151}
152152
153153
154- function unzipClient ( filePath :string ) {
155- const CLIENT_INSTALL_PATH = filePath . replace ( "download/" , '' ) . replace ( "-default.zip" , "" ) ;
154+ function unzipClient ( filePath : string ) {
155+ // Extract the version from the filename
156+ const match = filePath . match ( / s a n d b o x - c l i e n t - ( \d + \. \d + \. \d + ) - R E L E A S E - d e f a u l t \. z i p $ / ) ;
157+ if ( ! match ) {
158+ cliUtils . logAndExit ( 1 , `Could not determine client version from file name: ${ filePath } ` ) ;
159+ }
160+ const version = match [ 1 ] ;
161+ const CLIENT_INSTALL_PATH = path . join ( SANDBOX_CLI_HOME , `sandbox-client-${ version } -RELEASE` ) ;
156162 console . log ( `Installing to ${ CLIENT_INSTALL_PATH } ` ) ;
157- return decompress ( filePath , SANDBOX_CLI_HOME , {
158- filter : file => ! file . path . endsWith ( '/' ) // skip listing directories: https://github.com/kevva/decompress/issues/46
163+ // Filter out directories when decompressing. See https://github.com/kevva/decompress/issues/46
164+ return decompress ( filePath , CLIENT_INSTALL_PATH , {
165+ filter : file => ! file . path . endsWith ( '/' )
159166 } ) ;
160167}
161168
@@ -237,7 +244,7 @@ export function getSandboxLocalData(sandboxId: string) {
237244}
238245
239246function getLogPath ( ) {
240- return path . join ( getCurrentSandboxFolder ( ) , '/ logs' )
247+ return path . join ( getCurrentSandboxFolder ( ) , 'logs' )
241248}
242249
243250export function flushLocalSandbox ( sandboxId : string ) {
@@ -277,7 +284,10 @@ export async function executeSandboxClient(printLogs) {
277284 const loggingPath = getLogPath ( ) ;
278285 const loggingFilePath = path . join ( loggingPath , 'sandbox-client.log' ) ;
279286 const configPath = path . join ( getCurrentSandboxFolder ( ) , 'config.json' ) ;
280- const latestJar = ( await findLatestJar ( ) ) ! ;
287+ const latestJar = await findLatestJar ( ) ;
288+ if ( ! latestJar ) {
289+ cliUtils . logAndExit ( 1 , 'Unable to find Sandbox Client JAR file. Please try to reinstall sandbox-cli and contact support.' ) ;
290+ }
281291 const loggingConfigPath = path . join ( path . dirname ( path . dirname ( latestJar . path ) ) , 'conf' , 'logback.xml' ) ;
282292
283293 const springProfiles :string [ ] = [ ] ;
0 commit comments