diff --git a/src/commands/manifest/convert_gradle_to_maven.ts b/src/commands/manifest/convert_gradle_to_maven.ts index 685a7d448..b04cfd775 100644 --- a/src/commands/manifest/convert_gradle_to_maven.ts +++ b/src/commands/manifest/convert_gradle_to_maven.ts @@ -14,6 +14,7 @@ export async function convertGradleToMaven( ) { // Lazily access constants.spinner. const { spinner } = constants + const rbin = path.resolve(bin) const rtarget = path.resolve(target) @@ -29,10 +30,6 @@ export async function convertGradleToMaven( logger.groupEnd() } - spinner.start( - `Converting gradle to maven from \`${bin}\` on \`${target}\`...` - ) - try { // Run sbt with the init script we provide which should yield zero or more pom files. // We have to figure out where to store those pom files such that we can upload them and predict them through the GitHub API. @@ -43,8 +40,13 @@ export async function convertGradleToMaven( const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom'] if (verbose) { - spinner.log('[VERBOSE] Executing:', bin, commandArgs) + logger.log('[VERBOSE] Executing:', bin, commandArgs) } + + spinner.start( + `Converting gradle to maven from \`${bin}\` on \`${target}\`...` + ) + const output = await spawn(bin, commandArgs, { cwd: target || '.' }) @@ -64,7 +66,8 @@ export async function convertGradleToMaven( logger.error(output.stderr) logger.groupEnd() } - process.exit(1) + process.exitCode = 1 + return } logger.success('Executed gradle successfully') logger.log('Reported exports:') @@ -104,8 +107,7 @@ export async function convertGradleToMaven( // spinner.successAndStop(`OK. File should be available in \`${out}\``) // } } catch (e: any) { - spinner.stop() - logger.error( + spinner.errorAndStop( 'There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)') ) @@ -114,6 +116,8 @@ export async function convertGradleToMaven( logger.log(e) logger.groupEnd() } - process.exit(1) + process.exitCode = 1 + } finally { + spinner.stop() } } diff --git a/src/commands/manifest/convert_sbt_to_maven.ts b/src/commands/manifest/convert_sbt_to_maven.ts index ba720842c..ca896fcdf 100644 --- a/src/commands/manifest/convert_sbt_to_maven.ts +++ b/src/commands/manifest/convert_sbt_to_maven.ts @@ -32,9 +32,9 @@ export async function convertSbtToMaven( logger.groupEnd() } - spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`) - try { + spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`) + // Run sbt with the init script we provide which should yield zero or more // pom files. We have to figure out where to store those pom files such that // we can upload them and predict them through the GitHub API. We could do a @@ -59,7 +59,8 @@ export async function convertSbtToMaven( logger.error(output.stderr) logger.groupEnd() } - process.exit(1) + process.exitCode = 1 + return } const poms: string[] = [] output.stdout.replace(/Wrote (.*?.pom)\n/g, (_all: string, fn: string) => { @@ -70,7 +71,8 @@ export async function convertSbtToMaven( logger.error( 'There were no errors from sbt but it seems to not have generated any poms either' ) - process.exit(1) + process.exitCode = 1 + return } // Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout // TODO: what to do with multiple output files? Do we want to dump them to stdout? Raw or with separators or ? @@ -86,7 +88,8 @@ export async function convertSbtToMaven( ) poms.forEach(fn => logger.error('-', fn)) logger.error('Exiting now...') - process.exit(1) + process.exitCode = 1 + return } else { // if (verbose) { // logger.log( @@ -102,8 +105,7 @@ export async function convertSbtToMaven( logger.success(`OK`) } } catch (e: any) { - spinner.stop() - logger.error( + spinner?.errorAndStop( 'There was an unexpected error while running this' + (verbose ? '' : ' (use --verbose for details)') ) @@ -112,6 +114,8 @@ export async function convertSbtToMaven( logger.log(e) logger.groupEnd() } - process.exit(1) + process.exitCode = 1 + } finally { + spinner.stop() } }