Reputation: 2954
Im using GruntJS with grunt-contrib-coffee. It works great! With the help of Watch plugin it is even better. But here comes my doubt:
I have two folders, one of then with my coffeescript files and another one with my (compiled) js files. Looks like this
root_folder
|--- public
|--- libs
|--- ppalmeida <= here are my .js compiled files from src_client coffeescripts
|--- controllers
|--- core
|--- Main.js
|--- models
|--- src_client <= here are my .coffee files
|--- controllers
|--- core
|--- Main.coffee
|--- models
When I build using coffee --output --compile
command, the folder structure is kept: Coffeescript cli compiles the "core" folder and inside the Main.js.
But when Im running GruntJS, it puts all files inside the same folder (ppalmeida). So the controllers, core, models files are thrown in the same folder, witch i dont want.
This is my glob_to_multiple
configs:
coffee:
glob_to_multiple:
expand: true,
flatten: true,
cwd: 'src_client/',
src: ['**/*.coffee'],
dest: 'public/ppalmeida/',
ext: '.js'
So, in the end i got something like this:
root_folder
|--- public
|--- libs
|--- ppalmeida <= here are my .js compiled files from src_client coffeescripts
|--- controllers (empty)
|--- core (empty)
|--- models (empty)
|--- Main.js
|--- ControllerA.js
|--- ControllerB.js
|--- ModelA.js
|--- all_other_js_files_here.js
|--- src_client <= here are my .coffee files
|--- controllers
|--- ControllerA.coffee
|--- ControllerB.coffee
|--- core
|--- Main.coffee
|--- models
|--- ModelA.coffee
|--- ModelA.coffee
So. Is there a way to compile with contrib-coffee and avoid all js files being put in the same folder?
Thank you all.
PS: i dont know if it helps, but here is my complete Gruntfile.coffee:
module.exports = (grunt) ->
# Grunt config object
config =
pkg: grunt.file.readJSON("package.json")
# Grunt must watch the src_client folder for modifications in its files and run coffee task when some file is changed/created
watch:
coffee:
files: 'src_client/**/*.coffee',
tasks: ['coffee']
# Create the 'coffee' task, to compile all *.coffee files to *.js
coffee:
glob_to_multiple:
expand: true,
flatten: true,
cwd: 'src_client/',
src: ['**/*.coffee'],
dest: 'public/ppalmeida/',
ext: '.js'
# Init grunt with config object
grunt.initConfig config
# Load grunt plugins
grunt.loadNpmTasks 'grunt-contrib-coffee'
grunt.loadNpmTasks 'grunt-contrib-watch'
# Register coffee as a default task:
grunt.registerTask 'default', ['coffee']
Upvotes: 1
Views: 1103
Reputation: 2954
Oh, now i got it. The answer was right in front of me: just change the "flatten" property to "false", so it will keep the paths of the files, so coffeescript will compile using it and the folders structure is kept:
# Create the 'coffee' task, to compile all *.coffee files to *.js
coffee:
glob_to_multiple:
expand: true,
flatten: false, #here, it must be false to keep folder structure when compiling
cwd: 'src_client/',
src: ['**/*.coffee'],
dest: 'public/ppalmeida/',
ext: '.js'
Hope it helps someone. Thank you.
Upvotes: 9