philhawksworth / netlify-plugin-form-submissions

Fetch all submissions made to Netlify Forms in your site and stash them as JSON files before your build runs making the data available to your static site generator at build time.
MIT License
2 stars 1 forks source link

Create `inputs.dataDirectory` if it does not exist #5

Open ehmicky opened 4 years ago

ehmicky commented 4 years ago

If the directory specified by inputs.dataDirectory does not exist, the following call will fail:

https://github.com/philhawksworth/netlify-plugin-form-submissions/blob/69dd463bd0a22600c695b0acc302ba54e542e67b/index.js#L18

ENOENT: no such file or directory, open 'src/_data/approved-comments_submissions.json' 
    fs.js:458:3 Object.openSync
    fs.js:1355:35 Object.writeFileSync
    /opt/build/repo/node_modules/netlify-plugin-form-submissions/index.js:18:12 getFormSubmissions
    internal/process/task_queues.js:97:5 processTicksAndRejections
    /opt/build/repo/node_modules/netlify-plugin-form-submissions/index.js:62:5 async onPreBuild
    src/plugins/child/run.js:13:3 async Object.run
    src/plugins/child/main.js:34:38 async handleEvent
    src/plugins/ipc.js:102:9 async process.<anonymous>

Deploy logs Bugsnag error

This could be fixed by creating the directory if it does not exist (e.g. with make-dir or similar library).