Skip to content

Commit

Permalink
Add more options to compiler build command
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Beynon committed Jun 12, 2011
1 parent 102a979 commit b1f5a1f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions opal_lib/opal/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ def build(options = {})
options[:main] = files.first
elsif main
raise "Opal::Builder - Main file does not exist!" unless File.exists? main
files << main unless files.inclide? main
files << main unless files.include? main
elsif main == false
options[:main] = false
else
options[:main] = files.first
end

main = options[:main]

unless options[:out]
options[:out] = File.basename(main, '.rb') + '.js'
options[:out] = main.sub /\.rb$/, '.js'
end

FileUtils.mkdir_p File.dirname(options[:out])
Expand Down Expand Up @@ -143,7 +145,7 @@ def rebuild(options)
end

if options[:main]
main = File.basename(options[:main]).sub(/\.rb/, '')
main = options[:main].sub(/\.rb$/, '')
out.write "opal.require('#{main}');\n"
end

Expand Down
12 changes: 6 additions & 6 deletions opal_lib/opal/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def spec(*specs)
file that exists, it will be read, otherwise the
content will be run as a string.
]
# TODO make it compile as a string if file not exist
def compile(str)
raise "File does not exist: #{str}" unless File.exist? str
str = "\n\n#{File.read str}"
code = Opal::RubyParser.new(str).parse!.generate_top
puts "opal.run(function($runtime, self, __FILE__) { #{code} });"
method_options :out => :string, :watch => :boolean, :main => :string
def compile(*path)
opts = options
builder = Builder.new
builder.build :files => path,
:out => opts["out"], :watch => opts["watch"], :main => opts["main"]
end

desc "exec [FILENAME]", "Run the given ruby file"
Expand Down

0 comments on commit b1f5a1f

Please sign in to comment.