Skip to content

Commit

Permalink
create directory if not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jul 8, 2024
1 parent cb13f11 commit 35944cf
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions contracts/tasks/runners/exportImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { task } from 'hardhat/config'
import { isPathExist, makeDirectory } from '../../utils/misc'
import { getIpfsContent } from '@clrfund/common'
import fs from 'fs'
import { dirname } from 'path'

/**
* Download the IPFS file with the ipfsHash to the output directory
Expand All @@ -36,7 +37,13 @@ async function download({
const res = await getIpfsContent(ipfsHash, gateway)
if (res.hasBody()) {
console.log('Downloaded', ipfsHash)
fs.writeFileSync(`${outputDir}/${ipfsHash}`, res.body)
const path = `${outputDir}/${ipfsHash}`
const folder = dirname(path)
if (!isPathExist(folder)) {
makeDirectory(folder)
}

fs.writeFileSync(path, res.body)
}
}

Expand All @@ -47,10 +54,6 @@ task('export-images', 'Export project logo images')
.setAction(async ({ outputDir, roundFile, gateway }) => {
console.log('Starting to download from ipfs')

if (!isPathExist(outputDir)) {
makeDirectory(outputDir)
}

const data = fs.readFileSync(roundFile, { encoding: 'utf-8' })
const round = JSON.parse(data)
const projects = round.projects
Expand Down

0 comments on commit 35944cf

Please sign in to comment.