Git Product home page Git Product logo

jruncoffeescript's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.