Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/ipfs-deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function main() {

const deployOptions = {
publicDirPath: argv.path,
copyPublicGatewayUrlToClipboard: !argv.noClipboard,
copyHttpGatewayUrlToClipboard: !argv.noClipboard,
open: !argv.O,
port: argv.port,
remotePinners: argv.p,
Expand Down
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ const neatFrame = require('neat-frame')
const { stripIndent } = require('common-tags')

// # Pure functions
function publicGatewayUrl(hash) {
return `https://ipfs.io/ipfs/${hash}`
function httpGatewayUrl(hash, gatewayProvider = 'ipfs') {
const gateways = {
ipfs: 'https://ipfs.io',
infura: 'https://ipfs.infura.io',
pinata: 'https://gateway.pinata.cloud',
}
const origin = gateways[gatewayProvider] || gateways['ipfs']
return `${origin}/ipfs/${hash}`
}

function formatError(e) {
Expand Down Expand Up @@ -300,17 +306,17 @@ async function addToInfura(publicDirPath) {
}
}

function copyUrlToClipboard(hash) {
function copyUrlToClipboard(url) {
const spinner = ora()
spinner.start('📋 Copying public gateway URL to clipboard…')
clipboardy.writeSync(publicGatewayUrl(hash))
spinner.succeed('📋 Copied public gateway URL to clipboard:')
spinner.info(`🔗 ${chalk.green(publicGatewayUrl(hash))}`)
spinner.start('📋 Copying HTTP gateway URL to clipboard…')
clipboardy.writeSync(url)
spinner.succeed('📋 Copied HTTP gateway URL to clipboard:')
spinner.info(`🔗 ${chalk.green(url)}`)
}

async function deploy({
publicDirPath,
copyPublicGatewayUrlToClipboard = false,
copyHttpGatewayUrlToClipboard = false,
open = false,
port = '4002',
remotePinners = ['infura'],
Expand Down Expand Up @@ -370,23 +376,24 @@ async function deploy({

if (successfulRemotePinners.length > 0) {
const pinnedHash = Object.values(pinnedHashes)[0]
const gatewayUrl = httpGatewayUrl(pinnedHash, successfulRemotePinners[0])
const isEqual = hash => hash === pinnedHash
if (!fp.every(isEqual)(Object.values(pinnedHashes))) {
const spinner = ora()
spinner.fail('≠ Found inconsistency in pinned hashes:')
logError(pinnedHashes)
}

if (copyPublicGatewayUrlToClipboard) {
copyUrlToClipboard(pinnedHash)
if (copyHttpGatewayUrlToClipboard) {
copyUrlToClipboard(gatewayUrl)
}

if (dnsProviders.includes('cloudflare')) {
await updateCloudflareDns(siteDomain, credentials.cloudflare, pinnedHash)
}

if (open && _.isEmpty(dnsProviders)) {
await openUrl(publicGatewayUrl(pinnedHash))
await openUrl(gatewayUrl)
}
if (open && !_.isEmpty(dnsProviders)) {
await openUrl(`https://${siteDomain}`)
Expand Down