2010-07-24 11:31:43 -04:00
( function ( ) {
2010-08-08 10:05:44 -04:00
var BANNER , CoffeeScript , EventEmitter , SWITCHES , _a , _b , _c , compileOptions , compileScript , compileScripts , compileStdio , exec , fs , helpers , lint , optionParser , options , optparse , parseOptions , path , printTokens , sources , spawn , usage , version , watch , writeJs ;
2010-02-15 19:08:14 -05:00
fs = require ( 'fs' ) ;
2010-02-12 22:59:21 -05:00
path = require ( 'path' ) ;
2010-03-15 23:39:46 -04:00
optparse = require ( './optparse' ) ;
CoffeeScript = require ( './coffee-script' ) ;
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
_a = require ( './helpers' ) ;
helpers = _a . helpers ;
_b = require ( 'child_process' ) ;
spawn = _b . spawn ;
exec = _b . exec ;
_c = require ( 'events' ) ;
EventEmitter = _c . EventEmitter ;
helpers . extend ( CoffeeScript , new EventEmitter ( ) ) ;
2010-08-08 09:54:18 -04:00
global . CoffeeScript = CoffeeScript ;
2010-03-17 20:47:27 -04:00
BANNER = 'coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee' ;
2010-08-07 23:33:35 -04:00
SWITCHES = [ [ '-c' , '--compile' , 'compile to JavaScript and save as .js files' ] , [ '-i' , '--interactive' , 'run an interactive CoffeeScript REPL' ] , [ '-o' , '--output [DIR]' , 'set the directory for compiled JavaScript' ] , [ '-w' , '--watch' , 'watch scripts for changes, and recompile' ] , [ '-p' , '--print' , 'print the compiled JavaScript to stdout' ] , [ '-l' , '--lint' , 'pipe the compiled JavaScript through JSLint' ] , [ '-s' , '--stdio' , 'listen for and compile scripts over stdio' ] , [ '-e' , '--eval' , 'compile a string from the command line' ] , [ '-r' , '--require [FILE*]' , 'require a library before executing your script' ] , [ '--no-wrap' , 'compile without the top-level function wrapper' ] , [ '-t' , '--tokens' , 'print the tokens that the lexer produces' ] , [ '-n' , '--nodes' , 'print the parse tree that Jison produces' ] , [ '-v' , '--version' , 'display CoffeeScript version' ] , [ '-h' , '--help' , 'display this help message' ] ] ;
2010-02-13 10:16:28 -05:00
options = { } ;
sources = [ ] ;
2010-06-12 19:05:13 -04:00
optionParser = null ;
2010-05-14 23:40:04 -04:00
exports . run = function ( ) {
2010-02-16 01:04:48 -05:00
var flags , separator ;
2010-06-12 19:05:13 -04:00
parseOptions ( ) ;
2010-02-24 17:57:58 -05:00
if ( options . help ) {
return usage ( ) ;
}
if ( options . version ) {
return version ( ) ;
}
2010-02-13 10:16:28 -05:00
if ( options . interactive ) {
2010-03-15 23:39:46 -04:00
return require ( './repl' ) ;
2010-02-13 10:07:59 -05:00
}
2010-02-24 18:18:29 -05:00
if ( options . stdio ) {
2010-06-12 19:05:13 -04:00
return compileStdio ( ) ;
2010-02-24 18:18:29 -05:00
}
2010-02-13 23:27:13 -05:00
if ( options . eval ) {
2010-06-12 19:05:13 -04:00
return compileScript ( 'console' , sources [ 0 ] ) ;
2010-02-13 23:27:13 -05:00
}
2010-02-13 10:16:28 -05:00
if ( ! ( sources . length ) ) {
2010-06-12 11:09:30 -04:00
return require ( './repl' ) ;
2010-02-13 10:16:28 -05:00
}
2010-02-16 01:04:48 -05:00
separator = sources . indexOf ( '--' ) ;
flags = [ ] ;
if ( separator >= 0 ) {
2010-03-30 20:06:44 -04:00
flags = sources . slice ( ( separator + 1 ) , sources . length ) ;
sources = sources . slice ( 0 , separator ) ;
2010-02-16 01:04:48 -05:00
}
2010-07-10 15:36:54 -04:00
if ( options . run ) {
flags = sources . slice ( 1 , sources . length + 1 ) . concat ( flags ) ;
sources = [ sources [ 0 ] ] ;
}
2010-03-06 20:09:08 -05:00
process . ARGV = ( process . argv = flags ) ;
2010-06-12 19:05:13 -04:00
return compileScripts ( ) ;
2010-02-11 01:57:33 -05:00
} ;
2010-06-12 19:05:13 -04:00
compileScripts = function ( ) {
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
var _d , _e , _f , _g ;
_d = [ ] ; _f = sources ;
for ( _e = 0 , _g = _f . length ; _e < _g ; _e ++ ) {
2010-06-13 21:21:30 -04:00
( function ( ) {
var base , compile ;
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
var source = _f [ _e ] ;
return _d . push ( ( function ( ) {
2010-06-13 21:21:30 -04:00
base = source ;
compile = function ( source , topLevel ) {
return path . exists ( source , function ( exists ) {
if ( ! ( exists ) ) {
2010-08-14 17:25:29 -04:00
throw new Error ( "File not found: " + ( source ) ) ;
2010-06-13 21:21:30 -04:00
}
return fs . stat ( source , function ( err , stats ) {
if ( stats . isDirectory ( ) ) {
return fs . readdir ( source , function ( err , files ) {
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
var _h , _i , _j , _k , file ;
_h = [ ] ; _j = files ;
for ( _i = 0 , _k = _j . length ; _i < _k ; _i ++ ) {
file = _j [ _i ] ;
_h . push ( compile ( path . join ( source , file ) ) ) ;
2010-06-13 21:21:30 -04:00
}
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
return _h ;
2010-06-13 21:21:30 -04:00
} ) ;
} else if ( topLevel || path . extname ( source ) === '.coffee' ) {
fs . readFile ( source , function ( err , code ) {
return compileScript ( source , code . toString ( ) , base ) ;
} ) ;
if ( options . watch ) {
return watch ( source , base ) ;
2010-05-04 23:22:28 -04:00
}
}
2010-06-13 21:21:30 -04:00
} ) ;
2010-05-03 17:38:59 -04:00
} ) ;
2010-06-13 21:21:30 -04:00
} ;
return compile ( source , true ) ;
} ) ( ) ) ;
} ) ( ) ;
2010-02-11 01:57:33 -05:00
}
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
return _d ;
2010-02-16 23:59:32 -05:00
} ;
2010-06-12 19:05:13 -04:00
compileScript = function ( source , code , base ) {
2010-08-07 23:33:35 -04:00
var _d , _e , _f , codeOpts , file , js , o ;
2010-02-24 18:56:32 -05:00
o = options ;
2010-06-12 19:05:13 -04:00
codeOpts = compileOptions ( source ) ;
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
if ( o . require ) {
2010-08-07 23:33:35 -04:00
_e = o . require ;
for ( _d = 0 , _f = _e . length ; _d < _f ; _d ++ ) {
file = _e [ _d ] ;
2010-08-08 10:05:44 -04:00
require ( fs . realpathSync ( file ) ) ;
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
}
}
2010-02-16 23:59:32 -05:00
try {
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
CoffeeScript . emit ( 'compile' , {
source : source ,
code : code ,
base : base ,
options : options
} ) ;
2010-02-24 18:56:32 -05:00
if ( o . tokens ) {
2010-06-12 19:05:13 -04:00
return printTokens ( CoffeeScript . tokens ( code ) ) ;
2010-02-25 18:42:35 -05:00
} else if ( o . nodes ) {
return puts ( CoffeeScript . nodes ( code ) . toString ( ) ) ;
2010-03-07 21:49:08 -05:00
} else if ( o . run ) {
2010-06-12 19:05:13 -04:00
return CoffeeScript . run ( code , codeOpts ) ;
2010-02-12 23:09:57 -05:00
} else {
2010-06-12 19:05:13 -04:00
js = CoffeeScript . compile ( code , codeOpts ) ;
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
CoffeeScript . emit ( 'success' , js ) ;
2010-03-08 04:46:24 -05:00
if ( o . print ) {
2010-04-10 18:05:35 -04:00
return print ( js ) ;
2010-03-08 04:46:24 -05:00
} else if ( o . compile ) {
2010-06-12 19:05:13 -04:00
return writeJs ( source , js , base ) ;
2010-02-24 18:56:32 -05:00
} else if ( o . lint ) {
2010-02-16 23:59:32 -05:00
return lint ( js ) ;
2010-02-13 09:39:25 -05:00
}
2010-02-12 23:09:57 -05:00
}
2010-02-16 23:59:32 -05:00
} catch ( err ) {
2010-08-07 23:33:35 -04:00
CoffeeScript . emit ( 'failure' , err ) ;
if ( CoffeeScript . listeners ( 'failure' ) . length ) {
return null ;
2010-02-16 23:59:32 -05:00
}
2010-08-07 23:33:35 -04:00
if ( ! ( o . watch ) ) {
error ( err . stack ) && process . exit ( 1 ) ;
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
}
2010-08-07 23:33:35 -04:00
return puts ( err . message ) ;
2010-02-16 23:59:32 -05:00
}
} ;
2010-06-12 19:05:13 -04:00
compileStdio = function ( ) {
2010-04-10 18:05:35 -04:00
var code , stdin ;
2010-02-24 18:18:29 -05:00
code = '' ;
2010-04-10 18:05:35 -04:00
stdin = process . openStdin ( ) ;
2010-07-18 07:54:44 -04:00
stdin . on ( 'data' , function ( buffer ) {
2010-04-10 18:05:35 -04:00
if ( buffer ) {
return code += buffer . toString ( ) ;
2010-02-24 18:18:29 -05:00
}
} ) ;
2010-07-18 07:54:44 -04:00
return stdin . on ( 'end' , function ( ) {
2010-06-12 19:05:13 -04:00
return compileScript ( 'stdio' , code ) ;
2010-02-24 18:18:29 -05:00
} ) ;
} ;
2010-05-14 23:40:04 -04:00
watch = function ( source , base ) {
2010-05-03 17:38:59 -04:00
return fs . watchFile ( source , {
persistent : true ,
interval : 500
} , function ( curr , prev ) {
if ( curr . mtime . getTime ( ) === prev . mtime . getTime ( ) ) {
return null ;
}
return fs . readFile ( source , function ( err , code ) {
2010-06-12 19:05:13 -04:00
return compileScript ( source , code . toString ( ) , base ) ;
2010-02-21 19:59:27 -05:00
} ) ;
2010-05-03 17:38:59 -04:00
} ) ;
2010-02-11 01:57:33 -05:00
} ;
2010-06-12 19:05:13 -04:00
writeJs = function ( source , js , base ) {
var baseDir , compile , dir , filename , jsPath , srcDir ;
2010-02-12 22:59:21 -05:00
filename = path . basename ( source , path . extname ( source ) ) + '.js' ;
2010-06-12 19:05:13 -04:00
srcDir = path . dirname ( source ) ;
baseDir = srcDir . substring ( base . length ) ;
dir = options . output ? path . join ( options . output , baseDir ) : srcDir ;
jsPath = path . join ( dir , filename ) ;
2010-05-14 23:40:04 -04:00
compile = function ( ) {
2010-08-04 23:42:46 -04:00
if ( js . length <= 0 ) {
js = ' ' ;
2010-08-04 21:36:03 -04:00
}
2010-06-13 14:21:02 -04:00
return fs . writeFile ( jsPath , js , function ( err ) {
if ( options . compile && options . watch ) {
2010-08-14 17:25:29 -04:00
return puts ( "Compiled " + ( source ) ) ;
2010-06-13 14:21:02 -04:00
}
} ) ;
2010-05-04 23:22:28 -04:00
} ;
return path . exists ( dir , function ( exists ) {
2010-08-14 17:25:29 -04:00
return exists ? compile ( ) : exec ( "mkdir -p " + ( dir ) , compile ) ;
2010-05-03 17:38:59 -04:00
} ) ;
2010-02-12 22:59:21 -05:00
} ;
2010-05-14 23:40:04 -04:00
lint = function ( js ) {
2010-08-14 16:02:01 -04:00
var conf , jsl , printIt ;
2010-06-12 19:05:13 -04:00
printIt = function ( buffer ) {
2010-08-14 16:02:01 -04:00
return puts ( buffer . toString ( ) . trim ( ) ) ;
2010-04-10 18:05:35 -04:00
} ;
2010-08-14 16:02:01 -04:00
conf = _ _dirname + '/../extras/jsl.conf' ;
jsl = spawn ( 'jsl' , [ '-nologo' , '-stdin' , '-conf' , conf ] ) ;
2010-07-18 07:54:44 -04:00
jsl . stdout . on ( 'data' , printIt ) ;
jsl . stderr . on ( 'data' , printIt ) ;
2010-04-10 18:05:35 -04:00
jsl . stdin . write ( js ) ;
return jsl . stdin . end ( ) ;
2010-02-12 23:09:57 -05:00
} ;
2010-06-12 19:05:13 -04:00
printTokens = function ( tokens ) {
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
var _d , _e , _f , _g , _h , strings , tag , token , value ;
2010-02-24 18:56:32 -05:00
strings = ( function ( ) {
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
_d = [ ] ; _f = tokens ;
for ( _e = 0 , _g = _f . length ; _e < _g ; _e ++ ) {
token = _f [ _e ] ;
_d . push ( ( function ( ) {
_h = [ token [ 0 ] , token [ 1 ] . toString ( ) . replace ( /\n/ , '\\n' ) ] ;
tag = _h [ 0 ] ;
value = _h [ 1 ] ;
2010-08-07 08:02:16 -04:00
return "[" + ( tag ) + " " + ( value ) + "]" ;
2010-04-10 14:40:05 -04:00
} ) ( ) ) ;
2010-02-24 18:56:32 -05:00
}
Add command-line compiler hooks. To invoke, pass a file after -r and listen for any of these events: 'compile', 'success' and 'exception'. Example:
coffee -e -r ./snarl 'Hello!'
Contents of 'snarl.coffee' in the working directory:
http = require 'http'
CoffeeScript.on 'exception', (err) ->
client = http.createClient 9889, 'localhost'
request = client.request 'GET', '/?d={"action":1,"applicationName":"CoffeeScript","title":' + JSON.stringify(err.message) + ',"description":' + JSON.stringify(err.stack) + ',"priority":3}'
request.end()
err.handled = yes
To examine arguments available for each event (for debugging and getting started), use `puts JSON.stringify arguments`.
See http://nodejs.org/api.html#modules-309 and NODE_PATH for more details on how -r looks for files.
2010-08-07 13:24:37 -04:00
return _d ;
2010-04-10 14:40:05 -04:00
} ) ( ) ;
2010-02-24 18:56:32 -05:00
return puts ( strings . join ( ' ' ) ) ;
} ;
2010-06-12 19:05:13 -04:00
parseOptions = function ( ) {
2010-03-07 21:49:08 -05:00
var o ;
2010-06-12 19:05:13 -04:00
optionParser = new optparse . OptionParser ( SWITCHES , BANNER ) ;
2010-07-11 09:57:42 -04:00
o = ( options = optionParser . parse ( process . argv . slice ( 2 , process . argv . length ) ) ) ;
2010-08-08 00:07:00 -04:00
options . compile = options . compile || ( ! ! o . output ) ;
2010-03-08 04:46:24 -05:00
options . run = ! ( o . compile || o . print || o . lint ) ;
options . print = ! ! ( o . print || ( o . eval || o . stdio && o . compile ) ) ;
2010-07-24 15:27:11 -04:00
return ( sources = options . arguments ) ;
2010-02-11 01:57:33 -05:00
} ;
2010-07-30 20:37:12 -04:00
compileOptions = function ( fileName ) {
2010-03-07 22:08:24 -05:00
var o ;
o = {
2010-07-30 20:37:12 -04:00
fileName : fileName
2010-03-07 22:08:24 -05:00
} ;
2010-06-28 00:19:58 -04:00
o . noWrap = options [ 'no-wrap' ] ;
2010-03-07 22:08:24 -05:00
return o ;
2010-02-24 18:18:29 -05:00
} ;
2010-05-14 23:40:04 -04:00
usage = function ( ) {
2010-06-12 19:05:13 -04:00
puts ( optionParser . help ( ) ) ;
2010-03-07 00:28:58 -05:00
return process . exit ( 0 ) ;
} ;
2010-05-14 23:40:04 -04:00
version = function ( ) {
2010-08-14 17:25:29 -04:00
puts ( "CoffeeScript version " + ( CoffeeScript . VERSION ) ) ;
2010-03-07 00:28:58 -05:00
return process . exit ( 0 ) ;
} ;
2010-02-24 18:56:32 -05:00
} ) ( ) ;