Fix up the compilation process
This commit is contained in:
@@ -6,10 +6,60 @@ file "lib/handlebars/parser.js" => "src/handlebars.yy" do
|
||||
sh "mv handlebars.js lib/handlebars/parser.js"
|
||||
end
|
||||
|
||||
task :build => "lib/handlebars/parser.js"
|
||||
task :compile => "lib/handlebars/parser.js"
|
||||
|
||||
task :test => :build do
|
||||
desc "run the spec suite"
|
||||
task :spec => [:release] do
|
||||
system "rspec -cfs spec"
|
||||
end
|
||||
|
||||
task :default => [:build, :test]
|
||||
task :default => [:compile, :test]
|
||||
|
||||
def remove_exports(string)
|
||||
match = string.match(%r{^// BEGIN\(BROWSER\)\n(.*)\n^// END\(BROWSER\)}m)
|
||||
match ? match[1] : string
|
||||
end
|
||||
|
||||
minimal_deps = %w(ast jison_ext handlebars_lexer parser runtime utils).map do |file|
|
||||
"lib/handlebars/#{file}.js"
|
||||
end
|
||||
|
||||
debug_deps = %w(ast jison_ext handlebars_lexer printer parser runtime utils).map do |file|
|
||||
"lib/handlebars/#{file}.js"
|
||||
end
|
||||
|
||||
minimal_deps << "lib/handlebars.js"
|
||||
debug_deps << "lib/handlebars.js" << "lib/handlebars/debug.js"
|
||||
|
||||
minimal_deps.unshift "dist"
|
||||
debug_deps.unshift "dist"
|
||||
|
||||
def build_for_task(task)
|
||||
FileUtils.rm_rf("dist")
|
||||
FileUtils.mkdir_p("dist")
|
||||
|
||||
contents = ["var Handlebars = {};"]
|
||||
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.debug.js" => debug_deps do |task|
|
||||
build_for_task(task)
|
||||
end
|
||||
|
||||
task :build => [:compile, "dist/handlebars.js"]
|
||||
task :debug => [:compile, "dist/handlebars.debug.js"]
|
||||
|
||||
desc "build the build and debug versions of handlebars"
|
||||
task :release => [:build, :debug]
|
||||
|
||||
Reference in New Issue
Block a user