Skip to content

Commit

Permalink
Move the Util module out of Opal::Builder
Browse files Browse the repository at this point in the history
It's used only in the rake task and now it's no longer
added to opal-parser. related: #456
  • Loading branch information
elia committed Dec 15, 2013
1 parent 9f93f49 commit 22b010e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
6 changes: 4 additions & 2 deletions Rakefile
Expand Up @@ -17,6 +17,8 @@ task :default => [:rspec, :mspec]

desc 'Build opal.js and opal-parser.js to build/'
task :dist do
require 'opal/util'

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

Expand All @@ -31,8 +33,8 @@ task :dist do
$stdout.flush

src = env[lib].to_s
min = Opal::Builder::Util.uglify src
gzp = Opal::Builder::Util.gzip min
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
Expand Down
6 changes: 4 additions & 2 deletions lib/mspec/opal/rake_task.rb
Expand Up @@ -43,10 +43,11 @@ def initialize(name, &task_block)

desc 'Build specs to build/specs.js and build/specs.min.js'
task :build do
require 'opal/util'
path = './build/specs.js'
min_path = './build/specs.min.js'
Environment.new.build_specs(path)
min = ::Opal::Builder::Util.uglify File.read(path)
min = ::Opal::Util.uglify File.read(path)
File.open(min_path, 'w') { |f| f << min_path }
end
end
Expand Down Expand Up @@ -138,7 +139,8 @@ def specs
end

def build_min file = "#{basedir}/build/specs.min.js"
build ::Opal::Builder::Util.uglify(specs.to_s), file
require 'opal/util'
build ::Opal::Util.uglify(specs.to_s), file
end

def files
Expand Down
28 changes: 0 additions & 28 deletions lib/opal/builder.rb
Expand Up @@ -94,33 +94,5 @@ def build_js(path)
def build_erb(path)
::ERB.new(File.read(path)).result binding
end

module Util
extend self

# Used for uglifying source to minify
def uglify(str)
IO.popen('uglifyjs 2> /dev/null', '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 2> /dev/null', '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
end
end
end
29 changes: 29 additions & 0 deletions lib/opal/util.rb
@@ -0,0 +1,29 @@
module Opal
module Util
extend self

# Used for uglifying source to minify
def uglify(str)
IO.popen('uglifyjs 2> /dev/null', '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 2> /dev/null', '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
end
end

0 comments on commit 22b010e

Please sign in to comment.