mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-17 11:01:25 -05:00
call it 'CoffeeScript' in the command_line, so that --run scripts may access it as such
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
(function(){
|
(function(){
|
||||||
var BANNER, SWITCHES, coffee, compile_options, compile_script, compile_scripts, compile_stdio, fs, lint, option_parser, options, optparse, parse_options, path, print_tokens, sources, usage, version, watch_scripts, write_js;
|
var BANNER, CoffeeScript, SWITCHES, compile_options, compile_script, compile_scripts, compile_stdio, fs, lint, option_parser, options, optparse, parse_options, path, print_tokens, sources, usage, version, watch_scripts, write_js;
|
||||||
fs = require('fs');
|
fs = require('fs');
|
||||||
path = require('path');
|
path = require('path');
|
||||||
coffee = require('coffee-script');
|
|
||||||
optparse = require('optparse');
|
optparse = require('optparse');
|
||||||
|
CoffeeScript = require('coffee-script');
|
||||||
BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee";
|
BANNER = "coffee compiles CoffeeScript source files into JavaScript.\n\nUsage:\n coffee path/to/script.coffee";
|
||||||
SWITCHES = [['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-r', '--run', 'compile and run a CoffeeScript'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-n', '--no-wrap', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-tr', '--tree', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
SWITCHES = [['-i', '--interactive', 'run an interactive CoffeeScript REPL'], ['-r', '--run', 'compile and run a CoffeeScript'], ['-o', '--output [DIR]', 'set the directory for compiled JavaScript'], ['-w', '--watch', 'watch scripts for changes, and recompile'], ['-p', '--print', 'print the compiled JavaScript to stdout'], ['-l', '--lint', 'pipe the compiled JavaScript through JSLint'], ['-s', '--stdio', 'listen for and compile scripts over stdio'], ['-e', '--eval', 'compile a string from the command line'], ['-n', '--no-wrap', 'compile without the top-level function wrapper'], ['-t', '--tokens', 'print the tokens that the lexer produces'], ['-tr', '--tree', 'print the parse tree that Jison produces'], ['-v', '--version', 'display CoffeeScript version'], ['-h', '--help', 'display this help message']];
|
||||||
options = {};
|
options = {};
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
};
|
};
|
||||||
// The "--version" message.
|
// The "--version" message.
|
||||||
version = function version() {
|
version = function version() {
|
||||||
puts("CoffeeScript version " + coffee.VERSION);
|
puts("CoffeeScript version " + CoffeeScript.VERSION);
|
||||||
return process.exit(0);
|
return process.exit(0);
|
||||||
};
|
};
|
||||||
// Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
// Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
||||||
@@ -77,11 +77,11 @@
|
|||||||
o = options;
|
o = options;
|
||||||
try {
|
try {
|
||||||
if (o.tokens) {
|
if (o.tokens) {
|
||||||
return print_tokens(coffee.tokenize(code));
|
return print_tokens(CoffeeScript.tokenize(code));
|
||||||
} else if (o.tree) {
|
} else if (o.tree) {
|
||||||
return puts(coffee.tree(code).toString());
|
return puts(CoffeeScript.tree(code).toString());
|
||||||
} else {
|
} else {
|
||||||
js = coffee.compile(code, compile_options());
|
js = CoffeeScript.compile(code, compile_options());
|
||||||
if (o.run) {
|
if (o.run) {
|
||||||
return eval(js);
|
return eval(js);
|
||||||
} else if (o.lint) {
|
} else if (o.lint) {
|
||||||
@@ -111,7 +111,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
return process.stdio.addListener('close', function() {
|
return process.stdio.addListener('close', function() {
|
||||||
return process.stdio.write(coffee.compile(code, compile_options()));
|
return process.stdio.write(CoffeeScript.compile(code, compile_options()));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// Watch a list of source CoffeeScript files, recompiling them every time the
|
// Watch a list of source CoffeeScript files, recompiling them every time the
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
fs: require 'fs'
|
fs: require 'fs'
|
||||||
path: require 'path'
|
path: require 'path'
|
||||||
coffee: require 'coffee-script'
|
optparse: require 'optparse'
|
||||||
optparse: require('optparse')
|
CoffeeScript: require 'coffee-script'
|
||||||
|
|
||||||
BANNER: '''
|
BANNER: '''
|
||||||
coffee compiles CoffeeScript source files into JavaScript.
|
coffee compiles CoffeeScript source files into JavaScript.
|
||||||
@@ -56,7 +56,7 @@ usage: ->
|
|||||||
|
|
||||||
# The "--version" message.
|
# The "--version" message.
|
||||||
version: ->
|
version: ->
|
||||||
puts "CoffeeScript version " + coffee.VERSION
|
puts "CoffeeScript version " + CoffeeScript.VERSION
|
||||||
process.exit 0
|
process.exit 0
|
||||||
|
|
||||||
# Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
# Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
||||||
@@ -71,10 +71,10 @@ compile_scripts: ->
|
|||||||
compile_script: (source, code) ->
|
compile_script: (source, code) ->
|
||||||
o: options
|
o: options
|
||||||
try
|
try
|
||||||
if o.tokens then print_tokens coffee.tokenize code
|
if o.tokens then print_tokens CoffeeScript.tokenize code
|
||||||
else if o.tree then puts coffee.tree(code).toString()
|
else if o.tree then puts CoffeeScript.tree(code).toString()
|
||||||
else
|
else
|
||||||
js: coffee.compile code, compile_options()
|
js: CoffeeScript.compile code, compile_options()
|
||||||
if o.run then eval js
|
if o.run then eval js
|
||||||
else if o.lint then lint js
|
else if o.lint then lint js
|
||||||
else if o.print or o.eval then print js
|
else if o.print or o.eval then print js
|
||||||
@@ -89,7 +89,7 @@ compile_stdio: ->
|
|||||||
process.stdio.addListener 'data', (string) ->
|
process.stdio.addListener 'data', (string) ->
|
||||||
code += string if string
|
code += string if string
|
||||||
process.stdio.addListener 'close', ->
|
process.stdio.addListener 'close', ->
|
||||||
process.stdio.write coffee.compile code, compile_options()
|
process.stdio.write CoffeeScript.compile code, compile_options()
|
||||||
|
|
||||||
# Watch a list of source CoffeeScript files, recompiling them every time the
|
# Watch a list of source CoffeeScript files, recompiling them every time the
|
||||||
# files are updated.
|
# files are updated.
|
||||||
|
|||||||
Reference in New Issue
Block a user