Read from stdin if source is "-"

This commit is contained in:
tlrobinson 2009-12-24 14:40:39 -08:00
parent 39ceca477d
commit 08248180f9
1 changed files with 7 additions and 3 deletions

View File

@ -41,11 +41,15 @@ Usage:
# Compiles (or partially compiles) the source CoffeeScript file, returning # Compiles (or partially compiles) the source CoffeeScript file, returning
# the desired JS, tokens, or lint results. # the desired JS, tokens, or lint results.
def compile_javascript(source) def compile_javascript(source)
script = File.read(source) if source == "-"
script = STDIN.read
else
script = File.read(source)
end
return tokens(script) if @options[:tokens] return tokens(script) if @options[:tokens]
js = compile(script, source) js = compile(script, source)
return unless js return unless js
return puts(js) if @options[:print] return puts(js) if @options[:print] or source == "-"
return lint(js) if @options[:lint] return lint(js) if @options[:lint]
File.open(path_for(source), 'w+') {|f| f.write(js) } File.open(path_for(source), 'w+') {|f| f.write(js) }
end end
@ -73,7 +77,7 @@ Usage:
# Ensure that all of the source files exist. # Ensure that all of the source files exist.
def check_sources def check_sources
usage if @sources.empty? usage if @sources.empty?
missing = @sources.detect {|s| !File.exists?(s) } missing = @sources.detect {|s| !File.exists?(s) and s != "-" }
if missing if missing
STDERR.puts("File not found: '#{missing}'") STDERR.puts("File not found: '#{missing}'")
exit(1) exit(1)