Skip to content

Commit

Permalink
Merge pull request #48 from DarkFlorist/folder-exists
Browse files Browse the repository at this point in the history
check that folder exists before creating
  • Loading branch information
KillariDev authored Sep 16, 2024
2 parents ac4435e + 35cac52 commit b235e28
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion solidity/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ import { promises as fs } from 'fs'
import path = require('path')
import { compile } from 'solc'

async function exists(path: string) {
try {
await fs.stat(path)
return true
} catch {
return false
}
}

const compilePetalLock = async () => {
const input = {
language: 'Solidity',
Expand All @@ -24,7 +33,7 @@ const compilePetalLock = async () => {

var output = compile(JSON.stringify(input))
const artifactsDir = path.join(process.cwd(), 'artifacts')
await fs.mkdir(artifactsDir, { recursive: false })
if (!exists(artifactsDir)) await fs.mkdir(artifactsDir, { recursive: false })
fs.writeFile('artifacts/PetalLock.json', output)
}

Expand Down

0 comments on commit b235e28

Please sign in to comment.