forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
334 lines (268 loc) · 8.86 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
abort "Please use Ruby 1.9 to build Ember.js!" if RUBY_VERSION !~ /^1\.9/
require "bundler/setup"
require "erb"
require 'rake-pipeline'
require "ember_docs/cli"
require "colored"
desc "Strip trailing whitespace for JavaScript files in packages"
task :strip_whitespace do
Dir["packages/**/*.js"].each do |name|
body = File.read(name)
File.open(name, "w") do |file|
file.write body.gsub(/ +\n/, "\n")
end
end
end
desc "Build ember.js"
task :dist do
Rake::Pipeline::Project.new("Assetfile").invoke
end
desc "Clean build artifacts from previous builds"
task :clean do
sh "rm -rf tmp dist tests/ember-tests.js"
end
### UPLOAD LATEST EMBERJS BUILD TASK ###
desc "Upload latest Ember.js build to GitHub repository"
task :upload => :dist do
require "net/github-upload"
# setup
login = `git config github.user`.chomp # your login for github
token = `git config github.token`.chomp # your token for github
# get repo from git config's origin url
origin = `git config remote.origin.url`.chomp # url to origin
# extract USERNAME/REPO_NAME
# sample urls: https://github.com/emberjs/ember.js.git
# git://github.com/emberjs/ember.js.git
# [email protected]:emberjs/ember.js.git
# [email protected]:emberjs/ember.js
repo = origin.match(/github\.com[\/:](.+?)(\.git)?$/)[1]
puts "Uploading to repository: " + repo
gh = Net::GitHub::Upload.new(
:login => login,
:token => token
)
puts "Uploading ember-latest.js"
gh.replace(
:repos => repo,
:file => 'dist/ember.js',
:name => 'ember-latest.js',
:content_type => 'application/json',
:description => "Ember.js Master"
)
puts "Uploading ember-latest.min.js"
gh.replace(
:repos => repo,
:file => 'dist/ember.min.js',
:name => 'ember-latest.min.js',
:content_type => 'application/json',
:description => "Ember.js Master (minified)"
)
end
### RELEASE TASKS ###
EMBER_VERSION = File.read("VERSION").strip
namespace :release do
def pretend?
ENV['PRETEND']
end
namespace :framework do
desc "Update repo"
task :update do
puts "Making sure repo is up to date..."
system "git pull" unless pretend?
end
desc "Update Changelog"
task :changelog do
last_tag = `git describe --tags --abbrev=0`.strip
puts "Getting Changes since #{last_tag}"
cmd = "git log #{last_tag}..HEAD --format='* %s'"
puts cmd
changes = `#{cmd}`
output = "*Ember #{EMBER_VERSION} (#{Time.now.strftime("%B %d, %Y")})*\n\n#{changes}\n"
unless pretend?
File.open('CHANGELOG', 'r+') do |file|
current = file.read
file.pos = 0;
file.puts output
file.puts current
end
else
puts output.split("\n").map!{|s| " #{s}"}.join("\n")
end
end
desc "bump the version to the one specified in the VERSION file"
task :bump_version, :version do
puts "Bumping to version: #{EMBER_VERSION}"
unless pretend?
# Bump the version of each component package
Dir["packages/ember*/package.json", "ember.json"].each do |package|
contents = File.read(package)
contents.gsub! %r{"version": .*$}, %{"version": "#{EMBER_VERSION}",}
contents.gsub! %r{"(ember[\w-]*)": [^,\n]+(,)?$} do
%{"#{$1}": "#{EMBER_VERSION}"#{$2}}
end
File.open(package, "w") { |file| file.write contents }
end
# Bump ember-metal/core version
contents = File.read("packages/ember-metal/lib/core.js")
current_version = contents.match(/@version ([\w\.]+)/) && $1
contents.gsub!(current_version, EMBER_VERSION);
File.open("packages/ember-metal/lib/core.js", "w") do |file|
file.write contents
end
end
end
desc "Commit framework version bump"
task :commit do
puts "Commiting Version Bump"
unless pretend?
sh "git reset"
sh %{git add VERSION CHANGELOG packages/ember-metal/lib/core.js ember.json packages/**/package.json}
sh "git commit -m 'Version bump - #{EMBER_VERSION}'"
end
end
desc "Tag new version"
task :tag do
puts "Tagging v#{EMBER_VERSION}"
system "git tag v#{EMBER_VERSION}" unless pretend?
end
desc "Push new commit to git"
task :push do
puts "Pushing Repo"
unless pretend?
print "Are you sure you want to push the ember.js repo to github? (y/N) "
res = STDIN.gets.chomp
if res == 'y'
system "git push"
system "git push --tags"
else
puts "Not Pushing"
end
end
end
desc "Prepare for a new release"
task :prepare => [:update, :changelog, :bump_version]
desc "Commit the new release"
task :deploy => [:commit, :tag, :push]
end
namespace :starter_kit do
ember_output = "tmp/starter-kit/js/libs/ember-#{EMBER_VERSION}.js"
ember_min_output = "tmp/starter-kit/js/libs/ember-#{EMBER_VERSION}.min.js"
task :pull => "tmp/starter-kit" do
Dir.chdir("tmp/starter-kit") do
sh "git pull origin master"
end
end
task :clean => :pull do
Dir.chdir("tmp/starter-kit") do
rm_rf Dir["js/libs/ember*.js"]
end
end
task "dist/starter-kit.#{EMBER_VERSION}.zip" => ["tmp/starter-kit/index.html"] do
mkdir_p "dist"
Dir.chdir("tmp") do
sh %{zip -r ../dist/starter-kit.#{EMBER_VERSION}.zip starter-kit -x "starter-kit/.git/*"}
end
end
file ember_output => [:clean, "tmp/starter-kit", "dist/ember.js"] do
sh "cp dist/ember.js #{ember_output}"
end
file ember_min_output => [:clean, "tmp/starter-kit", "dist/ember.min.js"] do
sh "cp dist/ember.min.js #{ember_min_output}"
end
file "tmp/starter-kit" do
mkdir_p "tmp"
Dir.chdir("tmp") do
sh "git clone [email protected]:emberjs/starter-kit.git"
end
end
file "tmp/starter-kit/index.html" => [ember_output, ember_min_output] do
index = File.read("tmp/starter-kit/index.html")
index.gsub! %r{<script src="js/libs/ember-\d\.\d.*</script>},
%{<script src="js/libs/ember-#{EMBER_VERSION}.min.js"></script>}
File.open("tmp/starter-kit/index.html", "w") { |f| f.write index }
end
task :index => "tmp/starter-kit/index.html"
desc "Update starter-kit repo"
task :update => :index do
puts "Updating starter-kit repo"
unless pretend?
Dir.chdir("tmp/starter-kit") do
sh "git add -A"
sh "git commit -m 'Updated to #{EMBER_VERSION}'"
sh "git tag v#{EMBER_VERSION}"
print "Are you sure you want to push the starter-kit repo to github? (y/N) "
res = STDIN.gets.chomp
if res == 'y'
sh "git push origin master"
sh "git push --tags"
else
puts "Not pushing"
end
end
end
end
desc "Build the Ember.js starter kit"
task :build => "dist/starter-kit.#{EMBER_VERSION}.zip"
desc "Prepare starter-kit for release"
task :prepare => [:build]
desc "Release starter-kit"
task :deploy => [:update]
end
desc "Prepare Ember for new release"
task :prepare => ['framework:prepare', 'starter_kit:prepare']
desc "Deploy a new Ember release"
task :deploy => ['framework:deploy', 'starter_kit:deploy']
end
namespace :docs do
def doc_args
"#{Dir.glob("packages/ember-*").join(' ')} -E #{Dir.glob("packages/ember-*/tests").join(' ')} -t docs.emberjs.com"
end
desc "Preview Ember Docs (does not auto update)"
task :preview do
EmberDocs::CLI.start("preview #{doc_args}".split(' '))
end
desc "Build Ember Docs"
task :build do
EmberDocs::CLI.start("generate #{doc_args} -o docs".split(' '))
end
desc "Remove Ember Docs"
task :clean do
rm_r "docs"
end
end
desc "Run tests with phantomjs"
task :test, [:suite] => :dist do |t, args|
unless system("which phantomjs > /dev/null 2>&1")
abort "PhantomJS is not installed. Download from http://phantomjs.org"
end
suites = {
:default => ["package=all"],
:all => ["package=all",
"package=all&jquery=1.6.4&nojshint=true",
"package=all&extendprototypes=true&nojshint=true",
"package=all&extendprototypes=true&jquery=1.6.4&nojshint=true",
"package=all&dist=build&nojshint=true"]
}
suite = args[:suite] || :default
opts = suites[suite.to_sym]
unless opts
abort "No suite named: #{suite}"
end
cmd = opts.map do |opt|
"phantomjs tests/qunit/run-qunit.js \"file://localhost#{File.dirname(__FILE__)}/tests/index.html?#{opt}\""
end.join(' && ')
# Run the tests
puts "Running: #{opts.join(", ")}"
success = system(cmd)
if success
puts "Tests Passed".green
else
puts "Tests Failed".red
exit(1)
end
end
desc "Automatically run tests (Mac OS X only)"
task :autotest do
system("kicker -e 'rake test' packages")
end
task :default => :dist