Skip to content

Commit

Permalink
fix: cleanup on aborted init
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Apr 9, 2021
1 parent dcc8ab4 commit 111303e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ignore from 'ignore'
export default {
name: 'init',
run: async ({
filesystem: { append, read, exists },
filesystem: { append, read, exists, remove },
template: { generate },
print: {
colors: { highlight },
Expand All @@ -20,6 +20,13 @@ export default {
process.exit(1)
}

// Cleanup on Ctrl+C
process.on('SIGINT', () => {
remove('.supabase')
error(`Aborted ${highlight('supabase init')}.`)
process.exit(1)
})

const dockerCompose = which('docker-compose')
if (!dockerCompose) {
error(`Cannot find ${highlight('docker-compose')} executable in PATH.`)
Expand Down Expand Up @@ -78,15 +85,18 @@ export default {
},
})
)
).catch(() => {
spinner.fail('Error writing Docker setup files.')
).catch((err) => {
remove('.supabase')
spinner.fail(`Error writing Docker setup files: ${err.message}`)
process.exit(1)
})

await run(
'docker-compose --file .supabase/docker/docker-compose.yml build --no-cache && docker-compose --file .supabase/docker/docker-compose.yml --project-name supabase up --no-start --renew-anon-volumes'
).catch(() => {
spinner.fail('Error running docker-compose.')
'docker-compose --file .supabase/docker/docker-compose.yml build --no-cache && docker-compose --file .supabase/docker/docker-compose.yml --project-name supabase up --no-start --renew-anon-volumes',
{ trim: true }
).catch((err) => {
remove('.supabase')
spinner.fail(`Error running docker-compose: ${err.stderr}`)
process.exit(1)
})

Expand Down

0 comments on commit 111303e

Please sign in to comment.