Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gen): Generate node and Gruntfile with coffeescript #265

Closed
wants to merge 1 commit into from
Closed

Conversation

burtonjc
Copy link

Add build pipleline to handle coffee across whole stack

Closes #92

Add build pipleline to handle coffee across whole stack

Closes #92
@burtonjc
Copy link
Author

@ccolleyh worked on this with me as well.

@@ -46,15 +47,7 @@ module.exports = function (grunt) {
url: 'http://localhost:<%%= express.options.port %>'
}
},
watch: {<% if (coffee) { %>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have Gruntfile.coffee for coffeescript now, so we don't need coffee checks. We can assume you are using js if you are in Gruntfile.js and cs if you are in Gruntfile.coffee.

@burtonjc
Copy link
Author

Any chance you have had been able to look at this @DaftMonk?

@DaftMonk
Copy link
Member

Haven't had a chance to look at this yet, but I will after releasing 2.0

@thgil
Copy link

thgil commented Jun 30, 2014

@burtonjc does this work when you try grunt build and running the server in production mode? I get errors when angular tries to instantiate modules.

@thgil
Copy link

thgil commented Jun 30, 2014

Also, I noticed the watch task isn't running correctly. Changes to files are not being updated in .tmp/ so when livereload reloads the site it is just using the old code in .tmp/. Adding copy:dist after any changes should fix this though.

@burtonjc
Copy link
Author

Thanks @thgil, I will update the pr when I get a chance.

@thgil
Copy link

thgil commented Jun 30, 2014

Thanks, this PR saved me so much time!

@snowman-repos
Copy link

Not sure if this comment should go here, on another issue or in a new issue... ?

I guess a lot of this PR code is redundant now as a lot has changed for V2. Seems a few issues #59 #92 #296 are calling for CoffeeScript for the server app and to my mind this feature would make the generator 100% perfect. Is anyone else working on it at the moment? If so, need help? and if not, wanna help me? 😄

I guess we need:

  • Copies of all JavaScript server side tests and specs in app/templates/server converted to CoffeeScript, perhaps using something like js2coffee and then manually checking output. Filenames should be like in the app/templates/client/app folder: name(coffee).coffee
  • Update app/index.js to reference .coffee files for the server
  • Update test/test-file-creation.js to test server-side CoffeeScript files are created
  • Update gruntfile to reference .coffee files and run the Mocha tests from the CoffeeScript files
  • CoffeeScript versions of endpoint/templates files
  • Add CoffeeScript gruntfile

Anything else?

@meeDamian
Copy link
Contributor

Hi, I'm cleaning up client-side .coffee files now, and I would love to help with server side afterwards. How do we split work? :)

@meeDamian
Copy link
Contributor

After looking at server side it seems like adding coffeescript support would add a lot of complexity (ex. double filters seed(mongoose)(coffee).coffee) and would basically double server-side codebase to maintain, so I wonder if it wouldn't be better to write server stuff in coffee, and just compile it for users who choose javascript. I'm not sure if output will be pretty enough, though... We can use some prettifiers, but we will still have some unskipably ugly things like extend or some loops.

Any thoughts?

cc: @darryl-snow @DaftMonk @JaKXz @burtonjc(if still interested?)

@DaftMonk
Copy link
Member

Unfortunately Coffeescript > javascript compiling is quite ugly, and I would be surprised if a javascript prettifier would help. :(

@meeDamian
Copy link
Contributor

Agree. JS code would definitely lose a lot of it's clarity...

Assuming that's a blocker - I can PR with additional coffeescript structure. One question, though:

how do I handle double-conditions?

  1. seed(mongoose)(coffee).coffee,
  2. seed(mongoose,coffee).coffee,
  3. or should I add it here: app/server(coffee)/*? But that would also include some *.jade, *.html ~~and .jshintrc~~¹ files.
  4. build process changes are required

I've already started here, any review would be awesome. For now it's just syntax rewrite w/o any other process changes.

@DaftMonk what's your view on that?

¹ - that's actually good

@meeDamian
Copy link
Contributor

I just implemented server side coffeescript support in my app, and it's a nightmare. Grunt is currently using [email protected] (yeah, the one dating back to march 2012...). They are planning on bumping coffeescript version in v0.5.x, but it's still a long way to go.

My suggestion would be leaving coffeescript server side support until Grunt 0.5 arrives. Unless anyone is up for having two versions of each file: file.coffee and file.compiled.js. I'm not.

My way of making it work is so terrible that I'd rather not share ;P.

@DaftMonk
Copy link
Member

DaftMonk commented Aug 2, 2014

@chester1000 Sad to hear it didn't work out, but thanks for taking the time to try it.

@meeDamian
Copy link
Contributor

It did work out, but I ended up doing things that aren't... well... good practices. And I definitely wouldn't recommend doing them here ;)

@meeDamian
Copy link
Contributor

Ok, seems like this grunt nightmare is just a fallback if require 'coffee-script/register' isn't used anywhere.

So it might actually work:

  • Gruntfile.coffee will still be interpreted using [email protected], BUT
  • All other require'd .coffee files will be run through version of coffee specified in our package.json.

Steps to enable server-side coffee support:

  • add coffee-script dependency to package.json,
  • rewrite Gruntfile.js to Gruntfile.coffee¹ 1:1 with only express section altered as follows:
express:
  options:
    port: process.env.PORT or 9000
    opts: ['node_modules/.bin/coffee']

  dev:
    options:
      script: 'server/app.coffee'
      debug: true

  prod:
    options:
      script: 'dist/server/app.coffee'
  • add require 'coffee-script/register' somewhere on top of server/app.coffee
  • rewrite all server .js files to .coffee (I do not recommend just recompiling them),
  • add some clever generator conditions on top of that,
  • make sure that generator-ng-component supports server coffee setup as well!

@DaftMonk can you merge #392 to canary²? So I can start adding coffee support on top of that already?

Also, how about creating 2.1.0 milestone containing:


¹ - That's the file I'm currently using (contains grunt-build-control configured for heroku`).
² - Do I need to submit another PR?

@JaKXz JaKXz added this to the 2.1.0 milestone Aug 13, 2014
@thomporter
Copy link

Wish I started looking at this project sooner, I may have a solution...

@DaftMonk was absolutely right:

Unfortunately Coffeescript > javascript compiling is quite ugly

But ever noticed how you can go to js2coffee.org and the ugliest javascript comes out looking like nice coffeescript? I think that's our best bet - use grunt-js2coffee to produce .coffee files out of .js files:
https://github.com/jonschlinkert/grunt-js2coffee/

Note: I tried grabbing app.js from the generator, and running js2coffee on it, and it complained because of the <%%>s... So we'd need to build everything out in the generator in JS, and then convert it all to coffee... I would imagine we could do this with the client-side scripts too... 😉

@kingcody
Copy link
Member

I'm no coffee fan, but I do use grunt-js2coffee to translate all my PRs. It does work well, I just always find myself going through the 'decompiled' coffee making small syntax changes. Also I'm never sure as to whether or not I should use coffee shortcuts such as: callback? things moarThings. Its nice but it does add more inline code once translated back to js, instead of just using a small wrapper fn defined somewhere in the file... Just my 2¢ on js2coffee

@thomporter
Copy link

As a coffee fan, I can vote for js2coffee. The output isn't perfect, but it's really not that bad - certainly better than the other way around. If we can figure it out, it would save us all time, we'd just have to write well written JS instead of well written JS & CS. 😉

@faloi
Copy link

faloi commented Sep 2, 2014

@chester1000 thanks for your suggestion, it works well on my computer and CI. For Heroku, I changed the npm start command to node_modules/.bin/coffee -w server/app.coffee, but it doesn't look very elegant... any better idea?

@josephfinlayson
Copy link

I'm a real fan of this feature being integrated. +1

@simonh1000
Copy link

This is above my head, but just wanted to signal how welcome this will be

@ErikEvenson
Copy link

Would like this as well.

@rriemann
Copy link

I would like to see this integrated as well. @chester1000 , do you have an up-to-date branch with the changes you proposed for the meanwhile?

@wmertens
Copy link

How about making the server side in coffee, convert to js when required and only when the js output is unreadable provide a manual js version that is kept up-to-date manually?

I think most of the output will be ok...

@mjrk
Copy link

mjrk commented Apr 3, 2015

+1
Coffee, the yardstick of civilization.

@omgaz
Copy link

omgaz commented May 1, 2015

bump

@udnisap
Copy link

udnisap commented May 3, 2015

Anything else needed to be done on this? I can help out if needed.

@harryoh
Copy link

harryoh commented May 9, 2015

I create new generator for server-side coffee script.
visit to https://github.com/harryoh/generator-coffee-fullstack

@Awk34 Awk34 removed this from the 2.1.0 milestone Jul 15, 2015
@Awk34 Awk34 closed this May 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate node with coffeescript