Skip to content

kzmi/jruncoffeescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jruncoffeescript

This tool runs CoffeeScript compiler with javax.script.ScriptEngine provided by the standard JRE.

JRE7(Rhino) or JRE8(Nashorn) is required.

Build

javac jruncoffeescript/Coffee.java

Usage

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".

Use with Closure Compiler

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

Run from Ant

It takes a while until the tool comes to ready to compile, so it would be better to specify multiple files at once.

Specify directories

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>

Use FileSet

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>

Note

  • 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.

License

MIT License

About

Run CoffeeScript compiler in Java

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages