Permalink
Browse files

Make opal-parser buildable through RakeTask

  • Loading branch information...
1 parent 9fec9fb commit 7437b66cce052d90c3204eb7f6f34ee5fb034c8d @adambeynon committed Aug 28, 2012
Showing with 21 additions and 12 deletions.
  1. +1 −1 README.md
  2. +1 −10 Rakefile
  3. +11 −0 lib/opal.rb
  4. +8 −1 lib/opal/rake_task.rb
View
@@ -17,7 +17,7 @@ See the website, [http://opalrb.org](http://opalrb.org).
Build the runtime, tests and dependencies:
```
-rake opal parser
+rake opal
```
Run tests using phantom.js runner:
View
@@ -9,16 +9,7 @@ require 'opal/rake_task'
Opal::RakeTask.new do |t|
t.dependencies = %w(opal-spec)
t.files = [] # we handle this by Opal.runtime instead
-end
-
-desc "Build opal-parser ready for browser"
-task :parser do
- puts " * build/opal-parser.js"
- File.open('build/opal-parser.js', 'w+') do |o|
- o.puts Opal::Builder.new(:files => %w(racc.rb strscan.rb), :dir => 'core').build
- o.puts Opal.build_gem('opal')
- o.puts File.read('core/browser.js')
- end
+ t.parser = true # we want to also build opal-parser.js
end
desc "Build minified versions of core js builds"
View
@@ -58,6 +58,17 @@ def self.runtime
].join("\n")
end
+ # Returns parser prebuilt for js-environments.
+ #
+ # @return [String]
+ def self.parser_code
+ [
+ Builder.new(:files => %w(racc.rb strscan.rb), :dir => self.core_dir).build,
+ self.build_gem('opal'),
+ File.read(File.join self.core_dir, 'browser.js')
+ ].join("\n")
+ end
+
# Build gem with given name to a string.
#
# Opal.build_gem 'opal-spec'
@@ -6,7 +6,7 @@ module Opal
class RakeTask
include Rake::DSL if defined? Rake::DSL
- attr_accessor :name, :build_dir, :specs_dir, :files, :dependencies
+ attr_accessor :name, :build_dir, :specs_dir, :files, :dependencies, :parser
def initialize(namespace = nil)
@project_dir = Dir.getwd
@@ -56,6 +56,13 @@ def define_tasks
puts " * #{out}"
write_code Opal.runtime, out
+ # build opal-parser?
+ if @parser
+ out = File.join @build_dir, 'opal-parser.js'
+ puts " * #{out}"
+ write_code Opal.parser_code, out
+ end
+
@dependencies.each { |dep| build_gem dep }
end

0 comments on commit 7437b66

Please sign in to comment.