From 35944cf94163c843f09ded29958a28e2baebdf4e Mon Sep 17 00:00:00 2001 From: yuetloo Date: Mon, 8 Jul 2024 12:54:11 -0400 Subject: [PATCH] create directory if not exist --- contracts/tasks/runners/exportImages.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/contracts/tasks/runners/exportImages.ts b/contracts/tasks/runners/exportImages.ts index 4a0b0585..7800a85a 100644 --- a/contracts/tasks/runners/exportImages.ts +++ b/contracts/tasks/runners/exportImages.ts @@ -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 @@ -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) } } @@ -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