1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

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"
end
desc "Compile the Narwhal interface for bin/cs"
desc "Compile the Narwhal interface for --interactive and --run"
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/loader.cs --print > lib-js/coffee-script/loader.js"
sh "bin/coffee-script lib/coffee_script/narwhal/*.cs -o lib/coffee_script/narwhal/js"
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
@mtimes = {}
parse_options
return launch_repl if @options[:interactive]
return eval_scriptlet if @options[:eval]
check_sources
return run_scripts if @options[:run]
@sources.each {|source| compile_javascript(source) }
watch_coffee_scripts if @options[:watch]
end
@ -100,6 +102,17 @@ Usage:
puts js
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.
def tokens(script)
puts Lexer.new.tokenize(script).inspect
@ -134,6 +147,12 @@ Usage:
def parse_options
@options = {}
@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|
@options[:output] = 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|
@options[:lint] = true
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
end
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')
# 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.
checkForErrors: coffeeProcess =>

View file

@ -6,7 +6,7 @@
var File = require('file');
var Readline = require('readline');
// 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.
var checkForErrors = function(coffeeProcess) {
if (coffeeProcess.wait() === 0) {
@ -62,4 +62,4 @@
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]);
})();
})();

View file

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

View file

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

View file

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