This tool runs CoffeeScript compiler with javax.script.ScriptEngine provided by the standard JRE.
JRE7(Rhino) or JRE8(Nashorn) is required.
javac jruncoffeescript/Coffee.java
Usage: java jruncoffeescript.Coffee [options] [path/to/script.coffee ...]
-b --bare compile without a top-level function wrapper
-c --compile compile to JavaScript and save as .js files
-h --help display this help message
-m --map generate source map and save as .js.map files
--no-header suppress the "Generated by" header
--output DIR set the output directory for compiled JavaScript
-l --literate treat input as literate style coffee-script
-v --version display the version number
-w --watch watch scripts for changes and rerun commands
--verbose output more informations to stdout
--update compile only if the source file is newer than the js file
--closure OPTIONS call Google's Closure Compiler (requires compiler.jar in CLASSPATH)
coffee-script.js must be placed on the class path.
coffee-script.js is a core compiler (browser script) which can download from http://coffeescript.org/extras/coffee-script.js .
coffee-script-for-rhino.js is a modified version of the coffee-script.js for avoiding syntax error issue on the Rhino engine. Rhino engine doesn't fully support ECMAScript 5, and gets syntax error at the property name "double".
With --closure
option, the generated JavaScript code will be processed by the Google Closure Compiler.
compiler.jar (Closure Compiler Application) is required in the CLASSPATH like:
java -cp compiler.jar jruncoffeescript.Coffee --closure "--compilation_level SIMPLE_OPTIMIZATIONS" /path/to/script.coffee
It takes a while until the tool comes to ready to compile, so it would be better to specify multiple files at once.
in build.xml
<property name="coffeescript.sourcedir1" value="/path/to/directory..."/>
<property name="coffeescript.sourcedir2" value="/path/to/directory..."/>
<property name="coffeescript.sourcedir3" value="/path/to/directory..."/>
<target name="compile" description="Compiles coffeescript files">
<java
classname="jruncoffeescript.Coffee"
fork="true">
<!-- fork="true" is required for using ScriptEngine -->
<!-- need to specify class path -->
<arg value="-c"/>
<arg value="-m"/>
<arg value="--update"/>
<arg value="--verbose"/>
<arg path="${coffeescript.sourcedir1}"/>
<arg path="${coffeescript.sourcedir2}"/>
<arg path="${coffeescript.sourcedir3}"/>
</java>
</target>
in build.xml
<target name="compile" description="Compiles coffeescript files">
<pathconvert property="coffeescript.sourcefiles" pathsep=" ">
<fileset dir="js">
<include name="**/*.coffee"/>
</fileset>
<mapper type="glob" from="*" to='"*"'/><!-- for paths containing spaces -->
</pathconvert>
<java
classname="jruncoffeescript.Coffee"
fork="true">
<!-- fork="true" is required for using ScriptEngine -->
<!-- need to specify class path -->
<arg value="-c"/>
<arg value="-m"/>
<arg value="--update"/>
<arg value="--verbose"/>
<arg line="${coffeescript.sourcefiles}"/>
</java>
</target>
-
Currently
--join
is not supported. -
Generating source map will works, but the URI or path in the map file may be different from the output of the original
coffee
command.
MIT License