Rakefile in opal-0.3.43 vs Rakefile in opal-0.3.44
- old
+ new
@@ -45,73 +45,83 @@
#build path for spec files\dirs.
#Example:
#spec:core => spec/core/
#spec:core:array:allocae => spec/core/array/allocate_spec.rb
- def path(dirs)
+ def path(dirs)
path = "#{Dir.pwd}"
dirs.each do |dir|
- base = path + "/#{dir}"
+ base = path + "/#{dir}"
if Dir.exists?(base)
path = base
else
path = Dir.glob("#{base}_spec.rb")
- end
+ end
end
path = [path].flatten
raise "File or Dir with task #{t.name} not found." if path.empty?
path
end
-
+
RunSpec.new(path(t.name.split(":")))
end
end
desc "Build opal.js and opal-parser.js to build/"
task :dist do
Opal::Processor.arity_check_enabled = false
- env = Sprockets::Environment.new
- Opal.paths.each { |p| env.append_path p }
+ env = Opal::Environment.new
Dir.mkdir 'build' unless File.directory? 'build'
- File.open('build/opal.js', 'w+') { |f| f << env['opal'].to_s }
- File.open('build/opal-parser.js', 'w+') { |f| f << env['opal-parser'].to_s }
-end
+ %w[opal opal-parser].each do |lib|
+ puts "* building #{lib}..."
-desc "Check file sizes for opal.js runtime"
-task :sizes do
- Opal::Processor.arity_check_enabled = false
+ src = env[lib].to_s
+ min = uglify src
+ gzp = gzip min
- env = Sprockets::Environment.new
- Opal.paths.each { |p| env.append_path p }
+ 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
- src = env['opal'].to_s
- min = uglify src
- gzp = gzip min
+ print "done. (development: #{src.size}B"
+ print ", minified: #{min.size}B" if min
+ print ", gzipped: #{gzp.size}Bx" if gzp
+ puts ")."
+ puts
+ end
+end
- puts "development: #{src.size}, minified: #{min.size}, gzipped: #{gzp.size}"
+desc "Check file sizes for opal.js runtime"
+task :sizes => :dist do
end
desc "Rebuild grammar.rb for opal parser"
task :racc do
%x(racc -l lib/opal/grammar.y -o lib/opal/grammar.rb)
end
# Used for uglifying source to minify
def uglify(str)
- IO.popen('uglifyjs -nc', 'r+') do |i|
+ IO.popen('uglifyjs --no-mangle --compress warnings=false', '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
# Gzip code to check file size
def gzip(str)
IO.popen('gzip -f', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
+rescue Errno::ENOENT
+ $stderr.puts '"gzip" command not found, it is required to produce the .gz version'
+ nil
end