Node.js, CoffeeScript and Streamline

176 views
Skip to first unread message

niklassaers

unread,
Jul 15, 2012, 6:28:35 PM7/15/12
to stream...@googlegroups.com
Hi guys,
I'm an ObjC guy diving into Node for the summer. When I write Node, I use CoffeeScript, and while working I use supervisor to make sure everything is compiled right away.

How do I best make streamline.js fit into this workflow? Ideally, I'll just add _coffee to --extensions at the supervisor command line and be done with it. But how do I make Node compile the streamline'd coffee files before reloading?

Cheers

   Nik

Aseem Kishore

unread,
Jul 16, 2012, 8:17:07 AM7/16/12
to stream...@googlegroups.com
Hey Nik,

CoffeeScript and Streamline both come with a require() hook that lets you simply require() your .coffee and ._js/._coffee files as if they were regular .js files, compiling them on the fly each time.

So you can have your top-level JS (e.g. app.js or server.js) simply register these hooks and then require() your files like normal:

// e.g. app.js
require('coffee-script'); // registers automatically
require('streamline').register();
require('./app._coffee');

// app._coffee
console.log 'hello...'
setTimeout _, 1000
console.log '...world'

The only downside to this approach is that each compilation takes a bit of time. Streamline has support for caching built-in if you pass {cache: true}, to the register() call.

But that doesn't cache the CoffeeScript compilation, and the cache doesn't keep up with CoffeeScript version changes, so I made a little helper a while back to do a bit smarter caching for both:


We use this with node-dev, a really robust supervisor I've come to really love:


And it works great. This is our "top-level" JS file:


I've been meaning to ask Bruno about whether it might make sense for some of this better CoffeeScript support / smarter caching to be in Streamline proper, so it'd be great to get your thoughts.

Hope this helps!

Aseem

niklassaers

unread,
Jul 17, 2012, 2:22:29 PM7/17/12
to stream...@googlegroups.com
Hi Aseem,
Thanks for the pointers, having it as a part of require is really cool. :-)

I found your coffee-streamline package, and it seems to work really well :-) I don't know about the politics of what is proper and what is community, but I'd love for it to be used in the tutorials you find when first searching for this on Google. :-)

I find it a bit confusing that in the Node community, caching properties seem to be set in code rather than in config, I guess everyone just builds their way around this?

Thanks for the gist, looks nice. Also thanks for node-dev, I'll be sure to play with it

Cheers

   Nik

Alexey Petrushin

unread,
Jan 12, 2014, 5:51:11 PM1/12/14
to stream...@googlegroups.com
Yes, would be nice to have support for CoffeeScript out of the box.

Bruno Jouhier

unread,
Jan 12, 2014, 6:01:52 PM1/12/14
to stream...@googlegroups.com
Hi Alexey,

The CoffeeScript caching issue has been fixed 2 weeks ago: https://github.com/Sage/streamlinejs/commit/45a41b111ae7efff7372e5933fb5b91ece513557

The only problem that remains in this area is the fact that the cache is not invalidated if the coffeescript version changes. So, to be really on the safe side, you should delete the streamline cache (~/.streamline) if you upgrade CoffeeScript.

Bruno
Reply all
Reply to author
Forward
0 new messages