Skip to content

Commit

Permalink
Add rake task to automatically pre-build rspec for production
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Oct 17, 2013
1 parent 1c56529 commit 78dffb9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
Gemfile.lock
opal/opal-rspec/rspec.js
30 changes: 30 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
require 'bundler'
Bundler.require

desc "Build opal-rspec/rspec.js"
task :build do
Opal::Processor.dynamic_require_severity = :warning
Opal.append_path 'app'

Opal.use_gem 'rspec'
Opal.use_gem 'rspec-expectations'

code = Opal.process('rspec-builder')
min = uglify code

puts "\nDev: #{code.size}, min: #{min.size}"

File.open('opal/opal-rspec/rspec.js', 'w+') do |out|
out << min
end
end

def uglify(str)
IO.popen('uglifyjs', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
rescue Errno::ENOENT
$stderr.puts '"uglifyjs" command not found (install with: "npm install -g uglify-js")'
nil
end

6 changes: 6 additions & 0 deletions app/rspec-builder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rspec/core'
require 'rspec/mocks'
require 'rspec-expectations'

# For now, we don't support mocking. This placeholder in rspec-core allows that.
require 'rspec/core/mocking/with_absolutely_nothing'
10 changes: 4 additions & 6 deletions opal/opal-rspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
require 'dir'
require 'thread'

require 'rspec/core'
require 'rspec/mocks'
require 'rspec-expectations'

# For now, we don't support mocking. This placeholder in rspec-core allows that.
require 'rspec/core/mocking/with_absolutely_nothing'
# production
# require 'opal-rspec/rspec'
# development
require 'rspec-builder'

require 'opal-rspec/fixes'
require 'opal-rspec/text_formatter'
Expand Down

0 comments on commit 78dffb9

Please sign in to comment.