Reputation: 47626
I want my file/foder structure be clean on my website. So I don't want coffescript file be in the same folder as its compiled version.
While developing I'm using --watch key of compiler. I used this command before
coffee -cw ./ ./
which worked fine recursively for all coffeescript files when launching this from root of the website. But there is one problem - it puts compiled files in the same folder, which I try to avoid.
Is it possible to say to the compile - "please compile every coffeescript file and put compiled version in the parent folder"?
Update:
OK. A little bit of a clarification here. I.e. I have this folder structure
app
|- css
|- images
|- js
|- coffee
|- libs
|- controllers
|- coffee
|- services
|- coffee
|- loggers
|- coffee
As you can guessed I want to store all my coffeescript files inside coffee
folders, but compile them into the parent folder. E.g. I want to add one more logger, then I add newLogger.coffee
inside app/js/services/loggers/coffee and compiler compiles it and put newLogger.js
inside app/js/services/loggers.
I can use this command inside each coffee
folder
coffee -cw -o ../ ./
So, in this case with 4 coffee
folders I have 4 compiler instances running for each of them. Can I replace them with one instance?
Upvotes: 3
Views: 1090
Reputation: 3999
from coffeescript docs:
Compile a directory tree of .coffee files in src into a parallel tree of .js files in lib:
coffee --compile --output lib/ src/
Upvotes: 4
Reputation: 51480
You can do it with gruntjs task manager. With grunt you can specify any folder structure you want to maintain.
You can also add task to uglify all your js files after compilation.
Grunt is very useful for development, because it can watch your source files and recompile them after every change.
We're using it right now in our project to manage our front-end. Our task include:
.coffee
, .jade
and .less
files..js
and .css
files.Here's the example of gruntfile.coffee
which compiles, concatenates uglifies and deploys all .coffee
files from assets/js/
directory: https://gist.github.com/lbeschastny/5716323 (haven't tested it yet).
You can find more examples with the detailed instruction how to run them in getting started section of grunt site
Upvotes: 3
Reputation: 1982
see this link http://coffeescript.org/#usage
it says -o, --output [DIR] Write out all compiled JavaScript files into the specified directory. Use in conjunction with --compile or --watch.
hope it helps. :)
Upvotes: 1
Reputation: 25547
So, in this case with 4 coffee folders I have 4 compiler instances running for each of them. Can I replace them with one instance?
No. The Coffee compiler only supports changing the prefix of the directory path of the source to generate the output path; it does not support adding a suffix like ../
to it.
The coffee
command line utility is written in Coffescript and the source is very well documented, so you could modify it yourself to add the option you want. Easiest would be to simply change the meaning of the --output
option. (Although then you wouldn't be able to share the changes with the world, which would be a shame.) I think all you need to do is change:
dir = if opts.output then path.join opts.output, baseDir else srcDir
to:
dir = if opts.output then path.join baseDir, opts.output else srcDir
In the outputPath()
function: command.coffee line 261
Upvotes: 0
Reputation: 1870
you need to complete separate coffeescripts folder structure and compiled folder structure.
app
|- css
|- images
|- js
|- libs
|- controllers
|- services
|- loggers
This one will contain all coffee scripts.
app-src
|- js
|- controllers
|- services
|- loggers
Then compile at the root folder of both app and app-src coffee -cw app app-src
.
Upvotes: 0