futurice / metalsmith-prismic-server

npm app package for running on Heroku or similar to compile and deploy content for sites built with metalsmith-prismic-template
MIT License
4 stars 4 forks source link

Cleanup fix #18

Closed ds300 closed 8 years ago

ds300 commented 8 years ago

readdirSync throws errors if the path doesn't exist. Let's make sure the path exists before calling it.

fs.js:808
  return binding.readdir(pathModule._makeLong(path));
    at Error (native)
    at Object.fs.readdirSync (fs.js:808:18)
    at module.exports.cb (/app/node_modules/metalsmith-prismic-server/src/remove-old-dirs.js:13:6)
                 ^
    at null._repeat (/app/node_modules/metalsmith-prismic-server/src/prod-server.js:91:7)
Error: ENOENT: no such file or directory, scandir '/app/builds/preview'

    at wrapper [as _onTimeout] (timers.js:275:19)
...

Also, added a cleanupInterval option so one can configure how frequently the cleanups occur independently of the preview expiration age.