changed bin/coffee-script to bin/coffee

This commit is contained in:
Jeremy Ashkenas
2009-12-26 08:57:13 -08:00
parent 6a30d48ced
commit 3c67d54bbe
12 changed files with 61 additions and 39 deletions

2
README
View File

@@ -26,7 +26,7 @@
gem install coffee-script gem install coffee-script
Compile a script: Compile a script:
coffee-script /path/to/script.coffee coffee /path/to/script.coffee
For documentation, usage, and examples, see: For documentation, usage, and examples, see:
http://jashkenas.github.com/coffee-script/ http://jashkenas.github.com/coffee-script/

View File

@@ -19,7 +19,7 @@ namespace :build do
desc "Compile the Narwhal interface for --interactive and --run" desc "Compile the Narwhal interface for --interactive and --run"
task :narwhal do task :narwhal do
sh "bin/coffee-script lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js" sh "bin/coffee lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js"
end end
end end
@@ -27,7 +27,7 @@ end
desc "Build the documentation page" desc "Build the documentation page"
task :doc do task :doc do
source = 'documentation/index.html.erb' source = 'documentation/index.html.erb'
child = fork { exec "bin/coffee-script documentation/coffee/*.coffee -o documentation/js -w" } child = fork { exec "bin/coffee documentation/coffee/*.coffee -o documentation/js -w" }
at_exit { Process.kill("INT", child) } at_exit { Process.kill("INT", child) }
Signal.trap("INT") { exit } Signal.trap("INT") { exit }
loop do loop do

View File

@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
s.has_rdoc = false s.has_rdoc = false
s.require_paths = ['lib'] s.require_paths = ['lib']
s.executables = ['coffee-script'] 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']
end end

View File

@@ -91,12 +91,12 @@
gem install coffee-script</pre> gem install coffee-script</pre>
<p> <p>
Installing the gem provides the <tt>coffee-script</tt> command, which can Installing the gem provides the <tt>coffee</tt> command, which can
be used to compile CoffeeScript <tt>.coffee</tt> files into JavaScript, as be used to compile CoffeeScript <tt>.coffee</tt> files into JavaScript, as
well as debug them. In conjunction with well as debug them. In conjunction with
<a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee-script</tt> <a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee</tt>
command also provides direct evaluation and an interactive REPL. command also provides direct evaluation and an interactive REPL.
When compiling to JavaScript, <tt>coffee-script</tt> writes the output When compiling to JavaScript, <tt>coffee</tt> writes the output
as <tt>.js</tt> files in the same directory by default, but output as <tt>.js</tt> files in the same directory by default, but output
can be customized with the following options: can be customized with the following options:
</p> </p>
@@ -148,7 +148,7 @@ gem install coffee-script</pre>
<td><code>-e, --eval</code></td> <td><code>-e, --eval</code></td>
<td> <td>
Compile and print a little snippet of CoffeeScript directly from the Compile and print a little snippet of CoffeeScript directly from the
command line (or from <b>stdin</b>). For example:<br /><tt>coffee-script -e "square: x => x * x."</tt> command line (or from <b>stdin</b>). For example:<br /><tt>coffee -e "square: x => x * x."</tt>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -187,10 +187,10 @@ gem install coffee-script</pre>
</p> </p>
<pre> <pre>
coffee-script path/to/script.coffee coffee path/to/script.coffee
coffee-script --interactive coffee --interactive
coffee-script --watch --lint experimental.coffee coffee --watch --lint experimental.coffee
coffee-script --print app/scripts/*.coffee > concatenation.js</pre> coffee --print app/scripts/*.coffee > concatenation.js</pre>
<h2>Language Reference</h2> <h2>Language Reference</h2>
@@ -470,7 +470,7 @@ coffee-script --print app/scripts/*.coffee > concatenation.js</pre>
<p> <p>
<b class="header" style="margin-top: 20px;">0.1.3</b> <b class="header" style="margin-top: 20px;">0.1.3</b>
The <tt>coffee-script</tt> command now includes <tt>--interactive</tt>, The <tt>coffee</tt> command now includes <tt>--interactive</tt>,
which launches an interactive CoffeeScript session, and <tt>--run</tt>, which launches an interactive CoffeeScript session, and <tt>--run</tt>,
which directly compiles and executes a script. Both options depend on a which directly compiles and executes a script. Both options depend on a
working installation of Narwhal. working installation of Narwhal.

View File

@@ -1,5 +1,5 @@
(function(){ (function(){
var __a, __b, __c, __d, __e, __f, __g, __h, food, i, lunch, row; var __a, __b, __c, __d, __e, __f, __g, __h, __i, __j, __k, __l, food, i, lunch, row;
// Eat lunch. // Eat lunch.
__a = ['toast', 'cheese', 'wine']; __a = ['toast', 'cheese', 'wine'];
__d = []; __d = [];
@@ -17,4 +17,10 @@
__h[__f] = i % 2 === 0 ? highlight(row) : null; __h[__f] = i % 2 === 0 ? highlight(row) : null;
} }
__h; __h;
// Check the first one hundred combinations.
__k = [];
for (__l=0, i=1, __j=100; i<=__j; i++, __l++) {
__k[__l] = lockpick(combinations[i]);
}
__k;
})(); })();

View File

@@ -159,12 +159,12 @@ cubed_list = __d;
gem install coffee-script</pre> gem install coffee-script</pre>
<p> <p>
Installing the gem provides the <tt>coffee-script</tt> command, which can Installing the gem provides the <tt>coffee</tt> command, which can
be used to compile CoffeeScript <tt>.coffee</tt> files into JavaScript, as be used to compile CoffeeScript <tt>.coffee</tt> files into JavaScript, as
well as debug them. In conjunction with well as debug them. In conjunction with
<a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee-script</tt> <a href="http://narwhaljs.org/">Narwhal</a>, the <tt>coffee</tt>
command also provides direct evaluation and an interactive REPL. command also provides direct evaluation and an interactive REPL.
When compiling to JavaScript, <tt>coffee-script</tt> writes the output When compiling to JavaScript, <tt>coffee</tt> writes the output
as <tt>.js</tt> files in the same directory by default, but output as <tt>.js</tt> files in the same directory by default, but output
can be customized with the following options: can be customized with the following options:
</p> </p>
@@ -216,7 +216,7 @@ gem install coffee-script</pre>
<td><code>-e, --eval</code></td> <td><code>-e, --eval</code></td>
<td> <td>
Compile and print a little snippet of CoffeeScript directly from the Compile and print a little snippet of CoffeeScript directly from the
command line (or from <b>stdin</b>). For example:<br /><tt>coffee-script -e "square: x => x * x."</tt> command line (or from <b>stdin</b>). For example:<br /><tt>coffee -e "square: x => x * x."</tt>
</td> </td>
</tr> </tr>
<tr> <tr>
@@ -255,10 +255,10 @@ gem install coffee-script</pre>
</p> </p>
<pre> <pre>
coffee-script path/to/script.coffee coffee path/to/script.coffee
coffee-script --interactive coffee --interactive
coffee-script --watch --lint experimental.coffee coffee --watch --lint experimental.coffee
coffee-script --print app/scripts/*.coffee > concatenation.js</pre> coffee --print app/scripts/*.coffee > concatenation.js</pre>
<h2>Language Reference</h2> <h2>Language Reference</h2>
@@ -580,7 +580,10 @@ lunch<span class="Keyword">:</span> food.eat() <span class="Keyword">for</span>
<span class="Comment"><span class="Comment">#</span> Zebra-stripe a table.</span> <span class="Comment"><span class="Comment">#</span> Zebra-stripe a table.</span>
highlight(row) <span class="Keyword">for</span> row, i <span class="Keyword">in</span> table <span class="Keyword">if</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">is</span> <span class="Number">0</span>. highlight(row) <span class="Keyword">for</span> row, i <span class="Keyword">in</span> table <span class="Keyword">if</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">is</span> <span class="Number">0</span>.
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, __e, __f, __g, __h, food, i, lunch, row;
<span class="Comment"><span class="Comment">#</span> Check the first one hundred combinations.</span>
lockpick(combinations[i]) <span class="Keyword">for</span> i <span class="Keyword">in</span> [<span class="Number">1</span>..<span class="Number">100</span>].
</pre><pre class="idle"><span class="Storage">var</span> __a, __b, __c, __d, __e, __f, __g, __h, __i, __j, __k, __l, food, i, lunch, row;
<span class="Comment"><span class="Comment">//</span> Eat lunch.</span> <span class="Comment"><span class="Comment">//</span> Eat lunch.</span>
__a <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>]; __a <span class="Keyword">=</span> [<span class="String"><span class="String">'</span>toast<span class="String">'</span></span>, <span class="String"><span class="String">'</span>cheese<span class="String">'</span></span>, <span class="String"><span class="String">'</span>wine<span class="String">'</span></span>];
__d <span class="Keyword">=</span> []; __d <span class="Keyword">=</span> [];
@@ -598,6 +601,12 @@ __h <span class="Keyword">=</span> [];
__h[__f] <span class="Keyword">=</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">===</span> <span class="Number">0</span> ? highlight(row) : <span class="BuiltInConstant">null</span>; __h[__f] <span class="Keyword">=</span> i <span class="Keyword">%</span> <span class="Number">2</span> <span class="Keyword">===</span> <span class="Number">0</span> ? highlight(row) : <span class="BuiltInConstant">null</span>;
} }
__h; __h;
<span class="Comment"><span class="Comment">//</span> Check the first one hundred combinations.</span>
__k <span class="Keyword">=</span> [];
<span class="Keyword">for</span> (__l<span class="Keyword">=</span><span class="Number">0</span>, i<span class="Keyword">=</span><span class="Number">1</span>, __j<span class="Keyword">=</span><span class="Number">100</span>; i<span class="Keyword">&lt;=</span>__j; i<span class="Keyword">++</span>, __l<span class="Keyword">++</span>) {
__k[__l] <span class="Keyword">=</span> lockpick(combinations[i]);
}
__k;
</pre><br class='clear' /></div> </pre><br class='clear' /></div>
<p id="slice"> <p id="slice">
@@ -889,7 +898,7 @@ world...";
<p> <p>
<b class="header" style="margin-top: 20px;">0.1.3</b> <b class="header" style="margin-top: 20px;">0.1.3</b>
The <tt>coffee-script</tt> command now includes <tt>--interactive</tt>, The <tt>coffee</tt> command now includes <tt>--interactive</tt>,
which launches an interactive CoffeeScript session, and <tt>--run</tt>, which launches an interactive CoffeeScript session, and <tt>--run</tt>,
which directly compiles and executes a script. Both options depend on a which directly compiles and executes a script. Both options depend on a
working installation of Narwhal. working installation of Narwhal.

View File

@@ -5,15 +5,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../coffee-script')
module CoffeeScript module CoffeeScript
# The CommandLine handles all of the functionality of the `coffee-script` # The CommandLine handles all of the functionality of the `coffee`
# utility. # utility.
class CommandLine class CommandLine
BANNER = <<-EOS BANNER = <<-EOS
coffee-script compiles CoffeeScript source files into JavaScript. coffee compiles CoffeeScript source files into JavaScript.
Usage: Usage:
coffee-script path/to/script.coffee coffee path/to/script.coffee
EOS EOS
# Seconds to pause between checks for changed source files. # Seconds to pause between checks for changed source files.
@@ -190,8 +190,8 @@ Usage:
install_bundle install_bundle
exit exit
end end
opts.on_tail('--version', 'display coffee-script version') do opts.on_tail('--version', 'display CoffeeScript version') do
puts "coffee-script version #{CoffeeScript::VERSION}" puts "CoffeeScript version #{CoffeeScript::VERSION}"
exit exit
end end
opts.on_tail('-h', '--help', 'display this help message') do opts.on_tail('-h', '--help', 'display this help message') do

View File

@@ -1,6 +1,6 @@
# This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee # This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee
# Executes the `coffee-script` Ruby program to convert from CoffeeScript # Executes the `coffee` Ruby program to convert from CoffeeScript
# to Javascript. Eventually this will hopefully happen entirely within JS. # to Javascript. Eventually this will hopefully happen entirely within JS.
# Require external dependencies. # Require external dependencies.
@@ -9,13 +9,13 @@ 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().dirname().dirname().dirname().join('bin', 'coffee-script') coffeePath: File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee')
# Our general-purpose error handler. # Our general-purpose error handler.
checkForErrors: coffeeProcess => checkForErrors: coffeeProcess =>
return true if coffeeProcess.wait() is 0 return true if coffeeProcess.wait() is 0
system.stderr.print(coffeeProcess.stderr.read()) system.stderr.print(coffeeProcess.stderr.read())
throw new Error("coffee-script compile error"). throw new Error("CoffeeScript compile error").
# Run a simple REPL, round-tripping to the CoffeeScript compiler for every # Run a simple REPL, round-tripping to the CoffeeScript compiler for every
# command. # command.

View File

@@ -1,19 +1,19 @@
(function(){ (function(){
var File, OS, Readline, checkForErrors, coffeePath; var File, OS, Readline, checkForErrors, coffeePath;
// This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee Executes the `coffee-script` Ruby program to convert from CoffeeScript // This (javascript) file is generated from lib/coffee_script/narwhal/coffee-script.coffee Executes the `coffee` Ruby program to convert from CoffeeScript
// to Javascript. Eventually this will hopefully happen entirely within JS. Require external dependencies. // to Javascript. Eventually this will hopefully happen entirely within JS. Require external dependencies.
OS = require('os'); OS = require('os');
File = require('file'); 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().dirname().dirname().dirname().join('bin', 'coffee-script'); coffeePath = File.path(module.path).dirname().dirname().dirname().dirname().dirname().join('bin', 'coffee');
// Our general-purpose error handler. // Our general-purpose error handler.
checkForErrors = function(coffeeProcess) { checkForErrors = function(coffeeProcess) {
if (coffeeProcess.wait() === 0) { if (coffeeProcess.wait() === 0) {
return true; return true;
} }
system.stderr.print(coffeeProcess.stderr.read()); system.stderr.print(coffeeProcess.stderr.read());
throw new Error("coffee-script compile error"); throw new Error("CoffeeScript compile error");
}; };
// Run a simple REPL, round-tripping to the CoffeeScript compiler for every // Run a simple REPL, round-tripping to the CoffeeScript compiler for every
// command. // command.

View File

@@ -320,6 +320,13 @@ module CoffeeScript
@exclusive @exclusive
end end
# TODO -- figure out if we can detect if a range runs negative.
def downward?
end
# TODO -- figure out if we can expand ranges into the corresponding array,
# as an expression, reliably.
def compile(o={}) def compile(o={})
write() write()
end end

View File

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