Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/opal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f2324db6bf9b
Choose a base ref
...
head repository: opal/opal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b553c71bf1f6
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 23, 2014

  1. Copy the full SHA
    4338c92 View commit details
  2. Cleanup some code in util.rb

    [skip ci]
    elia committed Mar 23, 2014
    Copy the full SHA
    b553c71 View commit details
Showing with 24 additions and 19 deletions.
  1. +18 −9 Rakefile
  2. +6 −10 lib/opal/util.rb
27 changes: 18 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -15,30 +15,39 @@ MSpec::Opal::RakeTask.new(:mspec)
task :default => [:rspec, :mspec]


desc 'Build opal.js and opal-parser.js to build/'
desc <<-DESC
Build *corelib* and *stdlib* to "build/"
You can restrict the file list with the FILES env var (comma separated)
and the destination dir with the DIR env var.
Example: rake dist DIR=/tmp/foo FILES='opal.rb,base64.rb'
DESC
task :dist do
require 'opal/util'

Opal::Processor.arity_check_enabled = false
Opal::Processor.const_missing_enabled = false

env = Opal::Environment.new

Dir.mkdir 'build' unless File.directory? 'build'
libs = Dir['{opal,stdlib}/*.rb'].map { |lib| File.basename(lib, '.rb') }
width = libs.map(&:size).max
build_dir = ENV['DIR'] || 'build'
files = ENV['FILES'] ? ENV['FILES'].split(',') :
Dir['{opal,stdlib}/*.rb'].map { |lib| File.basename(lib, '.rb') }

Dir.mkdir build_dir unless File.directory? build_dir
width = files.map(&:size).max

libs.each do |lib|
files.each do |lib|
print "* building #{lib}...".ljust(width+'* building ... '.size)
$stdout.flush

src = env[lib].to_s
min = Opal::Util.uglify src
gzp = Opal::Util.gzip min

File.open("build/#{lib}.js", 'w+') { |f| f << src }
File.open("build/#{lib}.min.js", 'w+') { |f| f << min } if min
File.open("build/#{lib}.min.js.gz", 'w+') { |f| f << gzp } if gzp
File.open("#{build_dir}/#{lib}.js", 'w+') { |f| f << src }
File.open("#{build_dir}/#{lib}.min.js", 'w+') { |f| f << min } if min
File.open("#{build_dir}/#{lib}.min.js.gz", 'w+') { |f| f << gzp } if gzp

print "done. ("
print "development: #{('%.2f' % (src.size/1000.0)).rjust(6)}KB"
16 changes: 6 additions & 10 deletions lib/opal/util.rb
Original file line number Diff line number Diff line change
@@ -44,23 +44,19 @@ def hide_stderr
# Code from http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
ENV['PATH'].split(File::PATH_SEPARATOR).find do |path|
exts.find { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable? exe
exe if File.executable? exe
}
end
nil
end

INSTALLED = {}
def command_installed?(cmd, install_comment)
cmd = cmd.to_s
INSTALLED.fetch(cmd) do
unless INSTALLED[cmd] = which(cmd) != nil
$stderr.puts %Q("#{cmd}" command not found#{install_comment})
end
end
command_installed = INSTALLED[cmd.to_s] ||= which(cmd)
$stderr.puts %Q("#{cmd}" command not found#{install_comment}) unless command_installed
command_installed
end
end