kimroen / ember-cli-coffeescript

Adds precompilation of CoffeeScript files and all the basic generation types to the ember generate command.
MIT License
72 stars 49 forks source link

All coffee files when 'ember new' #65

Open lnmunhoz opened 9 years ago

lnmunhoz commented 9 years ago

When ember-cli creates a new project, all the main files already comes in common javascript. There's a way to create an extension for ember new to create the full project in coffee? Maybe something like ember new myApp --coffeescript

kimroen commented 9 years ago

Hi there, Lucas!

The way the ember new command works is to run all the things it needs to run, and then apply the app blueprint that comes with ember-cli. You can define your own app blueprint to run during this part by typing ember new myApp --blueprint=<url-for-my-blueprint>. We could certainly provide one that you could use for coffeescript-projects.

The problem with this though, and the reason we haven't done it, is that the app blueprint contains everything. The package.json, the starting folders, and lots of other things that aren't coffeescript-specific. I don't want to maintain a copy of that here and keep that up to date. You can see the blueprint here: https://github.com/ember-cli/ember-cli/tree/master/blueprints/app/files

Something I did think of though, that could be done:

We could provide a command that you can run after installing ember-cli-coffeescript that would ask you if you want to replace the js-files that comes with ember-cli with empty coffee-equivalents. Do you think that could be a solution? It could even run automatically when you install ember-cli-coffeescript.

The files in question would be app/app.js and app/router.js - I think those are the only ones? We could probably build upon that to add more things, but it's a start.

You would need to add a blueprint in the blueprints-folder and name it ember-cli-coffeescript. That way, it will automatically run when people run ember install:addon ember-cli-coffeescript.

If you'd like to take a shot at it, I'd love to accept a pull request with this. If not, I'll see if there's some time in the coming weeks.

lnmunhoz commented 9 years ago

Hey Kim! I think your solution is much more simple than mine. Definitely is more easily to maintain and is a good approach. I can try to do this and send a PR, but I don't have idea of how to do it. What file I should modify to start creating this improvement for the installation of the addon?

Thank you!

sdhull commented 9 years ago

Is there an easy way to simply to convert js to coffee? Maybe that's the solution here.

kimroen commented 9 years ago

@sdhull Yeah, you do have libraries like js2coffee that converts that way. The problem is that these files contain import statements, and js2coffee doesn't handle these.

This:

import Ember from 'ember';

needs to become this:

`import Ember from 'ember'`

There will probably be even more cases of newer ES2015-syntax showing up in the default templates, and that will mean that it's even less likely that you can convert that way. I still think that a default blueprint and/or after-install commands is the way to go. This way, the experience of starting a new ember-cli project with coffeescript will be like this:

  1. ember new my-project
  2. ember install ember-cli-coffeescript
  3. Confirm that you want to overwrite app.js and router.js.

I didn't get the time to implement this this weekend, but I will try again when I find some.

kimroen commented 7 years ago

Now that CoffeeScript supports things like import and export, it could be that using js2coffee as suggested previously is feasible.