Last active
December 18, 2015 16:09
-
-
Save henrahmagix/5809771 to your computer and use it in GitHub Desktop.
Delete compiled JS files when the source Coffee file gets deleted on a grunt watch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (grunt) -> | |
coffeeDir = 'coffee/' | |
jsDir = 'project/' | |
grunt.initConfig | |
coffee: | |
project: | |
expand: true | |
cwd: coffeeDir | |
src: ['*.coffee', '**/*.coffee'] | |
dest: jsDir | |
ext: '.js' | |
options: | |
bare: true | |
watch: | |
coffee: | |
files: ['coffee/*.coffee', 'coffee/**/*.coffee'] | |
tasks: ['coffee'] | |
grunt.event.on 'watch', (action, filepath) -> | |
# Delete compiled .js file of deleted source .coffee file. | |
if action == 'deleted' and grunt.file.exists jsFile | |
filepath = filepath.replace coffeeDir, '' | |
jsFile = jsDir + filepath.replace /\.coffee$/, '.js' | |
grunt.file.delete jsFile | |
grunt.log.ok 'File ' + jsFile + ' deleted' | |
grunt.loadNpmTasks task for task in ['grunt-contrib-coffee', 'grunt-contrib-watch'] | |
grunt.registerTask 'default', ['watch'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment