segmentio/metalsmith — pull request #80 by mayo (2014-09-03 22:28:27+00:00)
Title: Clean directories at build() instead of write()

I've ran into issues where plugins generate contents in the build directory, only to have the `write()` function clean up the build directory and generate more content. While this can be solved by disabling the core `clean()` and a "clean" plugin, it seems more reasonable to clean up the build directory at the beginning of a build before any plugins execute, rather than mid-execution of a build (in `write()`).

The impact of moving the cleanup code from `write()` to `build()` doesn't seem that significant change to the core.

I've used this change for about a week now with number of plugins, and all seems to work well. One exception is metalsmith-static plugin, which expects the build directory to exist. This however, is a use case which was not handled by the plugin in case the user did `rm -rf build` manually. I've addressed this issue with the plugin author and created a pull request there as well.

There was a discussion started in issue https://github.com/segmentio/metalsmith/issues/78, but this is perhaps better venue for discussing this change.