forked from opal/opal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
112 lines (90 loc) · 2.42 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
$:.unshift File.expand_path(File.join('..', 'opal_lib'), __FILE__)
require 'opal'
VERSION = File.read('VERSION').strip
opal_copyright = <<-EOS
/*!
* opal v#{VERSION}
* http://opalscript.org
*
* Copyright 2011, Adam Beynon
* Released under the MIT license
*/
EOS
def uglify(str)
IO.popen('uglifyjs -nc', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
end
def gzip(str)
IO.popen('gzip -f', 'r+') do |i|
i.puts str
i.close_write
return i.read
end
end
task :build => ["extras/opal.js", "extras/opal-parser.js"]
task :default => :build
file "extras" do
mkdir_p "extras"
end
task :clean do
rm_rf Dir['extras/*.js']
end
file "extras/opal.js" => "extras" do
File.open("extras/opal.js", "w+") do |file|
file.write opal_copyright
file.write uglify(Opal::Builder.new.build_core)
end
end
file "extras/opal.test.js" => "extras" do
File.open("extras/opal.test.js", "w+") do |file|
builder = Opal::Builder.new
Dir["spec/**/*.rb"].each do |spec|
file.write builder.wrap_source(spec, spec)
end
# opal.require('ospec/autorun')
end
end
file "extras/opal-parser.js" => "extras" do
File.open("extras/opal-parser.js", "w+") do |file|
file.write opal_copyright
file.write uglify(Opal::Builder.new.build_parser)
end
end
file "extras/ospec.js" => "extras" do
File.open("extras/ospec.js", "w+") do |file|
file.write opal_copyright
file.write Opal::Builder.new.build_stdlib 'ospec.rb', 'ospec/**/*.rb'
end
end
desc "Check file sizes for core builds"
task :file_sizes => :build do
m = File.read("extras/opal.js")
g = gzip(m)
puts "minified: #{m.size}, gzipped: #{g.size}"
end
desc "Rebuild ruby_parser.rb for opal build tools"
task :parser do
%x{racc -l opal_lib/opal/ruby/ruby_parser.y -o opal_lib/opal/ruby/ruby_parser.rb}
end
namespace :starter_kit do
starter_kit_dir = "extras/starter-kit"
js_sources = ["opal-#{VERSION}.js", "opal-#{VERSION}.min.js", "opal-parser-#{VERSION}.js", "opal-parser-#{VERSION}.min.js"]
js_target = "#{starter_kit_dir}/js"
file starter_kit_dir => "extras" do
sh "git clone [email protected]:opal/starter-kit.git #{starter_kit_dir}"
end
task :pull => starter_kit_dir do
Dir.chdir(starter_kit_dir) { sh "git pull origin master" }
end
task :js_sources do
js_sources.each do |src|
sh "cp extras/#{src} #{js_target}/#{src}"
end
end
task :build => [:min, starter_kit_dir]
end
namespace :web do
end