-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
62 lines (50 loc) · 1.79 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
require 'rake'
require 'rake/clean'
task :default => :spec
desc "Run all specs"
task :spec do
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
#t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
t.pattern = 'spec/*_spec.rb'
end
end
def version
File.read("mustache.js").match('version: "([^\"]+)",$')[1]
end
# Creates a rule that uses the .tmpl.{pre,post} stuff to make a final,
# wrapped, output file. There is some extra complexity because Dojo and YUI3
# use different template files and final locations.
def templated_build(name, opts={})
short = name.downcase
source = File.join("wrappers", short)
dependencies = ["mustache.js"] + Dir.glob("#{source}/*.tpl.*")
target_js = opts[:location] ? "mustache.js" : "#{short}.mustache.js"
CLEAN.include(opts[:location] ? opts[:location] : target_js)
desc "Package for #{name}"
task short.to_sym => dependencies do
puts "Packaging for #{name}"
mkdir_p opts[:location] if opts[:location]
sh "cat #{source}/#{target_js}.tpl.pre mustache.js \
#{source}/#{target_js}.tpl.post > #{opts[:location] || '.'}/#{target_js}"
# extra
if opts[:extra]
sh "sed -e 's/{{version}}/#{version}/' #{source}/#{opts[:extra]} \
> #{opts[:location]}/#{opts[:extra]}"
end
puts "Done, see #{opts[:location] || '.'}/#{target_js}"
end
end
templated_build "CommonJS", :location => "lib", :extra => "package.json"
templated_build "jQuery"
templated_build "Dojo", :location => "dojox/string"
templated_build "YUI3", :location => "yui3/mustache"
templated_build "RequireJS"
templated_build "qooxdoo"
task :minify do
# npm install uglify-js
mmjs = "mustache.min.js"
`echo "/*! Version: 0.4.2 */" > #{mmjs}`
`uglifyjs mustache.js >> #{mmjs}`
puts "Created #{mmjs}"
end