forked from emberjs-addons/ember-touch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
176 lines (133 loc) · 4.97 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
require "bundler/setup"
require "sproutcore"
require "erb"
require "uglifier"
LICENSE = File.read("generators/license.js")
## Some SproutCore modules expect an exports object to exist. Until bpm exists,
## just mock this out for now.
module SproutCore
module Compiler
class Entry
def body
"\n(function(exports) {\n#{@raw_body}\n})({});\n"
end
end
end
end
## HELPERS ##
def strip_require(file)
result = File.read(file)
result.gsub!(%r{^\s*require\(['"]([^'"])*['"]\);?\s*$}, "")
result
end
def strip_sc_assert(file)
result = File.read(file)
result.gsub!(%r{^(\s)+sc_assert\((.*)\).*$}, "")
result
end
def uglify(file)
uglified = Uglifier.compile(File.read(file))
"#{LICENSE}\n#{uglified}"
end
SproutCore::Compiler.intermediate = "tmp/intermediate"
SproutCore::Compiler.output = "tmp/static"
def compile_package_task(package)
js_tasks = SproutCore::Compiler::Preprocessors::JavaScriptTask.with_input "packages/#{package}/lib/**/*.js", "."
SproutCore::Compiler::CombineTask.with_tasks js_tasks, "#{SproutCore::Compiler.intermediate}/#{package}"
end
namespace :sproutcore do
task :touch => compile_package_task("sproutcore-touch")
task :TransformJS => compile_package_task("TransformJS")
end
task :build => ["sproutcore:touch","sproutcore:TransformJS"]
file "dist/sproutcore-touch.js" => :build do
puts "Generating sproutcore-touch.js"
mkdir_p "dist"
File.open("dist/sproutcore-touch.js", "w") do |file|
file.puts strip_require("tmp/static/TransformJS.js")
file.puts strip_require("tmp/static/sproutcore-touch.js")
end
end
# Minify dist/sproutcore-touch.js to dist/sproutcore-touch.min.js
file "dist/sproutcore-touch.min.js" => "dist/sproutcore-touch.js" do
puts "Generating sproutcore-touch.min.js"
File.open("dist/sproutcore.prod.js", "w") do |file|
file.puts strip_sc_assert("dist/sproutcore-touch.js")
end
File.open("dist/sproutcore-touch.min.js", "w") do |file|
file.puts uglify("dist/sproutcore-touch.js")
end
end
SC_VERSION = File.read("VERSION").strip
desc "bump the version to the specified version"
task :bump_version, :version do |t, args|
version = args[:version]
File.open("VERSION", "w") { |file| file.write version }
# Bump the version of subcomponents required by the "umbrella" sproutcore
# package.
contents = File.read("packages/sproutcore-touch/package.json")
contents.gsub! %r{"sproutcore-(\w+)": .*$} do
%{"sproutcore-#{$1}": "#{version}"}
end
File.open("packages/sproutcore-touch/package.json", "w") do |file|
file.write contents
end
# Bump the version of each component package
Dir["packages/sproutcore*/package.json", "package.json"].each do |package|
contents = File.read(package)
contents.gsub! %r{"version": .*$}, %{"version": "#{version}",}
contents.gsub! %r{"(sproutcore-?\w*)": [^\n\{,]*(,?)$} do
%{"#{$1}": "#{version}"#{$2}}
end
File.open(package, "w") { |file| file.write contents }
end
sh %{git add VERSION package.json packages/**/package.json}
sh %{git commit -m "Bump version to #{version}"}
end
## STARTER KIT ##
namespace :starter_kit do
sproutcore_output = "tmp/touch-starter-kit/js/libs/sproutcore-touch-#{SC_VERSION}.js"
sproutcore_min_output = "tmp/touch-starter-kit/js/libs/sproutcore-touch-#{SC_VERSION}.min.js"
task :pull => "tmp/touch-starter-kit" do
Dir.chdir("tmp/touch-starter-kit") do
sh "git pull origin master"
end
end
task :clean => :pull do
Dir.chdir("tmp/touch-starter-kit") do
rm_rf Dir["js/libs/sproutcore*.js"]
end
end
task "dist/touch-starter-kit.#{SC_VERSION}.zip" => ["tmp/touch-starter-kit/index.html"] do
mkdir_p "dist"
Dir.chdir("tmp") do
sh %{zip -r ../dist/touch-starter-kit.#{SC_VERSION}.zip touch-starter-kit -x "touch-starter-kit/.git/*"}
end
end
task sproutcore_output => ["tmp/touch-starter-kit", "dist/sproutcore-touch.js"] do
sh "cp dist/sproutcore-touch.js #{sproutcore_output}"
end
task sproutcore_min_output => ["tmp/touch-starter-kit", "dist/sproutcore-touch.min.js"] do
sh "cp dist/sproutcore-touch.min.js #{sproutcore_min_output}"
end
file "tmp/touch-starter-kit" do
mkdir_p "tmp"
Dir.chdir("tmp") do
sh "git clone git://github.com/sproutcore/starter-kit.git -b sproutcore-touch touch-starter-kit"
end
end
file "tmp/touch-starter-kit/index.html" => [sproutcore_output, sproutcore_min_output] do
index = File.read("tmp/touch-starter-kit/index.html")
index.gsub! %r{<script src="js/libs/sproutcore-touch-\d\.\d.*</script>},
%{<script src="js/libs/sproutcore-touch-#{SC_VERSION}.min.js"></script>}
File.open("tmp/touch-starter-kit/index.html", "w") { |f| f.write index }
end
task :index => "tmp/touch-starter-kit/index.html"
desc "Build the SproutCore Touch starter kit"
task :build => "dist/touch-starter-kit.#{SC_VERSION}.zip"
end
desc "Clean build artifacts from previous builds"
task :clean do
sh "rm -rf tmp && rm -rf dist"
end
task :default => ["dist/sproutcore-touch.min.js"]