diff --git a/Rakefile b/Rakefile index 51f7b2a3..c7768517 100644 --- a/Rakefile +++ b/Rakefile @@ -19,7 +19,8 @@ namespace :build do desc "Compile the Narwhal interface for --interactive and --run" task :narwhal do - sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js" + sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/lib/coffee-script" + sh "mv lib/coffee_script/narwhal/lib/coffee-script/coffee-script.js lib/coffee_script/narwhal/lib/coffee-script.js" end end diff --git a/coffee-script.gemspec b/coffee-script.gemspec index ef684aa0..ec801ec3 100644 --- a/coffee-script.gemspec +++ b/coffee-script.gemspec @@ -22,5 +22,5 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.executables = ['coffee'] - s.files = Dir['bin/*', 'examples/*', 'lib/**/*', 'coffee-script.gemspec', 'LICENSE', 'README'] + s.files = Dir['bin/*', 'examples/*', 'lib/**/*', 'coffee-script.gemspec', 'LICENSE', 'README', 'package.json'] end \ No newline at end of file diff --git a/lib/coffee_script/command_line.rb b/lib/coffee_script/command_line.rb index 1074d911..fe5898d2 100644 --- a/lib/coffee_script/command_line.rb +++ b/lib/coffee_script/command_line.rb @@ -19,8 +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' + # Command to execute in Narwhal + PACKAGE = File.dirname(File.dirname(File.dirname(__FILE__))) + LAUNCHER = "narwhal -p #{PACKAGE} -e 'require(\"coffee-script\").run(system.args);'" # Run the CommandLine off the contents of ARGV. def initialize @@ -107,7 +108,7 @@ Usage: # Use Narwhal to run an interactive CoffeeScript session. def launch_repl - exec "narwhal #{LAUNCHER}" + exec "#{LAUNCHER}" rescue Errno::ENOENT puts "Error: Narwhal must be installed to use the interactive REPL." exit(1) @@ -116,7 +117,7 @@ Usage: # Use Narwhal to compile and execute CoffeeScripts. def run_scripts sources = @sources.join(' ') - exec "narwhal #{LAUNCHER} #{sources}" + exec "#{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/js/launcher.js b/lib/coffee_script/narwhal/js/launcher.js deleted file mode 100644 index c8442a18..00000000 --- a/lib/coffee_script/narwhal/js/launcher.js +++ /dev/null @@ -1,3 +0,0 @@ -(function(){ - require("./coffee-script").run(system.args); -})(); \ No newline at end of file diff --git a/lib/coffee_script/narwhal/launcher.coffee b/lib/coffee_script/narwhal/launcher.coffee deleted file mode 100644 index ec83edef..00000000 --- a/lib/coffee_script/narwhal/launcher.coffee +++ /dev/null @@ -1 +0,0 @@ -require("./coffee-script").run(system.args) \ No newline at end of file diff --git a/lib/coffee_script/narwhal/js/coffee-script.js b/lib/coffee_script/narwhal/lib/coffee-script.js similarity index 99% rename from lib/coffee_script/narwhal/js/coffee-script.js rename to lib/coffee_script/narwhal/lib/coffee-script.js index dc283606..08204763 100644 --- a/lib/coffee_script/narwhal/js/coffee-script.js +++ b/lib/coffee_script/narwhal/lib/coffee-script.js @@ -65,7 +65,7 @@ exports.makeNarwhalFactory = function(path) { var code, factoryText; code = exports.compileFile(path); - factoryText = "function(require,exports,module,system,print){ 1 + 1 /**/\n}"; + factoryText = "function(require,exports,module,system,print){ " + code + " /**/\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/loader.js b/lib/coffee_script/narwhal/lib/coffee-script/loader.js similarity index 90% rename from lib/coffee_script/narwhal/js/loader.js rename to lib/coffee_script/narwhal/lib/coffee-script/loader.js index cf4c1ed4..1a79dbbb 100644 --- a/lib/coffee_script/narwhal/js/loader.js +++ b/lib/coffee_script/narwhal/lib/coffee-script/loader.js @@ -7,7 +7,7 @@ loader = { // Reload the coffee-script environment from source. reload: function(topId, path) { - coffeescript = coffeescript || require('./coffee-script'); + coffeescript = coffeescript || require('coffee-script'); return (factories[topId] = coffeescript.makeNarwhalFactory(path)); }, // Ensure that the coffee-script environment is loaded. diff --git a/lib/coffee_script/narwhal/loader.coffee b/lib/coffee_script/narwhal/loader.coffee index 9797408a..509a533e 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. diff --git a/package.json b/package.json index 7d83b675..d3811285 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "coffee-script", - "lib": "lib/coffee_script/narwhal/js", - "preload": ["loader"], + "lib": "lib/coffee_script/narwhal/lib", + "preload": ["coffee-script/loader"], "description": "Unfancy JavaScript", "keywords": ["javascript", "language"], "author": "Jeremy Ashkenas",