Removing the mixed-in sys/util module. Switching from 'puts' to console.log

This commit is contained in:
Jeremy Ashkenas 2010-10-24 12:48:42 -04:00
parent aed0e8790e
commit 26a115adcf
23 changed files with 86 additions and 89 deletions

View File

@ -11,12 +11,12 @@ reset = '\033[0m'
# Run a CoffeeScript through our node/coffee interpreter.
run = (args) ->
proc = spawn 'bin/coffee', args
proc.stderr.on 'data', (buffer) -> puts buffer.toString()
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
proc.on 'exit', (status) -> process.exit(1) if status != 0
# Log a message with a color.
log = (message, color, explanation) ->
puts color + message + reset + ' ' + (explanation or '')
console.log color + message + reset + ' ' + (explanation or '')
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
@ -25,9 +25,9 @@ task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options)
lib = "#{base}/lib/coffee-script"
bin = "#{base}/bin"
node = "~/.node_libraries/coffee-script"
puts "Installing CoffeeScript to #{lib}"
puts "Linking to #{node}"
puts "Linking 'coffee' to #{bin}/coffee"
console.log "Installing CoffeeScript to #{lib}"
console.log "Linking to #{node}"
console.log "Linking 'coffee' to #{bin}/coffee"
exec([
"mkdir -p #{lib} #{bin}"
"cp -rf bin lib LICENSE README package.json src #{lib}"

View File

@ -4,5 +4,4 @@ var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
require(lib + '/helpers').extend(global, require(/^v0\.[012]/.test(process.version) ? 'sys' : 'util'));
require(lib + '/cake').run();

View File

@ -4,5 +4,4 @@ var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
require(lib + '/helpers').extend(global, require(/^v0\.[012]/.test(process.version) ? 'sys' : 'util'));
require(lib + '/command').run();

View File

@ -11,6 +11,6 @@ index = (list, target) ->
if val < target then low = mid + 1 else high = mid
return -1
puts 2 is index [10, 20, 30, 40, 50], 30
puts 4 is index [-97, 35, 67, 88, 1200], 1200
puts 0 is index [0, 45, 70], 0
console.log 2 is index [10, 20, 30, 40, 50], 30
console.log 4 is index [-97, 35, 67, 88, 1200], 1200
console.log 0 is index [0, 45, 70], 0

View File

@ -8,6 +8,6 @@ runtime = (N) ->
t = n - 1 + sum / n
t
puts runtime(3) is 2.6666666666666665
puts runtime(5) is 7.4
puts runtime(8) is 16.92142857142857
console.log runtime(3) is 2.6666666666666665
console.log runtime(5) is 7.4
console.log runtime(8) is 16.92142857142857

View File

@ -26,9 +26,9 @@ match_star = (c, regexp, text) ->
return false unless text and (text[0] is c or c is '.')
text = text.slice(1)
puts match("ex", "some text")
puts match("s..t", "spit")
puts match("^..t", "buttercup")
puts match("i..$", "cherries")
puts match("o*m", "vrooooommm!")
puts match("^hel*o$", "hellllllo")
console.log match("ex", "some text")
console.log match("s..t", "spit")
console.log match("^..t", "buttercup")
console.log match("i..$", "cherries")
console.log match("o*m", "vrooooommm!")
console.log match("^hel*o$", "hellllllo")

View File

@ -11,7 +11,7 @@ append = (location, data) ->
throw new Error("Location does not exist") unless path.exists()
File.open path, 'a', (file) ->
file.puts YAML.dump data
file.console.log YAML.dump data
data
@ -35,7 +35,7 @@ write = (location, data) ->
File.open path, 'w', (file) ->
return false if Digest.MD5.hexdigest(file.read()) is data.hash()
file.puts YAML.dump data
file.console.log YAML.dump data
true

View File

@ -19,7 +19,7 @@ binary_search = (items, value) ->
# Test the function.
puts 2 is binary_search [10, 20, 30, 40, 50], 30
puts 4 is binary_search [-97, 35, 67, 88, 1200], 1200
puts 0 is binary_search [0, 45, 70], 0
puts(-1 is binary_search [0, 45, 70], 10)
console.log 2 is binary_search [10, 20, 30, 40, 50], 30
console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
console.log 0 is binary_search [0, 45, 70], 0
console.log(-1 is binary_search [0, 45, 70], 10)

View File

@ -7,5 +7,5 @@ bubble_sort = (list) ->
# Test the function.
puts bubble_sort([3, 2, 1]).join(' ') is '1 2 3'
puts bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
console.log bubble_sort([3, 2, 1]).join(' ') is '1 2 3'
console.log bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'

View File

@ -93,16 +93,16 @@ class LinkedList
list = new LinkedList
list.add("Hi")
puts list.size() is 1
puts list.item(0) is "Hi"
puts list.item(1) is null
console.log list.size() is 1
console.log list.item(0) is "Hi"
console.log list.item(1) is null
list = new LinkedList
list.add("zero").add("one").add("two")
puts list.size() is 3
puts list.item(2) is "two"
puts list.remove(1) is "one"
puts list.item(0) is "zero"
puts list.item(1) is "two"
puts list.size() is 2
puts list.item(-10) is null
console.log list.size() is 3
console.log list.item(2) is "two"
console.log list.remove(1) is "one"
console.log list.item(0) is "zero"
console.log list.item(1) is "two"
console.log list.size() is 2
console.log list.item(-10) is null

View File

@ -31,6 +31,6 @@ is_valid_identifier = (identifier) ->
# Tests.
puts is_valid_identifier("49927398716") is true
puts is_valid_identifier("4408041234567893") is true
puts is_valid_identifier("4408041234567890") is false
console.log is_valid_identifier("49927398716") is true
console.log is_valid_identifier("4408041234567893") is true
console.log is_valid_identifier("4408041234567890") is false

View File

@ -15,5 +15,5 @@ merge_sort = (list) ->
# Test the function.
puts merge_sort([3, 2, 1]).join(' ') is '1 2 3'
puts merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
console.log merge_sort([3, 2, 1]).join(' ') is '1 2 3'
console.log merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'

View File

@ -19,5 +19,5 @@ selection_sort = (list) ->
# Test the function.
puts selection_sort([3, 2, 1]).join(' ') is '1 2 3'
puts selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
console.log selection_sort([3, 2, 1]).join(' ') is '1 2 3'
console.log selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'

View File

@ -76,29 +76,29 @@ WishScanner =
# p_up = rand( charisma )
# if p_up % 9 == 7
# @life += p_up / 4
# puts "[#{ self.class } magick powers up #{ p_up }!]"
# console.log "[#{ self.class } magick powers up #{ p_up }!]"
# end
# @life -= damage
# puts "[#{ self.class } has died.]" if @life <= 0
# console.log "[#{ self.class } has died.]" if @life <= 0
# end
#
# # This method takes one turn in a fight.
# def fight( enemy, weapon )
# if life <= 0
# puts "[#{ self.class } is too dead to fight!]"
# console.log "[#{ self.class } is too dead to fight!]"
# return
# end
#
# # Attack the opponent
# your_hit = rand( strength + weapon )
# puts "[You hit with #{ your_hit } points of damage!]"
# console.log "[You hit with #{ your_hit } points of damage!]"
# enemy.hit( your_hit )
#
# # Retaliation
# p enemy
# if enemy.life > 0
# enemy_hit = rand( enemy.strength + enemy.weapon )
# puts "[Your enemy hit with #{ enemy_hit } points of damage!]"
# console.log "[Your enemy hit with #{ enemy_hit } points of damage!]"
# self.hit( enemy_hit )
# end
# end
@ -112,24 +112,24 @@ Creature =
p_up = Math.rand this.charisma
if p_up % 9 is 7
this.life += p_up / 4
puts "[" + this.name + " magick powers up " + p_up + "!]"
console.log "[" + this.name + " magick powers up " + p_up + "!]"
this.life -= damage
if this.life <= 0 then puts "[" + this.name + " has died.]"
if this.life <= 0 then console.log "[" + this.name + " has died.]"
# This method takes one turn in a fight.
fight: (enemy, weapon) ->
if this.life <= 0 then return puts "[" + this.name + "is too dead to fight!]"
if this.life <= 0 then return console.log "[" + this.name + "is too dead to fight!]"
# Attack the opponent.
your_hit = Math.rand this.strength + weapon
puts "[You hit with " + your_hit + "points of damage!]"
console.log "[You hit with " + your_hit + "points of damage!]"
enemy.hit your_hit
# Retaliation.
puts enemy
console.log enemy
if enemy.life > 0
enemy_hit = Math.rand enemy.strength + enemy.weapon
puts "[Your enemy hit with " + enemy_hit + "points of damage!]"
console.log "[Your enemy hit with " + enemy_hit + "points of damage!]"
this.hit enemy_hit

View File

@ -1,6 +1,5 @@
# Contributed by Jason Huggins
sys = require 'sys'
http = require 'http'
server = http.createServer (req, res) ->
@ -10,4 +9,4 @@ server = http.createServer (req, res) ->
server.listen 3000
sys.puts "Server running at http://localhost:3000/"
console.log "Server running at http://localhost:3000/"

View File

@ -57,18 +57,18 @@
};
printTasks = function() {
var _ref, desc, name, spaces, task;
puts('');
console.log('');
for (name in _ref = tasks) {
task = _ref[name];
spaces = 20 - name.length;
spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
desc = task.description ? "# " + task.description : '';
puts("cake " + name + spaces + " " + desc);
console.log("cake " + name + spaces + " " + desc);
}
return switches.length ? puts(oparse.help()) : undefined;
return switches.length ? console.log(oparse.help()) : undefined;
};
missingTask = function(task) {
puts("No such task: \"" + task + "\"");
console.log("No such task: \"" + task + "\"");
return process.exit(1);
};
}).call(this);

View File

@ -104,13 +104,13 @@
if (o.tokens) {
return printTokens(CoffeeScript.tokens(t.input));
} else if (o.nodes) {
return puts(CoffeeScript.nodes(t.input).toString().trim());
return console.log(CoffeeScript.nodes(t.input).toString().trim());
} else if (o.run) {
return CoffeeScript.run(t.input, t.options);
} else {
t.output = CoffeeScript.compile(t.input, t.options);
CoffeeScript.emit('success', task);
return o.print ? print(t.output) : o.compile ? writeJs(t.file, t.output, base) : o.lint ? lint(t.output) : undefined;
return o.print ? console.log(t.output.trim()) : o.compile ? writeJs(t.file, t.output, base) : o.lint ? lint(t.output) : undefined;
}
} catch (err) {
CoffeeScript.emit('failure', err, task);
@ -118,7 +118,7 @@
return;
}
if (o.watch) {
return puts(err.message);
return console.log(err.message);
}
error(err.stack);
return process.exit(1);
@ -163,7 +163,7 @@
js = ' ';
}
return fs.writeFile(jsPath, js, function(err) {
return err ? puts(err.message) : opts.compile && opts.watch ? puts("Compiled " + source) : undefined;
return err ? console.log(err.message) : opts.compile && opts.watch ? console.log("Compiled " + source) : undefined;
});
};
return path.exists(dir, function(exists) {
@ -173,7 +173,7 @@
lint = function(js) {
var conf, jsl, printIt;
printIt = function(buffer) {
return puts(buffer.toString().trim());
return console.log(buffer.toString().trim());
};
conf = __dirname + '/../extras/jsl.conf';
jsl = spawn('jsl', ['-nologo', '-stdin', '-conf', conf]);
@ -193,7 +193,7 @@
}
return _result;
})();
return puts(strings.join(' '));
return console.log(strings.join(' '));
};
parseOptions = function() {
var o;
@ -211,11 +211,11 @@
};
};
usage = function() {
puts(optionParser.help());
console.log(optionParser.help());
return process.exit(0);
};
version = function() {
puts("CoffeeScript version " + CoffeeScript.VERSION);
console.log("CoffeeScript version " + CoffeeScript.VERSION);
return process.exit(0);
};
}).call(this);

View File

@ -18,10 +18,10 @@
fileName: 'repl'
});
if (val !== undefined) {
puts(inspect(val));
console.log(inspect(val));
}
} catch (err) {
puts(err.stack || err.toString());
console.log(err.stack || err.toString());
}
return repl.prompt();
};

View File

@ -55,15 +55,15 @@ exports.run = ->
# Display the list of Cake tasks in a format similar to `rake -T`
printTasks = ->
puts ''
console.log ''
for all name, task of tasks
spaces = 20 - name.length
spaces = if spaces > 0 then Array(spaces + 1).join(' ') else ''
desc = if task.description then "# #{task.description}" else ''
puts "cake #{name}#{spaces} #{desc}"
puts oparse.help() if switches.length
console.log "cake #{name}#{spaces} #{desc}"
console.log oparse.help() if switches.length
# Print an error and exit when attempting to all an undefined task.
missingTask = (task) ->
puts "No such task: \"#{task}\""
console.log "No such task: \"#{task}\""
process.exit 1

View File

@ -100,12 +100,12 @@ compileScript = (file, input, base) ->
t = task = {file, input, options}
CoffeeScript.emit 'compile', task
if o.tokens then printTokens CoffeeScript.tokens t.input
else if o.nodes then puts CoffeeScript.nodes(t.input).toString().trim()
else if o.nodes then console.log CoffeeScript.nodes(t.input).toString().trim()
else if o.run then CoffeeScript.run t.input, t.options
else
t.output = CoffeeScript.compile t.input, t.options
CoffeeScript.emit 'success', task
if o.print then print t.output
if o.print then console.log t.output.trim()
else if o.compile then writeJs t.file, t.output, base
else if o.lint then lint t.output
catch err
@ -113,7 +113,7 @@ compileScript = (file, input, base) ->
# node will print a stack trace and exit the program.
CoffeeScript.emit 'failure', err, task
return if CoffeeScript.listeners('failure').length
return puts err.message if o.watch
return console.log err.message if o.watch
error err.stack
process.exit 1
@ -149,15 +149,15 @@ writeJs = (source, js, base) ->
compile = ->
js = ' ' if js.length <= 0
fs.writeFile jsPath, js, (err) ->
if err then puts err.message
else if opts.compile and opts.watch then puts "Compiled #{source}"
if err then console.log err.message
else if opts.compile and opts.watch then console.log "Compiled #{source}"
path.exists dir, (exists) ->
if exists then compile() else exec "mkdir -p #{dir}", compile
# Pipe compiled JS through JSLint (requires a working `jsl` command), printing
# any errors or warnings that arise.
lint = (js) ->
printIt = (buffer) -> puts buffer.toString().trim()
printIt = (buffer) -> console.log buffer.toString().trim()
conf = __dirname + '/../extras/jsl.conf'
jsl = spawn 'jsl', ['-nologo', '-stdin', '-conf', conf]
jsl.stdout.on 'data', printIt
@ -170,7 +170,7 @@ printTokens = (tokens) ->
strings = for token in tokens
[tag, value] = [token[0], token[1].toString().replace(/\n/, '\\n')]
"[#{tag} #{value}]"
puts strings.join(' ')
console.log strings.join(' ')
# Use the [OptionParser module](optparse.html) to extract all options from
# `process.argv` that are specified in `SWITCHES`.
@ -187,10 +187,10 @@ compileOptions = (fileName) -> {fileName, bare: opts.bare}
# Print the `--help` usage message and exit.
usage = ->
puts optionParser.help()
console.log optionParser.help()
process.exit 0
# Print the `--version` message and exit.
version = ->
puts "CoffeeScript version #{CoffeeScript.VERSION}"
console.log "CoffeeScript version #{CoffeeScript.VERSION}"
process.exit 0

View File

@ -2,7 +2,7 @@
# and evaluates it. Good for simple tests, or poking around the **Node.js** API.
# Using it looks like this:
#
# coffee> puts "#{num} bottles of beer" for num in [99..1]
# coffee> console.log "#{num} bottles of beer" for num in [99..1]
# Require the **coffee-script** module to get access to the compiler.
CoffeeScript = require './coffee-script'
@ -21,9 +21,9 @@ helpers.extend global, quit: -> process.exit(0)
run = (buffer) ->
try
val = CoffeeScript.eval buffer.toString(), bare: on, globals: on, fileName: 'repl'
puts inspect val if val isnt undefined
console.log inspect val if val isnt undefined
catch err
puts err.stack or err.toString()
console.log err.stack or err.toString()
repl.prompt()
# Create the REPL by listening to **stdin**.

View File

@ -10,7 +10,7 @@
class exports.Rewriter
# Helpful snippet for debugging:
# puts (t[0] + '/' + t[1] for t in @tokens).join ' '
# console.log (t[0] + '/' + t[1] for t in @tokens).join ' '
# Rewrite the token stream in multiple passes, one logical filter at
# a time. This could certainly be changed into a single pass through the

View File

@ -4,7 +4,7 @@ callWithLambda = (l) -> null
for i in array
result = callWithLambda(->)
if i == 2
puts "i = 2"
console.log "i = 2"
else
break