removed bin/cs in favor of a more comprehensive coffee-script command ... now with --interactive and --run

This commit is contained in:
Jeremy Ashkenas
2009-12-24 23:57:27 -08:00
parent 7a0de52c96
commit 73aaf127c8
10 changed files with 33 additions and 14 deletions

View File

@@ -17,10 +17,9 @@ namespace :build do
sh "racc #{args[:extra_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y" sh "racc #{args[:extra_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y"
end end
desc "Compile the Narwhal interface for bin/cs" desc "Compile the Narwhal interface for --interactive and --run"
task :narwhal do task :narwhal do
sh "bin/coffee-script lib/coffee_script/narwhal/coffee-script.cs --print > lib-js/coffee-script.js" sh "bin/coffee-script lib/coffee_script/narwhal/*.cs -o lib/coffee_script/narwhal/js"
sh "bin/coffee-script lib/coffee_script/narwhal/loader.cs --print > lib-js/coffee-script/loader.js"
end end
end end

3
bin/cs
View File

@@ -1,3 +0,0 @@
#!/usr/bin/env narwhal
require("coffee-script").run(system.args);

View File

@@ -23,8 +23,10 @@ Usage:
def initialize def initialize
@mtimes = {} @mtimes = {}
parse_options parse_options
return launch_repl if @options[:interactive]
return eval_scriptlet if @options[:eval] return eval_scriptlet if @options[:eval]
check_sources check_sources
return run_scripts if @options[:run]
@sources.each {|source| compile_javascript(source) } @sources.each {|source| compile_javascript(source) }
watch_coffee_scripts if @options[:watch] watch_coffee_scripts if @options[:watch]
end end
@@ -100,6 +102,17 @@ Usage:
puts js puts js
end end
# Use Narwhal to run an interactive CoffeeScript session.
def launch_repl
exec "narwhal lib/coffee_script/narwhal/js/launcher.js"
end
# Use Narwhal to compile and execute CoffeeScripts.
def run_scripts
sources = @sources.join(' ')
exec "narwhal lib/coffee_script/narwhal/js/launcher.js #{sources}"
end
# Print the tokens that the lexer generates from a source script. # Print the tokens that the lexer generates from a source script.
def tokens(script) def tokens(script)
puts Lexer.new.tokenize(script).inspect puts Lexer.new.tokenize(script).inspect
@@ -134,6 +147,12 @@ Usage:
def parse_options def parse_options
@options = {} @options = {}
@option_parser = OptionParser.new do |opts| @option_parser = OptionParser.new do |opts|
opts.on('-i', '--interactive', 'run a CoffeeScript REPL (requires Narwhal)') do |i|
@options[:interactive] = true
end
opts.on('-r', '--run', 'compile and run a script (requires Narwhal)') do |r|
@options[:run] = true
end
opts.on('-o', '--output [DIR]', 'set the directory for compiled JavaScript') do |d| opts.on('-o', '--output [DIR]', 'set the directory for compiled JavaScript') do |d|
@options[:output] = d @options[:output] = d
FileUtils.mkdir_p(d) unless File.exists?(d) FileUtils.mkdir_p(d) unless File.exists?(d)
@@ -147,7 +166,7 @@ Usage:
opts.on('-l', '--lint', 'pipe the compiled JavaScript through JSLint') do |l| opts.on('-l', '--lint', 'pipe the compiled JavaScript through JSLint') do |l|
@options[:lint] = true @options[:lint] = true
end end
opts.on('-e', '--eval', 'eval a little scriptlet or read from stdin') do |e| opts.on('-e', '--eval', 'compile a cli scriptlet or read from stdin') do |e|
@options[:eval] = true @options[:eval] = true
end end
opts.on('-t', '--tokens', 'print the tokens that the lexer produces') do |t| opts.on('-t', '--tokens', 'print the tokens that the lexer produces') do |t|

View File

@@ -9,7 +9,7 @@ File: require('file')
Readline: require('readline') Readline: require('readline')
# The path to the CoffeeScript Compiler. # The path to the CoffeeScript Compiler.
coffeePath: File.path(module.path).dirname().dirname().join('bin', 'coffee-script') coffeePath: File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee-script')
# Our general-purpose error handler. # Our general-purpose error handler.
checkForErrors: coffeeProcess => checkForErrors: coffeeProcess =>

View File

@@ -6,7 +6,7 @@
var File = require('file'); var File = require('file');
var Readline = require('readline'); var Readline = require('readline');
// The path to the CoffeeScript Compiler. // The path to the CoffeeScript Compiler.
var coffeePath = File.path(module.path).dirname().dirname().join('bin', 'coffee-script'); var coffeePath = File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee-script');
// Our general-purpose error handler. // Our general-purpose error handler.
var checkForErrors = function(coffeeProcess) { var checkForErrors = function(coffeeProcess) {
if (coffeeProcess.wait() === 0) { if (coffeeProcess.wait() === 0) {
@@ -62,4 +62,4 @@
return eval("(" + factoryText + ")"); return eval("(" + factoryText + ")");
} }
}; };
})(); })();

View File

@@ -0,0 +1,3 @@
(function(){
require("coffee-script").run(system.args);
})();

View File

@@ -17,4 +17,4 @@
} }
}; };
require.loader.loaders.unshift([".cs", loader]); require.loader.loaders.unshift([".cs", loader]);
})(); })();

View File

@@ -0,0 +1 @@
require("coffee-script").run(system.args)

View File

@@ -1,7 +1,7 @@
{ {
"name": "coffee-script", "name": "coffee-script",
"lib": "lib-js", "lib": "lib/coffee_script/narwhal/js",
"preload": ["coffee-script/loader"], "preload": ["loader"],
"description": "Unfancy JavaScript", "description": "Unfancy JavaScript",
"keywords": ["javascript", "language"], "keywords": ["javascript", "language"],
"author": "Jeremy Ashkenas", "author": "Jeremy Ashkenas",

View File

@@ -7,7 +7,7 @@ class ExecutionTest < Test::Unit::TestCase
def test_execution_of_coffeescript def test_execution_of_coffeescript
sources = ['test/fixtures/execution/*.cs'].join(' ') sources = ['test/fixtures/execution/*.cs'].join(' ')
assert `bin/cs #{sources}`.match(ALLS_WELL) assert `bin/coffee-script -r #{sources}`.match(ALLS_WELL)
end end
def test_lintless_coffeescript def test_lintless_coffeescript