forked from handlebars-lang/handlebars.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
106 lines (81 loc) · 2.71 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
require "rubygems"
require "bundler/setup"
file "lib/handlebars/compiler/parser.js" => ["src/handlebars.yy","src/handlebars.l"] do
if ENV['PATH'].split(':').any? {|folder| File.exists?(folder+'/jison')}
system "jison src/handlebars.yy src/handlebars.l"
File.open("lib/handlebars/compiler/parser.js", "w") do |file|
file.puts File.read("handlebars.js") + ";"
end
sh "rm handlebars.js"
else
puts "Jison is not installed. Try running `npm install jison`."
end
end
task :compile => "lib/handlebars/compiler/parser.js"
desc "run the spec suite"
task :spec => [:release] do
system "rspec -cfs spec"
end
task :default => [:compile, :spec]
def remove_exports(string)
match = string.match(%r{^// BEGIN\(BROWSER\)\n(.*)\n^// END\(BROWSER\)}m)
match ? match[1] : string
end
minimal_deps = %w(base compiler/parser compiler/base compiler/ast utils compiler/compiler vm).map do |file|
"lib/handlebars/#{file}.js"
end
vm_deps = %w(base utils vm).map do |file|
"lib/handlebars/#{file}.js"
end
directory "dist"
minimal_deps.unshift "dist"
def build_for_task(task)
FileUtils.rm_rf("dist/*") if File.directory?("dist")
FileUtils.mkdir_p("dist")
contents = []
task.prerequisites.each do |filename|
next if filename == "dist"
contents << "// #{filename}\n" + remove_exports(File.read(filename)) + ";"
end
File.open(task.name, "w") do |file|
file.puts contents.join("\n")
end
end
file "dist/handlebars.js" => minimal_deps do |task|
build_for_task(task)
end
file "dist/handlebars.vm.js" => vm_deps do |task|
build_for_task(task)
end
task :build => [:compile, "dist/handlebars.js"]
task :vm => [:compile, "dist/handlebars.vm.js"]
desc "build the build and vm version of handlebars"
task :release => [:build, :vm]
directory "vendor"
desc "benchmark against dust.js and mustache.js"
task :bench => "vendor" do
require "open-uri"
File.open("vendor/mustache.js", "w") do |file|
file.puts open("https://github.com/janl/mustache.js/raw/master/mustache.js").read
file.puts "module.exports = Mustache;"
end
File.open("vendor/benchmark.js", "w") do |file|
file.puts open("https://github.com/mathiasbynens/benchmark.js/raw/master/benchmark.js").read
end
if File.directory?("vendor/dustjs")
system "cd vendor/dustjs && git pull"
else
system "git clone git://github.com/akdubya/dustjs.git vendor/dustjs"
end
if File.directory?("vendor/coffee")
system "cd vendor/coffee && git pull"
else
system "git clone git://github.com/jashkenas/coffee-script.git vendor/coffee"
end
if File.directory?("vendor/eco")
system "cd vendor/eco && git pull"
else
system "git clone git://github.com/sstephenson/eco.git vendor/eco"
end
system "node bench/handlebars.js"
end