Skip to content

Commit 525aeac

Browse files
committed
fix(bin): Handle no path arg when also can't guess
1 parent 24864e4 commit 525aeac

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

bin/ipfs-deploy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ async function main() {
119119
https://twitter.com/${chalk.whiteBright('agentofuser')}
120120
`)
121121
} else {
122-
await deploy(deployOptions)
122+
const pinnedHash = await deploy(deployOptions)
123+
if (!pinnedHash) {
124+
process.exit(1)
125+
}
123126
}
124127
}
125128

index.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ function guessPathIfEmpty(publicPath) {
100100
spinner.fail(
101101
`🔮 Couldn't guess what to deploy. Please specify a ${white('path')}.`
102102
)
103-
process.exit(1)
103+
return undefined
104104
}
105+
} else {
106+
return publicPath
105107
}
106108
}
107109

@@ -164,10 +166,11 @@ async function showSize(path) {
164166
const kibi = byteSize(size, { units: 'iec' })
165167
const readableSize = `${kibi.value} ${kibi.unit}`
166168
spinner.succeed(`🚚 ${chalk.blue(path)} weighs ${readableSize}.`)
169+
return readableSize
167170
} catch (e) {
168171
spinner.fail("⚖ Couldn't calculate website size.")
169172
logError(e)
170-
process.exit(1)
173+
return undefined
171174
}
172175
}
173176

@@ -326,7 +329,15 @@ async function deploy({
326329
} = {}) {
327330
publicDirPath = guessPathIfEmpty(publicDirPath)
328331

329-
await showSize(publicDirPath)
332+
if (!publicDirPath) {
333+
return undefined
334+
}
335+
336+
const readableSize = await showSize(publicDirPath)
337+
338+
if (!readableSize) {
339+
return undefined
340+
}
330341

331342
let successfulRemotePinners = []
332343
let pinnedHashes = {}
@@ -374,13 +385,16 @@ async function deploy({
374385
await updateCloudflareDns(siteDomain, credentials.cloudflare, pinnedHash)
375386
}
376387

377-
if (open && _.isEmpty(dnsProviders))
388+
if (open && _.isEmpty(dnsProviders)) {
378389
await openUrl(publicGatewayUrl(pinnedHash))
379-
if (open && !_.isEmpty(dnsProviders))
390+
}
391+
if (open && !_.isEmpty(dnsProviders)) {
380392
await openUrl(`https://${siteDomain}`)
393+
}
394+
return pinnedHash
381395
} else {
382396
logError('Failed to deploy.')
383-
process.exit(1)
397+
return undefined
384398
}
385399
}
386400

0 commit comments

Comments
 (0)