coffeescript-compiler v0.1.1
CoffeeScript Compiler
Introduction
This is a node module which allows you to compile CoffeeScript code (strings of code or files containing code) to JavaScript from JavaScript. Output is provided as a string and can optionally be written out to a file.
Usage
You can install this package via npm install coffeescript-compiler
. Please note that this package does NOT define any version of coffee-script
as a dependency for any reason other than testing. You must either have the coffee
command available in your path or have the complete path to access the coffee
command.
All examples assume that you have included this module and created a new Compiler
as follows:
var Compiler = require('coffeescript-compiler');
var cc = new Compiler();
Assuming you have coffee
on your path, compiling a string of CoffeeScript (in this example, a = 5
) is simple:
cc.compile('a = 5', function (status, output) {
if (status === 0) {
// JavaScript available as a string in the `output` variable
}
});
You can get a bare compilation (no wrapper function) by passing in a configuration object as the second argument to compile(...)
:
cc.compile('a = 5', {bare: true}, function (status, output) {
if (status === 0) {
// Bare JavaScript available as a string in the `output` variable
}
});
The configuration object can contain the following options:
asFileName
: If set totrue
the first argument passed tocompile
is treated as a file name rather than an input string. If this is set and an error is encountered while reading the error will be thrown.bare
: Compiles input to bare JavaScript if set totrue
.writeFile
: A string containing a filename to write JavaScript output to. If this is set and an error is encountered while writing the error will be thrown.
License
The MIT License
Copyright (c) 2012 Kenneth Powers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.