Many coffee source files in /assets/src/coffee
etc (./child/paths
and so on) and I'd like to output them to assets/js/
and assets/js/child/paths
.
It looks like I've gotten close, but it's not working. Using grunt-contrib-coffee
and grunt-contrib-watch
.
grunt.initConfig
watch:
coffee:
files: '<%= coffee.src %>',
tasks: 'coffee:dev'
options:
nospawn: true
coffee:
src: 'assets/src/coffee/**/*.coffee'
dev:
options:
sourceMap: true
files: [
expand: true
cwd: "assets/"
src: "/src/coffee/**/*.coffee"
dest: "../js/"
ext: ".js"
]
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks 'grunt-contrib-watch'
# Default task.
grunt.registerTask "default", "watch"
grunt.event.on('watch', (action, filepath) ->
(grunt.log.writeln('\n'+ filepath + ' has ' + action))
dest = "#{path.dirname(filepath.replace("src/coffee", "js"))}"
grunt.config(['coffee', 'dev', 'files', 'src'], [filepath])
grunt.config(['coffee', 'dev', 'files', 'dest'], [dest])
(grunt.log.writeln("src: #{grunt.config(['coffee', 'dev', 'files', 'src'])}"))
(grunt.log.writeln("dest: #{grunt.config(['coffee', 'dev', 'files', 'dest'])}"))
)
Ok, so the output of that looks like:
assets/src/coffee/projAlpha/dl.coffee has changed
src: assets/src/coffee/projAlpha/dl.coffee
dest: assets/js/projAlpha/dl.coffee
but the file actually ends up in: assets/src/coffee/projAlpha/dl.coffee
... and it's coffee script. It should be in assets/js/projAlpha/dl.js
.
I've gotten the grunt coffee utility to compile all the files at once and put them in the right place. I'd rather they got compiled one at a time though, since I've got a few files now and am adding more all the time.