cleanup Gruntfile by extracting executable code

This cleans up the Gruntfile by moving the nontrivial executable code out of it and into separate modules.