mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 03:21:20 -05:00
removed bin/cs in favor of a more comprehensive coffee-script command ... now with --interactive and --run
This commit is contained in:
5
Rakefile
5
Rakefile
@@ -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
3
bin/cs
@@ -1,3 +0,0 @@
|
|||||||
#!/usr/bin/env narwhal
|
|
||||||
|
|
||||||
require("coffee-script").run(system.args);
|
|
||||||
@@ -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|
|
||||||
|
|||||||
@@ -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 =>
|
||||||
|
|||||||
@@ -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 + ")");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
3
lib/coffee_script/narwhal/js/launcher.js
Normal file
3
lib/coffee_script/narwhal/js/launcher.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
(function(){
|
||||||
|
require("coffee-script").run(system.args);
|
||||||
|
})();
|
||||||
@@ -17,4 +17,4 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
require.loader.loaders.unshift([".cs", loader]);
|
require.loader.loaders.unshift([".cs", loader]);
|
||||||
})();
|
})();
|
||||||
1
lib/coffee_script/narwhal/launcher.cs
Normal file
1
lib/coffee_script/narwhal/launcher.cs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("coffee-script").run(system.args)
|
||||||
@@ -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",
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user