mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
trading the cs> prompt for the coffee> prompt
This commit is contained in:
@@ -25,7 +25,7 @@ exports.run: args =>
|
|||||||
|
|
||||||
while true
|
while true
|
||||||
try
|
try
|
||||||
system.stdout.write('cs> ').flush()
|
system.stdout.write('coffee> ').flush()
|
||||||
result: exports.evalCS(Readline.readline())
|
result: exports.evalCS(Readline.readline())
|
||||||
print(result) if result isnt undefined
|
print(result) if result isnt undefined
|
||||||
catch e
|
catch e
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
(function(){
|
(function(){
|
||||||
|
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-script` 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.
|
||||||
var OS = require('os');
|
OS = require('os');
|
||||||
var File = require('file');
|
File = require('file');
|
||||||
var Readline = require('readline');
|
Readline = require('readline');
|
||||||
// The path to the CoffeeScript Compiler.
|
// The path to the CoffeeScript Compiler.
|
||||||
var 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-script');
|
||||||
// Our general-purpose error handler.
|
// Our general-purpose error handler.
|
||||||
var checkForErrors = function(coffeeProcess) {
|
checkForErrors = function(coffeeProcess) {
|
||||||
if (coffeeProcess.wait() === 0) {
|
if (coffeeProcess.wait() === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -18,14 +18,15 @@
|
|||||||
// 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.
|
||||||
exports.run = function(args) {
|
exports.run = function(args) {
|
||||||
|
var result;
|
||||||
args.shift();
|
args.shift();
|
||||||
if (args.length) {
|
if (args.length) {
|
||||||
return require(File.absolute(args[0]));
|
return require(File.absolute(args[0]));
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
system.stdout.write('cs> ').flush();
|
system.stdout.write('coffee> ').flush();
|
||||||
var result = exports.evalCS(Readline.readline());
|
result = exports.evalCS(Readline.readline());
|
||||||
if (result !== undefined) {
|
if (result !== undefined) {
|
||||||
print(result);
|
print(result);
|
||||||
}
|
}
|
||||||
@@ -36,13 +37,15 @@
|
|||||||
};
|
};
|
||||||
// Compile a given CoffeeScript file into JavaScript.
|
// Compile a given CoffeeScript file into JavaScript.
|
||||||
exports.compileFile = function(path) {
|
exports.compileFile = function(path) {
|
||||||
var coffee = OS.popen([coffeePath, "--print", "--no-wrap", path]);
|
var coffee;
|
||||||
|
coffee = OS.popen([coffeePath, "--print", "--no-wrap", path]);
|
||||||
checkForErrors(coffee);
|
checkForErrors(coffee);
|
||||||
return coffee.stdout.read();
|
return coffee.stdout.read();
|
||||||
};
|
};
|
||||||
// Compile a string of CoffeeScript into JavaScript.
|
// Compile a string of CoffeeScript into JavaScript.
|
||||||
exports.compile = function(source) {
|
exports.compile = function(source) {
|
||||||
var coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
|
var coffee;
|
||||||
|
coffee = OS.popen([coffeePath, "--eval", "--no-wrap"]);
|
||||||
coffee.stdin.write(source).flush().close();
|
coffee.stdin.write(source).flush().close();
|
||||||
checkForErrors(coffee);
|
checkForErrors(coffee);
|
||||||
return coffee.stdout.read();
|
return coffee.stdout.read();
|
||||||
@@ -53,8 +56,9 @@
|
|||||||
};
|
};
|
||||||
// Make a factory for the CoffeeScript environment.
|
// Make a factory for the CoffeeScript environment.
|
||||||
exports.makeNarwhalFactory = function(path) {
|
exports.makeNarwhalFactory = function(path) {
|
||||||
var code = exports.compileFile(path);
|
var code, factoryText;
|
||||||
var factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";
|
code = exports.compileFile(path);
|
||||||
|
factoryText = "function(require,exports,module,system,print){" + code + "/**/\n}";
|
||||||
if (system.engine === "rhino") {
|
if (system.engine === "rhino") {
|
||||||
return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null);
|
return Packages.org.mozilla.javascript.Context.getCurrentContext().compileFunction(global, factoryText, path, 0, null);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
(function(){
|
(function(){
|
||||||
|
var coffeescript, factories, loader;
|
||||||
// This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
|
// This (javascript) file is generated from lib/coffee_script/narwhal/loader.coffee
|
||||||
var coffeescript = null;
|
coffeescript = null;
|
||||||
var factories = {
|
factories = {
|
||||||
};
|
};
|
||||||
var loader = {
|
loader = {
|
||||||
// Reload the coffee-script environment from source.
|
// Reload the coffee-script environment from source.
|
||||||
reload: function(topId, path) {
|
reload: function(topId, path) {
|
||||||
coffeescript = coffeescript || require('coffee-script');
|
coffeescript = coffeescript || require('coffee-script');
|
||||||
|
|||||||
Reference in New Issue
Block a user