Refactor write code out of cmd.

This will allow others to use watchify as a library for the purpose of,
say, creating a grunt plugin.