From 7ae8687a3eb42b36fa54aa4fd63815c9c91cbda8 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Sun, 27 Dec 2009 12:43:05 -0800 Subject: [PATCH] fixing paths for running coffee compiles CoffeeScript source files into JavaScript. Usage: coffee path/to/script.coffee -i, --interactive run a CoffeeScript REPL (requires Narwhal) -r, --run compile and run a script (requires Narwhal) -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 -e, --eval compile a cli scriptlet or read from stdin -t, --tokens print the tokens that the lexer produces -v, --verbose print at every step of code generation -n, --no-wrap raw output, no safety wrapper or vars --install-bundle install the CoffeeScript TextMate bundle --version display CoffeeScript version -h, --help display this help message outside of the coffee-script directory --- lib/coffee_script/command_line.rb | 7 +++++-- lib/coffee_script/narwhal/coffee-script.coffee | 6 ++++-- lib/coffee_script/narwhal/js/coffee-script.js | 13 ++++++++++--- lib/coffee_script/narwhal/js/launcher.js | 2 +- lib/coffee_script/narwhal/js/loader.js | 5 ++--- lib/coffee_script/narwhal/launcher.coffee | 2 +- lib/coffee_script/narwhal/loader.coffee | 2 +- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/lib/coffee_script/command_line.rb b/lib/coffee_script/command_line.rb index afa5fdab..1074d911 100644 --- a/lib/coffee_script/command_line.rb +++ b/lib/coffee_script/command_line.rb @@ -19,6 +19,9 @@ Usage: # Seconds to pause between checks for changed source files. WATCH_INTERVAL = 0.5 + # Path to the Narwhal Launcher: + LAUNCHER = File.expand_path(File.dirname(__FILE__)) + '/narwhal/js/launcher.js' + # Run the CommandLine off the contents of ARGV. def initialize @mtimes = {} @@ -104,7 +107,7 @@ Usage: # Use Narwhal to run an interactive CoffeeScript session. def launch_repl - exec "narwhal lib/coffee_script/narwhal/js/launcher.js" + exec "narwhal #{LAUNCHER}" rescue Errno::ENOENT puts "Error: Narwhal must be installed to use the interactive REPL." exit(1) @@ -113,7 +116,7 @@ Usage: # Use Narwhal to compile and execute CoffeeScripts. def run_scripts sources = @sources.join(' ') - exec "narwhal lib/coffee_script/narwhal/js/launcher.js #{sources}" + exec "narwhal #{LAUNCHER} #{sources}" rescue Errno::ENOENT puts "Error: Narwhal must be installed in order to execute CoffeeScripts." exit(1) diff --git a/lib/coffee_script/narwhal/coffee-script.coffee b/lib/coffee_script/narwhal/coffee-script.coffee index 5271b29d..2a4d8f58 100644 --- a/lib/coffee_script/narwhal/coffee-script.coffee +++ b/lib/coffee_script/narwhal/coffee-script.coffee @@ -21,7 +21,9 @@ checkForErrors: coffeeProcess => # command. exports.run: args => args.shift() - return require(File.absolute(args[0])) if args.length + if args.length + exports.evalCS(File.read(path)) for path in args. + return true. while true try @@ -51,7 +53,7 @@ exports.evalCS: source => # Make a factory for the CoffeeScript environment. exports.makeNarwhalFactory: path => code: exports.compileFile(path) - factoryText: "function(require,exports,module,system,print){" + code + "/**/\n}" + factoryText: "function(require,exports,module,system,print){ 1 + 1 /**/\n}" if system.engine is "rhino" Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null) else diff --git a/lib/coffee_script/narwhal/js/coffee-script.js b/lib/coffee_script/narwhal/js/coffee-script.js index 4be0e13d..dc283606 100644 --- a/lib/coffee_script/narwhal/js/coffee-script.js +++ b/lib/coffee_script/narwhal/js/coffee-script.js @@ -18,10 +18,17 @@ // Run a simple REPL, round-tripping to the CoffeeScript compiler for every // command. exports.run = function(args) { - var result; + var __a, __b, __c, __d, path, result; args.shift(); if (args.length) { - return require(File.absolute(args[0])); + __a = args; + __d = []; + for (__b=0, __c=__a.length; __b<__c; __b++) { + path = __a[__b]; + __d[__b] = exports.evalCS(File.read(path)); + } + __d; + return true; } while (true) { try { @@ -58,7 +65,7 @@ exports.makeNarwhalFactory = function(path) { var code, factoryText; code = exports.compileFile(path); - factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}"; + factoryText = "function(require,exports,module,system,print){ 1 + 1 /**/\n}"; if (system.engine === "rhino") { return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null); } else { diff --git a/lib/coffee_script/narwhal/js/launcher.js b/lib/coffee_script/narwhal/js/launcher.js index 953c677e..c8442a18 100644 --- a/lib/coffee_script/narwhal/js/launcher.js +++ b/lib/coffee_script/narwhal/js/launcher.js @@ -1,3 +1,3 @@ (function(){ - require("coffee-script").run(system.args); + require("./coffee-script").run(system.args); })(); \ No newline at end of file diff --git a/lib/coffee_script/narwhal/js/loader.js b/lib/coffee_script/narwhal/js/loader.js index 35b52274..cf4c1ed4 100644 --- a/lib/coffee_script/narwhal/js/loader.js +++ b/lib/coffee_script/narwhal/js/loader.js @@ -7,9 +7,8 @@ loader = { // Reload the coffee-script environment from source. reload: function(topId, path) { - coffeescript = coffeescript || require('coffee-script'); - factories[topId] = coffeescript.makeNarwhalFactory(path); - return factories[topId]; + coffeescript = coffeescript || require('./coffee-script'); + return (factories[topId] = coffeescript.makeNarwhalFactory(path)); }, // Ensure that the coffee-script environment is loaded. load: function(topId, path) { diff --git a/lib/coffee_script/narwhal/launcher.coffee b/lib/coffee_script/narwhal/launcher.coffee index 26fe7ac3..ec83edef 100644 --- a/lib/coffee_script/narwhal/launcher.coffee +++ b/lib/coffee_script/narwhal/launcher.coffee @@ -1 +1 @@ -require("coffee-script").run(system.args) \ No newline at end of file +require("./coffee-script").run(system.args) \ No newline at end of file diff --git a/lib/coffee_script/narwhal/loader.coffee b/lib/coffee_script/narwhal/loader.coffee index 509a533e..9797408a 100644 --- a/lib/coffee_script/narwhal/loader.coffee +++ b/lib/coffee_script/narwhal/loader.coffee @@ -7,7 +7,7 @@ loader: { # Reload the coffee-script environment from source. reload: topId, path => - coffeescript ||= require('coffee-script') + coffeescript ||= require('./coffee-script') factories[topId]: coffeescript.makeNarwhalFactory(path). # Ensure that the coffee-script environment is loaded.