0

I would like to append new .coffee files to a single .js file.

Right now my project structure is

coffee /

--controllers /

----Ajax.coffee

--views /

----Login.coffee

--app.coffee

The file app.coffee was created first, but when I created Ajax.coffee the code got prepended to the app.js file, because it is higher in the structure. Is there a way to append the code instead? I really want to use a compile-to-single file rather than loading loads of files with requires, but the code prepending makes it a pain in the ass.

I am using PHPStorm and it's watchers.

Foxhoundn
  • 1,766
  • 2
  • 13
  • 19
  • 1
    Sounds like you should look into browserify. A quick google gave me this: https://github.com/jnordberg/coffeeify –  May 25 '15 at 21:47

2 Answers2

1

You can use grunt as a build tool to structure a project like yours. Grunt can be configured to watch, compile, minify, uglify, test and even run your code automatically on change. The initial learning curve might be a bit steep, but you will never look back.

http://gruntjs.com/

Exinferis
  • 689
  • 7
  • 17
  • Grunt is just a watcher and compiler, it doesn't say anywhere that it does what I need it to do, append the code based on the time of the file creation rather than structure in the project tree. – Foxhoundn May 26 '15 at 07:44
  • 1
    Sorry, but you are wrong. Grunt is NOT a compiler NOR a simple watcher! Neither is Apache ANT or other other build tools. And looking at the grunt-contrib-coffee will give you an idea about handling coffee files https://www.npmjs.com/package/grunt-contrib-coffee http://stackoverflow.com/questions/23905751/compiling-coffeescript-files-with-grunt http://spin.atomicobject.com/2013/05/13/javascript-front-end-grunt/ – Exinferis May 26 '15 at 08:01
  • Ok, I have installed and made grunt running, but no matter what I do, no matter what parameter I use, newer files are again prepended to the .js file, if they are higher in the tree structure. – Foxhoundn May 26 '15 at 09:16
  • The only way I can make it work is to put the app.coffee file in a _core folder that ends up being the 1st folder and file in the tree, therefore it's code is always the first in the resulting JS file. – Foxhoundn May 26 '15 at 09:23
  • In the end I had to actually do -> --compile --join bundle.js -- folder/core/ folder/controllers/ folder/views This suits my needs – Foxhoundn May 26 '15 at 10:55
-1

You should give 'cake' a shot. It is a comprehensive build system for coffee.

You can create build tasks that do different things, for instance, a build:dev task that leaves comments in the generated JS and a build:release task that minifies, removes comments etc from the generated JS.

Here's the official documentation

Community
  • 1
  • 1
Ankit
  • 21
  • 4
  • Cake is very simple and you will hit limits soon, I would not recommend using it. – Exinferis May 26 '15 at 07:35
  • @Exinferis, could you give me an example of the kind of problems one could face with cake? Because I am currently using cake with a relatively small project (few dozen coffee files and some scss files). I might consider switching to grunt if it gives me some significant advantage over cake. – Ankit May 27 '15 at 04:58