check whether the folder exists before attempting to create it, avoiding exception

This commit is contained in:
Tom Wells 2020-04-21 10:34:07 +02:00
parent 7cd64f7337
commit c49fda2951

View File

@ -37,7 +37,7 @@ const listFiles = (dir) =>
[])
const ensureDirectory = (dir) =>
fs.mkdirSync(dir, { recursive: true })
fs.existsSync(dir) || fs.mkdirSync(dir, { recursive: true })
const saveToFolder = (prefix) => ({ filepath, content }) =>
fs.writeFileSync(path.join(prefix, filepath), content, { encoding: 'utf8' })