Skip to content

Commit

Permalink
added experimental (but working) method to install CoffeeScript: 'sud…
Browse files Browse the repository at this point in the history
…o bin/cake install' -- once you've done that, you can take cake and coffee out of their bin/
  • Loading branch information
jashkenas committed Feb 17, 2010
1 parent 2d0ad73 commit 0490cb2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 15 deletions.
9 changes: 9 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ run: (args) ->
proc.addListener 'error', (err) -> if err then puts err


task 'install', 'install CoffeeScript into /usr/local', ->
exec([
'mkdir -p /usr/local/lib/coffee-script'
'cp -rf bin lib LICENSE README package.json src vendor /usr/local/lib/coffee-script'
'ln -sf /usr/local/lib/coffee-script/bin/coffee /usr/local/bin/coffee'
'ln -sf /usr/local/lib/coffee-script/bin/cake /usr/local/bin/cake'
].join(' && '))


task 'build', 'build the CoffeeScript language from source', ->
fs.readdir('src').addCallback (files) ->
files: 'src/' + file for file in files when file.match(/\.coffee$/)
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CoffeeScript is a little language that compiles into JavaScript.

Install the compiler:
... to be determined ...
sudo bin/cake install

Compile a script:
coffee /path/to/script.coffee
Expand Down
1 change: 1 addition & 0 deletions bin/cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

process.mixin(require('sys'));

require.paths.unshift('/usr/local/lib/coffee-script/lib');
require.paths.unshift('./lib');

require('cake').run();
1 change: 1 addition & 0 deletions bin/coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

process.mixin(require('sys'));

require.paths.unshift('/usr/local/lib/coffee-script/lib');
require.paths.unshift('./lib');

require('command_line').run();
18 changes: 8 additions & 10 deletions lib/repl.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
(function(){
var coffee, prompt, quit, readline, run;
var coffee, prompt, quit, readline;
// A CoffeeScript port/version of the Node.js REPL.
// Required modules.
coffee = require('coffee-script');
process.mixin(require('sys'));
// Shortcut variables.
prompt = 'coffee> ';
quit = function quit() {
return process.stdio.close();
return process.exit(0);
};
// The main REPL function. Called everytime a line of code is entered.
readline = function readline(code) {
return run(coffee.compile(code, {
no_wrap: true,
globals: true
}));
};
// Attempt to evaluate the command. If there's an exception, print it.
run = function run(js) {
var val;
readline = function readline(code) {
var js, val;
try {
js = coffee.compile(code, {
no_wrap: true,
globals: true
});
val = eval(js);
if (val !== undefined) {
p(val);
Expand Down
7 changes: 3 additions & 4 deletions src/repl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ process.mixin require 'sys'

# Shortcut variables.
prompt: 'coffee> '
quit: -> process.stdio.close()
quit: -> process.exit(0)

# The main REPL function. Called everytime a line of code is entered.
readline: (code) -> run coffee.compile code, {no_wrap: true, globals: true}

# Attempt to evaluate the command. If there's an exception, print it.
run: (js) ->
readline: (code) ->
try
js: coffee.compile code, {no_wrap: true, globals: true}
val: eval(js)
p val if val isnt undefined
catch err
Expand Down

0 comments on commit 0490cb2

Please sign in to comment.