Skip to content

Commit 11d718b

Browse files
authored
Manifest: Better handling of spinner and exit (#353)
1 parent 9a5a4f8 commit 11d718b

File tree

2 files changed

+25
-17
lines changed

2 files changed

+25
-17
lines changed

src/commands/manifest/convert_gradle_to_maven.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function convertGradleToMaven(
1414
) {
1515
// Lazily access constants.spinner.
1616
const { spinner } = constants
17+
1718
const rbin = path.resolve(bin)
1819
const rtarget = path.resolve(target)
1920

@@ -29,10 +30,6 @@ export async function convertGradleToMaven(
2930
logger.groupEnd()
3031
}
3132

32-
spinner.start(
33-
`Converting gradle to maven from \`${bin}\` on \`${target}\`...`
34-
)
35-
3633
try {
3734
// Run sbt with the init script we provide which should yield zero or more pom files.
3835
// 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(
4340
const commandArgs = ['--init-script', initLocation, ...gradleOpts, 'pom']
4441

4542
if (verbose) {
46-
spinner.log('[VERBOSE] Executing:', bin, commandArgs)
43+
logger.log('[VERBOSE] Executing:', bin, commandArgs)
4744
}
45+
46+
spinner.start(
47+
`Converting gradle to maven from \`${bin}\` on \`${target}\`...`
48+
)
49+
4850
const output = await spawn(bin, commandArgs, {
4951
cwd: target || '.'
5052
})
@@ -64,7 +66,8 @@ export async function convertGradleToMaven(
6466
logger.error(output.stderr)
6567
logger.groupEnd()
6668
}
67-
process.exit(1)
69+
process.exitCode = 1
70+
return
6871
}
6972
logger.success('Executed gradle successfully')
7073
logger.log('Reported exports:')
@@ -104,8 +107,7 @@ export async function convertGradleToMaven(
104107
// spinner.successAndStop(`OK. File should be available in \`${out}\``)
105108
// }
106109
} catch (e: any) {
107-
spinner.stop()
108-
logger.error(
110+
spinner.errorAndStop(
109111
'There was an unexpected error while running this' +
110112
(verbose ? '' : ' (use --verbose for details)')
111113
)
@@ -114,6 +116,8 @@ export async function convertGradleToMaven(
114116
logger.log(e)
115117
logger.groupEnd()
116118
}
117-
process.exit(1)
119+
process.exitCode = 1
120+
} finally {
121+
spinner.stop()
118122
}
119123
}

src/commands/manifest/convert_sbt_to_maven.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ export async function convertSbtToMaven(
3232
logger.groupEnd()
3333
}
3434

35-
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`)
36-
3735
try {
36+
spinner.start(`Converting sbt to maven from \`${bin}\` on \`${target}\`...`)
37+
3838
// Run sbt with the init script we provide which should yield zero or more
3939
// pom files. We have to figure out where to store those pom files such that
4040
// we can upload them and predict them through the GitHub API. We could do a
@@ -59,7 +59,8 @@ export async function convertSbtToMaven(
5959
logger.error(output.stderr)
6060
logger.groupEnd()
6161
}
62-
process.exit(1)
62+
process.exitCode = 1
63+
return
6364
}
6465
const poms: string[] = []
6566
output.stdout.replace(/Wrote (.*?.pom)\n/g, (_all: string, fn: string) => {
@@ -70,7 +71,8 @@ export async function convertSbtToMaven(
7071
logger.error(
7172
'There were no errors from sbt but it seems to not have generated any poms either'
7273
)
73-
process.exit(1)
74+
process.exitCode = 1
75+
return
7476
}
7577
// Move the pom file to ...? initial cwd? loc will be an absolute path, or dump to stdout
7678
// 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(
8688
)
8789
poms.forEach(fn => logger.error('-', fn))
8890
logger.error('Exiting now...')
89-
process.exit(1)
91+
process.exitCode = 1
92+
return
9093
} else {
9194
// if (verbose) {
9295
// logger.log(
@@ -102,8 +105,7 @@ export async function convertSbtToMaven(
102105
logger.success(`OK`)
103106
}
104107
} catch (e: any) {
105-
spinner.stop()
106-
logger.error(
108+
spinner?.errorAndStop(
107109
'There was an unexpected error while running this' +
108110
(verbose ? '' : ' (use --verbose for details)')
109111
)
@@ -112,6 +114,8 @@ export async function convertSbtToMaven(
112114
logger.log(e)
113115
logger.groupEnd()
114116
}
115-
process.exit(1)
117+
process.exitCode = 1
118+
} finally {
119+
spinner.stop()
116120
}
117121
}

0 commit comments

Comments
 (0)