Skip to content

Commit

Permalink
Merge pull request #11 from StauroDEV/fix-bugs
Browse files Browse the repository at this point in the history
fix: bugs
  • Loading branch information
talentlessguy authored Nov 27, 2023
2 parents e846935 + 8f2a34c commit 766dbf4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
20 changes: 12 additions & 8 deletions src/actions/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path'
import { PROVIDERS } from '../constants.js'
import { PROVIDERS, isTTY } from '../constants.js'
import { MissingDirectoryError, NoProvidersError } from '../errors.js'
import { walk, fileSize, packCAR, parseTokensFromEnv, tokensToProviderNames, findEnvVarProviderName } from '../index.js'
import { exists } from '../utils/fs.js'
Expand Down Expand Up @@ -36,13 +36,14 @@ export const deployAction = async (
const [size, files] = await walk(normalizedPath)

if (size === 0) throw new MissingDirectoryError(dir)
const distName = ['.', 'dist'].includes(dir) ? name : dir

logger.start(`Packing ${colors.cyan(dir === '.' ? name : dir)} (${fileSize(size, 2)})`)
logger.start(`Packing ${isTTY ? colors.cyan(distName) : distName} (${fileSize(size, 2)})`)

const { rootCID, blob } = await packCAR(files, name, dist)

const cid = rootCID.toString()
logger.info(`Root CID: ${colors.white(cid)}`)
logger.info(`Root CID: ${isTTY ? colors.white(cid) : cid}`)

const apiTokens = parseTokensFromEnv()

Expand All @@ -54,7 +55,7 @@ export const deployAction = async (

let total = 0

const bar = process.stdout.isTTY
const bar = isTTY
? new AsciiBar({
total: providers.length,
formatString: '#spinner #bar #message',
Expand Down Expand Up @@ -102,11 +103,14 @@ export const deployAction = async (
}
else logger.success('Deployed across all providers')

const dwebLink = `https://${cid}.ipfs.dweb.link`
const ipfsScanLink = `https://ipfs-scan.io/?cid=${cid}`

console.log(
`\nOpen in a browser:\n${colors.bold('IPFS')}: ${colors.underline(
`https://${cid}.ipfs.dweb.link`,
)}\n${colors.bold('IPFS Scan')}: ${colors.underline(
`https://ipfs-scan.io/?cid=${cid}`,
`\nOpen in a browser:\n${isTTY ? colors.bold('IPFS') : 'IPFS'}: ${colors.underline(
isTTY ? colors.underline(dwebLink) : dwebLink,
)}\n${isTTY ? colors.bold('IPFS Scan') : 'IPFS Scan'}: ${colors.underline(
isTTY ? colors.underline(ipfsScanLink) : ipfsScanLink,
)}`,
)

Expand Down
10 changes: 7 additions & 3 deletions src/actions/ens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { ApiClient } from '@stauro/piggybank/api'
import { chainIdToSafeApiUrl } from '../utils/safe.js'
import * as colors from 'colorette'
import { logger } from '../utils/logger.js'
import { isTTY } from '../constants.js'

export const ensAction = async (
cid: string,
Expand Down Expand Up @@ -129,8 +130,10 @@ export const ensAction = async (
chainId: chain.id,
origin: 'Piggybank',
})
// eslint-disable-next-line @stylistic/max-len
logger.success(`Transaction proposed to a Safe wallet.\nOpen in a browser: ${colors.underline(`https://app.safe.global/transactions/queue?safe=${safeAddress}`)}`)
const safeLink = `https://app.safe.global/transactions/queue?safe=${safeAddress}`
logger.success(`Transaction proposed to a Safe wallet.\nOpen in a browser: ${
isTTY ? colors.underline(safeLink) : safeLink
}`)
}
catch (e) {
logger.error('Failed to propose a transaction', e)
Expand Down Expand Up @@ -168,7 +171,8 @@ export const ensAction = async (
if (receipt.status === 'reverted') return logger.error('Transaction reverted')

logger.success('Transaction submitted')
logger.info(`Open in a browser: ${colors.underline(`https://${domain}.limo`)}`)
const browserLink = `https://${domain}.limo`
logger.info(`Open in a browser: ${isTTY ? colors.underline(browserLink) : browserLink}`)
}
return process.exit()
}
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ string,
supported: 'both',
},
}

export const isTTY = process.stdout.isTTY
4 changes: 2 additions & 2 deletions src/providers/gw3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const mapGw3StatusToGenericStatus = (status: GW3PinStatus): PinStatus => {
const baseURL = 'https://gw3.io'
const providerName = 'Gateway3'

export const uploadOnGW3: UploadFunction = async ({ token, car, cid, accessKey, first, verbose }) => {
export const uploadOnGW3: UploadFunction = async ({ token, car, cid, accessKey, first, name, verbose }) => {
if (!accessKey) throw new MissingKeyError('GW3_ACCESS_KEY')
if (first) {
const res1 = await fetch(
Expand Down Expand Up @@ -63,7 +63,7 @@ export const uploadOnGW3: UploadFunction = async ({ token, car, cid, accessKey,
}

const res = await fetch(
new URL(`/api/v0/pin/add?arg=${cid}&ts=${getTs()}`, baseURL),
new URL(`/api/v0/pin/add?arg=${cid}&ts=${getTs()}&name=${name}`, baseURL),
{
method: 'POST',
headers: {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bgGreen, bgRed, bgYellow, cyan, green } from 'colorette'
import { SupportedMethods } from '../types.js'
import { isTTY } from '../constants.js'

const responseStatus = (status: number) => {
if (status < 300) return bgGreen(status)
Expand All @@ -12,7 +13,7 @@ export const logger = {
console.log('📦', ...args)
},
info(...args: unknown[]) {
console.info('🛈 ', ...args)
console.info('🟢 ', ...args)
},
error(...args: unknown[]) {
console.error('🚨', ...args)
Expand All @@ -24,7 +25,8 @@ export const logger = {
console.log('✔', ...args)
},
request(method: 'GET' | 'POST' | 'PUT', url: string, status: number) {
console.log('\n', method === 'GET' ? cyan(method) : green(method), url, responseStatus(status))
if (isTTY) console.log('\n', method === 'GET' ? cyan(method) : green(method), url, responseStatus(status))
else console.log('\n', method, url, status)
},
}

Expand Down

0 comments on commit 766dbf4

Please sign in to comment.