We can compile coffescript file to js-file with command:
coffee –join path/to/result.js –compile path/to/coffeescript_dir/
But what if I want to compile a piece of coffeescript code (as text) and get piece of js code (as a text too), and they are not files.
For example:
-
cs text:
"func = () -> 55" -
js text result:
"var func; func = function(){return 55;}"
It must be done from console, or even better from python interactive console 🙂
You can use
--evalto take a string parameter as coffee input,--bareto avoid the JS output being wrapped in a closure, and--printto print the output on stdout instead of a file:To call it from Python, you can use the subprocess module: