2010-07-24 11:31:43 -04:00
( function ( ) {
2011-12-18 15:23:42 -05:00
var BANNER , CoffeeScript , EventEmitter , SWITCHES , compileJoin , compileOptions , compilePath , compileScript , compileStdio , exec , forkNode , fs , helpers , joinTimeout , lint , loadRequires , notSources , optionParser , optparse , opts , outputPath , parseOptions , path , printLine , printTokens , printWarn , removeSource , sourceCode , sources , spawn , timeLog , unwatchDir , usage , version , wait , watch , watchDir , watchers , writeJs , _ref ;
2011-09-18 18:16:39 -04:00
2010-02-15 19:08:14 -05:00
fs = require ( 'fs' ) ;
2011-09-18 18:16:39 -04:00
2010-02-12 22:59:21 -05:00
path = require ( 'path' ) ;
2011-09-18 18:16:39 -04:00
2010-11-04 23:05:04 -04:00
helpers = require ( './helpers' ) ;
2011-09-18 18:16:39 -04:00
2010-03-15 23:39:46 -04:00
optparse = require ( './optparse' ) ;
2011-09-18 18:16:39 -04:00
2010-03-15 23:39:46 -04:00
CoffeeScript = require ( './coffee-script' ) ;
2011-09-18 18:16:39 -04:00
2010-09-28 16:47:12 -04:00
_ref = require ( 'child_process' ) , spawn = _ref . spawn , exec = _ref . exec ;
2011-09-18 18:16:39 -04:00
2010-09-28 16:47:12 -04:00
EventEmitter = require ( 'events' ) . EventEmitter ;
2011-09-18 18:16:39 -04:00
2010-09-25 04:39:19 -04:00
helpers . extend ( CoffeeScript , new EventEmitter ) ;
2011-09-18 18:16:39 -04:00
2011-10-24 16:19:15 -04:00
printLine = function ( line ) {
return process . stdout . write ( line + '\n' ) ;
} ;
printWarn = function ( line ) {
2011-10-27 11:23:03 -04:00
return process . stderr . write ( line + '\n' ) ;
2011-10-24 16:19:15 -04:00
} ;
2011-09-11 22:43:28 -04:00
BANNER = 'Usage: coffee [options] path/to/script.coffee\n\nIf called without options, `coffee` will run your script.' ;
2011-09-18 18:16:39 -04:00
2011-09-11 22:43:28 -04:00
SWITCHES = [ [ '-b' , '--bare' , 'compile without a top-level function wrapper' ] , [ '-c' , '--compile' , 'compile to JavaScript and save as .js files' ] , [ '-e' , '--eval' , 'pass a string from the command line as input' ] , [ '-h' , '--help' , 'display this help message' ] , [ '-i' , '--interactive' , 'run an interactive CoffeeScript REPL' ] , [ '-j' , '--join [FILE]' , 'concatenate the source CoffeeScript before compiling' ] , [ '-l' , '--lint' , 'pipe the compiled JavaScript through JavaScript Lint' ] , [ '-n' , '--nodes' , 'print out the parse tree that the parser produces' ] , [ '--nodejs [ARGS]' , 'pass options directly to the "node" binary' ] , [ '-o' , '--output [DIR]' , 'set the output directory for compiled JavaScript' ] , [ '-p' , '--print' , 'print out the compiled JavaScript' ] , [ '-r' , '--require [FILE*]' , 'require a library before executing your script' ] , [ '-s' , '--stdio' , 'listen for and compile scripts over stdio' ] , [ '-t' , '--tokens' , 'print out the tokens that the lexer/rewriter produce' ] , [ '-v' , '--version' , 'display the version number' ] , [ '-w' , '--watch' , 'watch scripts for changes and rerun commands' ] ] ;
2011-09-18 18:16:39 -04:00
2010-08-15 08:32:09 -04:00
opts = { } ;
2011-09-18 18:16:39 -04:00
2010-02-13 10:16:28 -05:00
sources = [ ] ;
2011-09-18 18:16:39 -04:00
2011-12-18 10:27:22 -05:00
sourceCode = [ ] ;
2011-09-18 18:16:39 -04:00
2011-12-18 11:27:02 -05:00
notSources = { } ;
2011-12-18 12:26:04 -05:00
watchers = { } ;
2010-06-12 19:05:13 -04:00
optionParser = null ;
2011-09-18 18:16:39 -04:00
2011-04-30 23:01:36 -04:00
exports . run = function ( ) {
2011-12-18 11:27:02 -05:00
var source , _i , _len , _results ;
2010-06-12 19:05:13 -04:00
parseOptions ( ) ;
2011-08-07 02:59:37 -04:00
if ( opts . nodejs ) return forkNode ( ) ;
if ( opts . help ) return usage ( ) ;
if ( opts . version ) return version ( ) ;
if ( opts . require ) loadRequires ( ) ;
if ( opts . interactive ) return require ( './repl' ) ;
2011-11-10 09:11:27 -05:00
if ( opts . watch && ! fs . watch ) {
2011-12-19 11:23:27 -05:00
return printWarn ( "The --watch feature depends on Node v0.6.0+. You are running " + process . version + "." ) ;
2011-11-10 09:11:27 -05:00
}
2011-08-07 02:59:37 -04:00
if ( opts . stdio ) return compileStdio ( ) ;
if ( opts . eval ) return compileScript ( null , sources [ 0 ] ) ;
if ( ! sources . length ) return require ( './repl' ) ;
if ( opts . run ) opts . literals = sources . splice ( 1 ) . concat ( opts . literals ) ;
2011-11-05 10:34:44 -04:00
process . argv = process . argv . slice ( 0 , 2 ) . concat ( opts . literals ) ;
2011-04-30 10:59:55 -04:00
process . argv [ 0 ] = 'coffee' ;
2011-05-01 13:45:47 -04:00
process . execPath = require . main . filename ;
2011-12-18 11:27:02 -05:00
_results = [ ] ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = sources . length ; _i < _len ; _i ++ ) {
2011-12-18 11:27:02 -05:00
source = sources [ _i ] ;
2011-12-18 12:26:04 -05:00
_results . push ( compilePath ( source , true , path . normalize ( source ) ) ) ;
2011-12-18 11:27:02 -05:00
}
return _results ;
2010-02-11 01:57:33 -05:00
} ;
2011-09-18 18:16:39 -04:00
2011-12-18 11:27:02 -05:00
compilePath = function ( source , topLevel , base ) {
2011-12-18 13:50:04 -05:00
return fs . stat ( source , function ( err , stats ) {
if ( err && err . code !== 'ENOENT' ) throw err ;
if ( ( err != null ? err . code : void 0 ) === 'ENOENT' ) {
if ( topLevel && source . slice ( - 7 ) !== '.coffee' ) {
source = sources [ sources . indexOf ( source ) ] = "" + source + ".coffee" ;
return compilePath ( source , topLevel , base ) ;
}
if ( topLevel ) {
console . error ( "File not found: " + source ) ;
process . exit ( 1 ) ;
}
return ;
2011-12-18 11:27:02 -05:00
}
2011-12-18 13:50:04 -05:00
if ( stats . isDirectory ( ) ) {
if ( opts . watch ) watchDir ( source , base ) ;
return fs . readdir ( source , function ( err , files ) {
var file , index , _i , _len , _ref2 , _results ;
2011-12-18 14:39:19 -05:00
if ( err && err . code !== 'ENOENT' ) throw err ;
if ( ( err != null ? err . code : void 0 ) === 'ENOENT' ) return ;
2011-12-18 13:50:04 -05:00
files = files . map ( function ( file ) {
return path . join ( source , file ) ;
2010-10-13 07:29:22 -04:00
} ) ;
2011-12-18 13:50:04 -05:00
index = sources . indexOf ( source ) ;
[ ] . splice . apply ( sources , [ index , index - index + 1 ] . concat ( files ) ) , files ;
[ ] . splice . apply ( sourceCode , [ index , index - index + 1 ] . concat ( _ref2 = files . map ( function ( ) {
return null ;
} ) ) ) , _ref2 ;
_results = [ ] ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = files . length ; _i < _len ; _i ++ ) {
2011-12-18 13:50:04 -05:00
file = files [ _i ] ;
_results . push ( compilePath ( file , false , base ) ) ;
}
return _results ;
} ) ;
} else if ( topLevel || path . extname ( source ) === '.coffee' ) {
if ( opts . watch ) watch ( source , base ) ;
return fs . readFile ( source , function ( err , code ) {
2011-12-18 14:39:19 -05:00
if ( err && err . code !== 'ENOENT' ) throw err ;
if ( ( err != null ? err . code : void 0 ) === 'ENOENT' ) return ;
2011-12-18 13:50:04 -05:00
return compileScript ( source , code . toString ( ) , base ) ;
} ) ;
} else {
notSources [ source ] = true ;
return removeSource ( source , base ) ;
}
2011-12-18 11:27:02 -05:00
} ) ;
2010-02-16 23:59:32 -05:00
} ;
2011-09-18 18:16:39 -04:00
2010-08-15 08:32:09 -04:00
compileScript = function ( file , input , base ) {
2011-01-13 14:50:00 -05:00
var o , options , t , task ;
2010-08-15 08:32:09 -04:00
o = opts ;
options = compileOptions ( file ) ;
2010-02-16 23:59:32 -05:00
try {
2010-10-20 13:29:06 -04:00
t = task = {
2010-08-15 08:32:09 -04:00
file : file ,
input : input ,
options : options
2010-10-20 13:29:06 -04:00
} ;
2010-08-15 08:32:09 -04:00
CoffeeScript . emit ( 'compile' , task ) ;
2010-02-24 18:56:32 -05:00
if ( o . tokens ) {
2010-08-15 08:32:09 -04:00
return printTokens ( CoffeeScript . tokens ( t . input ) ) ;
2010-02-25 18:42:35 -05:00
} else if ( o . nodes ) {
2011-10-24 16:19:15 -04:00
return printLine ( CoffeeScript . nodes ( t . input ) . toString ( ) . trim ( ) ) ;
2010-03-07 21:49:08 -05:00
} else if ( o . run ) {
2010-08-15 08:32:09 -04:00
return CoffeeScript . run ( t . input , t . options ) ;
2011-12-18 11:27:02 -05:00
} else if ( o . join && t . file !== o . join ) {
sourceCode [ sources . indexOf ( t . file ) ] = t . input ;
return compileJoin ( ) ;
2010-02-12 23:09:57 -05:00
} else {
2010-08-15 08:32:09 -04:00
t . output = CoffeeScript . compile ( t . input , t . options ) ;
2010-08-12 18:28:38 -04:00
CoffeeScript . emit ( 'success' , task ) ;
2010-11-08 23:07:51 -05:00
if ( o . print ) {
2011-10-24 16:19:15 -04:00
return printLine ( t . output . trim ( ) ) ;
2010-11-08 23:07:51 -05:00
} else if ( o . compile ) {
return writeJs ( t . file , t . output , base ) ;
} else if ( o . lint ) {
return lint ( t . file , t . output ) ;
}
2010-02-12 23:09:57 -05:00
}
2010-02-16 23:59:32 -05:00
} catch ( err ) {
2010-08-12 18:28:38 -04:00
CoffeeScript . emit ( 'failure' , err , task ) ;
2011-08-07 02:59:37 -04:00
if ( CoffeeScript . listeners ( 'failure' ) . length ) return ;
2011-10-24 16:19:15 -04:00
if ( o . watch ) return printLine ( err . message ) ;
printWarn ( err instanceof Error && err . stack || ( "ERROR: " + err ) ) ;
2010-08-15 08:32:09 -04:00
return process . exit ( 1 ) ;
2010-02-16 23:59:32 -05:00
}
} ;
2011-09-18 18:16:39 -04: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 ) {
2011-08-07 02:59:37 -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-11-06 09:21:45 -04:00
return compileScript ( null , code ) ;
2010-02-24 18:18:29 -05:00
} ) ;
} ;
2011-09-18 18:16:39 -04:00
2011-12-18 15:19:08 -05:00
joinTimeout = null ;
2011-12-18 11:27:02 -05:00
compileJoin = function ( ) {
2011-12-18 12:26:04 -05:00
if ( ! opts . join ) return ;
2011-12-18 10:27:22 -05:00
if ( ! sourceCode . some ( function ( code ) {
return code === null ;
} ) ) {
2011-12-18 15:19:08 -05:00
clearTimeout ( joinTimeout ) ;
2011-12-18 15:27:08 -05:00
return joinTimeout = wait ( 100 , function ( ) {
2011-12-18 15:19:08 -05:00
return compileScript ( opts . join , sourceCode . join ( '\n' ) , opts . join ) ;
2011-12-18 15:27:08 -05:00
} ) ;
2011-12-18 10:27:22 -05:00
}
2010-12-23 00:26:15 -05:00
} ;
2011-09-18 18:16:39 -04:00
2011-01-15 10:46:53 -05:00
loadRequires = function ( ) {
2011-03-28 17:12:27 -04:00
var realFilename , req , _i , _len , _ref2 ;
2011-01-15 10:46:53 -05:00
realFilename = module . filename ;
module . filename = '.' ;
2011-03-28 17:12:27 -04:00
_ref2 = opts . require ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = _ref2 . length ; _i < _len ; _i ++ ) {
2011-03-28 17:12:27 -04:00
req = _ref2 [ _i ] ;
2011-01-15 10:46:53 -05:00
require ( req ) ;
}
return module . filename = realFilename ;
} ;
2011-09-18 18:16:39 -04:00
2010-05-14 23:40:04 -04:00
watch = function ( source , base ) {
2011-12-22 15:02:25 -05:00
var compile , compileTimeout , prevStats , rewatch , watchErr , watcher ;
2011-12-18 09:05:42 -05:00
prevStats = null ;
2011-12-18 14:05:18 -05:00
compileTimeout = null ;
2011-12-18 14:15:33 -05:00
watchErr = function ( e ) {
if ( e . code === 'ENOENT' ) {
2011-12-18 15:19:08 -05:00
if ( sources . indexOf ( source ) === - 1 ) return ;
2011-12-22 15:02:25 -05:00
try {
rewatch ( ) ;
return compile ( ) ;
} catch ( e ) {
removeSource ( source , base , true ) ;
return compileJoin ( ) ;
}
2011-12-18 14:15:33 -05:00
} else {
throw e ;
}
} ;
2011-12-22 14:30:12 -05:00
rewatch = function ( ) {
var watcher ;
if ( typeof watcher !== "undefined" && watcher !== null ) watcher . close ( ) ;
return watcher = fs . watch ( source , compile ) ;
} ;
2011-12-18 09:05:42 -05:00
compile = function ( ) {
2011-12-18 14:05:18 -05:00
clearTimeout ( compileTimeout ) ;
2011-12-18 14:26:23 -05:00
return compileTimeout = wait ( 25 , function ( ) {
2011-12-18 14:05:18 -05:00
return fs . stat ( source , function ( err , stats ) {
2011-12-18 14:15:33 -05:00
if ( err ) return watchErr ( err ) ;
2011-12-18 14:05:18 -05:00
if ( prevStats && ( stats . size === prevStats . size && stats . mtime . getTime ( ) === prevStats . mtime . getTime ( ) ) ) {
2011-12-22 14:30:12 -05:00
return rewatch ( ) ;
2011-12-18 14:05:18 -05:00
}
prevStats = stats ;
return fs . readFile ( source , function ( err , code ) {
2011-12-18 14:15:33 -05:00
if ( err ) return watchErr ( err ) ;
2011-12-22 14:30:12 -05:00
compileScript ( source , code . toString ( ) , base ) ;
return rewatch ( ) ;
2011-12-18 14:05:18 -05:00
} ) ;
2011-12-18 09:05:42 -05:00
} ) ;
2011-12-18 14:26:23 -05:00
} ) ;
} ;
2011-12-18 14:01:13 -05:00
try {
2011-12-22 14:30:12 -05:00
return watcher = fs . watch ( source , compile ) ;
2011-12-18 14:01:13 -05:00
} catch ( e ) {
return watchErr ( e ) ;
}
2010-02-11 01:57:33 -05:00
} ;
2011-09-18 18:16:39 -04:00
2011-12-18 11:27:02 -05:00
watchDir = function ( source , base ) {
2011-12-18 15:19:08 -05:00
var readdirTimeout , watcher ;
readdirTimeout = null ;
2011-12-18 14:01:13 -05:00
try {
return watcher = fs . watch ( source , function ( ) {
2011-12-18 15:19:08 -05:00
clearTimeout ( readdirTimeout ) ;
2011-12-18 15:27:08 -05:00
return readdirTimeout = wait ( 25 , function ( ) {
2011-12-18 15:19:08 -05:00
return fs . readdir ( source , function ( err , files ) {
var file , _i , _len , _results ;
if ( err ) {
if ( err . code !== 'ENOENT' ) throw err ;
watcher . close ( ) ;
return unwatchDir ( source , base ) ;
2011-12-18 14:01:13 -05:00
}
2011-12-18 12:26:04 -05:00
files = files . map ( function ( file ) {
return path . join ( source , file ) ;
} ) ;
_results = [ ] ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = files . length ; _i < _len ; _i ++ ) {
2011-12-18 15:19:08 -05:00
file = files [ _i ] ;
2011-12-18 12:26:04 -05:00
if ( ! ( ! notSources [ file ] ) ) continue ;
if ( sources . some ( function ( s ) {
return s . indexOf ( file ) >= 0 ;
} ) ) {
continue ;
}
sources . push ( file ) ;
sourceCode . push ( null ) ;
_results . push ( compilePath ( file , false , base ) ) ;
}
return _results ;
2011-12-18 15:19:08 -05:00
} ) ;
2011-12-18 15:27:08 -05:00
} ) ;
2011-12-18 11:27:02 -05:00
} ) ;
2011-12-18 14:01:13 -05:00
} catch ( e ) {
if ( e . code !== 'ENOENT' ) throw e ;
}
2011-12-18 11:27:02 -05:00
} ;
2011-12-18 15:19:08 -05:00
unwatchDir = function ( source , base ) {
2011-12-18 15:21:50 -05:00
var file , prevSources , toRemove , _i , _len ;
2011-12-18 15:19:08 -05:00
prevSources = sources . slice ( ) ;
toRemove = ( function ( ) {
var _i , _len , _results ;
_results = [ ] ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = sources . length ; _i < _len ; _i ++ ) {
2011-12-18 15:19:08 -05:00
file = sources [ _i ] ;
if ( file . indexOf ( source ) >= 0 ) _results . push ( file ) ;
}
return _results ;
} ) ( ) ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = toRemove . length ; _i < _len ; _i ++ ) {
2011-12-18 15:19:08 -05:00
file = toRemove [ _i ] ;
removeSource ( file , base , true ) ;
}
2011-12-18 15:21:50 -05:00
if ( ! sources . some ( function ( s , i ) {
return prevSources [ i ] !== s ;
} ) ) {
2011-12-18 15:19:08 -05:00
return ;
}
return compileJoin ( ) ;
} ;
2011-12-18 12:26:04 -05:00
removeSource = function ( source , base , removeJs ) {
var index , jsPath ;
2011-12-18 11:27:02 -05:00
index = sources . indexOf ( source ) ;
sources . splice ( index , 1 ) ;
2011-12-18 12:26:04 -05:00
sourceCode . splice ( index , 1 ) ;
if ( removeJs && ! opts . join ) {
jsPath = outputPath ( source , base ) ;
return path . exists ( jsPath , function ( exists ) {
if ( exists ) {
return fs . unlink ( jsPath , function ( err ) {
2011-12-18 14:15:33 -05:00
if ( err && err . code !== 'ENOENT' ) throw err ;
2011-12-18 12:26:04 -05:00
return timeLog ( "removed " + source ) ;
} ) ;
}
} ) ;
}
2011-12-18 11:27:02 -05:00
} ;
outputPath = function ( source , base ) {
var baseDir , dir , filename , 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 ) ;
2010-12-23 17:34:50 -05:00
baseDir = base === '.' ? srcDir : srcDir . substring ( base . length ) ;
2010-08-15 08:32:09 -04:00
dir = opts . output ? path . join ( opts . output , baseDir ) : srcDir ;
2011-12-18 11:27:02 -05:00
return path . join ( dir , filename ) ;
} ;
writeJs = function ( source , js , base ) {
var compile , jsDir , jsPath ;
jsPath = outputPath ( source , base ) ;
jsDir = path . dirname ( jsPath ) ;
2010-05-14 23:40:04 -04:00
compile = function ( ) {
2011-08-07 02:59:37 -04:00
if ( js . length <= 0 ) js = ' ' ;
2010-06-13 14:21:02 -04:00
return fs . writeFile ( jsPath , js , function ( err ) {
2010-11-08 23:07:51 -05:00
if ( err ) {
2011-10-24 16:19:15 -04:00
return printLine ( err . message ) ;
2010-11-08 23:07:51 -05:00
} else if ( opts . compile && opts . watch ) {
2011-12-18 11:27:02 -05:00
return timeLog ( "compiled " + source ) ;
2010-11-08 23:07:51 -05:00
}
2010-06-13 14:21:02 -04:00
} ) ;
2010-05-04 23:22:28 -04:00
} ;
2011-12-18 11:27:02 -05:00
return path . exists ( jsDir , function ( exists ) {
2010-11-08 23:07:51 -05:00
if ( exists ) {
return compile ( ) ;
} else {
2011-12-18 11:27:02 -05:00
return exec ( "mkdir -p " + jsDir , compile ) ;
2010-11-08 23:07:51 -05:00
}
2010-05-03 17:38:59 -04:00
} ) ;
2010-02-12 22:59:21 -05:00
} ;
2011-09-18 18:16:39 -04:00
2011-12-18 14:26:23 -05:00
wait = function ( milliseconds , func ) {
return setTimeout ( func , milliseconds ) ;
} ;
2011-12-18 11:27:02 -05:00
timeLog = function ( message ) {
return console . log ( "" + ( ( new Date ) . toLocaleTimeString ( ) ) + " - " + message ) ;
} ;
2010-10-24 20:51:55 -04:00
lint = function ( file , js ) {
2010-08-14 16:02:01 -04:00
var conf , jsl , printIt ;
2010-06-12 19:05:13 -04:00
printIt = function ( buffer ) {
2011-10-24 16:19:15 -04:00
return printLine ( file + ':\t' + buffer . toString ( ) . trim ( ) ) ;
2010-04-10 18:05:35 -04:00
} ;
2011-11-08 16:04:10 -05:00
conf = _ _dirname + '/../../extras/jsl.conf' ;
2010-08-14 16:02:01 -04:00
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
} ;
2011-09-18 18:16:39 -04:00
2010-06-12 19:05:13 -04:00
printTokens = function ( tokens ) {
2010-12-13 21:24:32 -05:00
var strings , tag , token , value ;
2010-12-23 13:50:52 -05:00
strings = ( function ( ) {
2011-03-28 17:12:27 -04:00
var _i , _len , _ref2 , _results ;
2010-11-09 00:17:08 -05:00
_results = [ ] ;
2011-12-21 14:37:38 -05:00
for ( _i = 0 , _len = tokens . length ; _i < _len ; _i ++ ) {
2010-10-01 18:26:37 -04:00
token = tokens [ _i ] ;
2011-03-28 17:12:27 -04:00
_ref2 = [ token [ 0 ] , token [ 1 ] . toString ( ) . replace ( /\n/ , '\\n' ) ] , tag = _ref2 [ 0 ] , value = _ref2 [ 1 ] ;
2010-11-09 00:17:08 -05:00
_results . push ( "[" + tag + " " + value + "]" ) ;
2010-02-24 18:56:32 -05:00
}
2010-11-09 00:17:08 -05:00
return _results ;
2010-12-23 13:50:52 -05:00
} ) ( ) ;
2011-10-24 16:19:15 -04:00
return printLine ( strings . join ( ' ' ) ) ;
2010-02-24 18:56:32 -05:00
} ;
2011-09-18 18:16:39 -04:00
2010-06-12 19:05:13 -04:00
parseOptions = function ( ) {
2011-12-21 14:06:34 -05:00
var i , o , source , _i , _len ;
2010-12-18 09:29:04 -05:00
optionParser = new optparse . OptionParser ( SWITCHES , BANNER ) ;
2010-10-20 13:29:06 -04:00
o = opts = optionParser . parse ( process . argv . slice ( 2 ) ) ;
2010-10-01 18:17:35 -04:00
o . compile || ( o . compile = ! ! o . output ) ;
2010-08-15 08:32:09 -04:00
o . run = ! ( o . compile || o . print || o . lint ) ;
o . print = ! ! ( o . print || ( o . eval || o . stdio && o . compile ) ) ;
2011-12-18 11:27:02 -05:00
sources = o . arguments ;
2011-12-21 14:06:34 -05:00
for ( i = _i = 0 , _len = sources . length ; _i < _len ; i = ++ _i ) {
2011-12-18 11:27:02 -05:00
source = sources [ i ] ;
sourceCode [ i ] = null ;
}
2010-02-11 01:57:33 -05:00
} ;
2011-09-18 18:16:39 -04:00
2011-01-15 10:46:53 -05:00
compileOptions = function ( filename ) {
2010-10-13 15:09:56 -04:00
return {
2011-01-15 10:46:53 -05:00
filename : filename ,
2010-12-18 09:29:04 -05:00
bare : opts . bare
2010-03-07 22:08:24 -05:00
} ;
2010-02-24 18:18:29 -05:00
} ;
2011-09-18 18:16:39 -04:00
2010-12-18 09:29:04 -05:00
forkNode = function ( ) {
var args , nodeArgs ;
nodeArgs = opts . nodejs . split ( /\s+/ ) ;
args = process . argv . slice ( 1 ) ;
args . splice ( args . indexOf ( '--nodejs' ) , 2 ) ;
return spawn ( process . execPath , nodeArgs . concat ( args ) , {
2010-12-17 02:39:39 -05:00
cwd : process . cwd ( ) ,
env : process . env ,
customFds : [ 0 , 1 , 2 ]
} ) ;
} ;
2011-09-18 18:16:39 -04:00
2010-05-14 23:40:04 -04:00
usage = function ( ) {
2011-10-24 16:19:15 -04:00
return printLine ( ( new optparse . OptionParser ( SWITCHES , BANNER ) ) . help ( ) ) ;
2010-03-07 00:28:58 -05:00
} ;
2011-09-18 18:16:39 -04:00
2010-05-14 23:40:04 -04:00
version = function ( ) {
2011-10-24 16:19:15 -04:00
return printLine ( "CoffeeScript version " + CoffeeScript . VERSION ) ;
2010-03-07 00:28:58 -05:00
} ;
2011-12-14 10:39:20 -05:00
2010-09-21 03:53:58 -04:00
} ) . call ( this ) ;