forked from emberjs/ember.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
526 lines (419 loc) · 14.6 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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
abort "Please use Ruby 1.9 to build Ember.js!" if RUBY_VERSION !~ /^1\.9/
require "bundler/setup"
def pipeline
require 'rake-pipeline'
Rake::Pipeline::Project.new("Assetfile")
end
def setup_uploader(root=Dir.pwd)
require './lib/github_uploader'
login = origin = nil
Dir.chdir(root) do
# get the github user name
login = `git config github.user`.chomp
# 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
end
repoUrl = origin.match(/github\.com[\/:]((.+?)\/(.+?))(\.git)?$/)
username = ENV['GH_USERNAME'] || repoUrl[2] # username part of origin url
repo = ENV['GH_REPO'] || repoUrl[3] # repository name part of origin url
token = ENV["GH_OAUTH_TOKEN"]
uploader = GithubUploader.new(login, username, repo, token)
uploader.authorize
uploader
end
def upload_file(uploader, filename, description, file)
print "Uploading #{filename}..."
if uploader.upload_file(filename, description, file)
puts "Success"
else
puts "Failure"
end
end
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
puts "Building Ember..."
pipeline.invoke
puts "Done"
end
desc "Clean build artifacts from previous builds"
task :clean do
puts "Cleaning build..."
rm_rf "dist" # Make sure even things RakeP doesn't know about are cleaned
rm_f "tests/ember-tests.js"
puts "Done"
end
desc "Upload latest Ember.js build to GitHub repository"
task :upload_latest => [:clean, :dist] do
uploader = setup_uploader
# Upload minified first, so non-minified shows up on top
upload_file(uploader, 'ember-latest.min.js', "Ember.js Master (minified)", "dist/ember.min.js")
upload_file(uploader, 'ember-latest.js', "Ember.js Master", "dist/ember.js")
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
require "ember_docs/cli"
EmberDocs::CLI.start("preview #{doc_args}".split(' '))
end
desc "Build Ember Docs"
task :build do
require "ember_docs/cli"
EmberDocs::CLI.start("generate #{doc_args} -o docs".split(' '))
end
desc "Build and upload Ember Docs"
task :upload => :build do
raise "missing environment variable EMBER_DOCS_UPLOAD_PATH" unless ENV.has_key?('EMBER_DOCS_UPLOAD_PATH')
Rake::Task["docs:build"].invoke
upload_path = ENV['EMBER_DOCS_UPLOAD_PATH']
FileUtils.cd(upload_path) do
system "git pull"
end
FileUtils.rm_rf("#{upload_path}/html.old") if Dir.exists?("#{upload_path}/html.old")
FileUtils.mv("#{upload_path}/html", "#{upload_path}/html.old")
FileUtils.cp_r("docs", "#{upload_path}/html")
FileUtils.cd(upload_path) do
system "git add html && git commit --all -m 'Upload generated API docs' && git push heroku master"
end
FileUtils.rm_rf("#{upload_path}/html.old")
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|
require "colored"
unless system("which phantomjs > /dev/null 2>&1")
abort "PhantomJS is not installed. Download from http://phantomjs.org"
end
packages = Dir['packages/*/tests'].map{|p| p.split('/')[1] }
suites = {
:default => packages.map{|p| "package=#{p}" },
:runtime => [ "package=ember-metal,ember-runtime" ],
:all => packages.map{|p| "package=#{p}" } +
["package=all&jquery=git&nojshint=true",
"package=all&extendprototypes=true&nojshint=true",
"package=all&extendprototypes=true&jquery=git&nojshint=true",
"package=all&nocpdefaultcacheable=true&nojshint=true",
"package=all&noviewpreservescontext=true&nojshint=true",
"package=all&dist=build&nojshint=true"]
}
packages.each do |package|
suites[package.to_sym] = ["package=#{package}"]
end
if ENV['TEST']
opts = [ENV['TEST']]
else
suite = args[:suite] || :default
opts = suites[suite.to_sym]
end
unless opts
abort "No suite named: #{suite}"
end
success = true
opts.each do |opt|
cmd = "phantomjs tests/qunit/run-qunit.js \"file://localhost#{File.dirname(__FILE__)}/tests/index.html?#{opt}\""
system(cmd)
# A bit of a hack until we can figure this out on Travis
tries = 0
while tries < 3 && $?.exitstatus === 124
tries += 1
puts "Timed Out. Trying again..."
system(cmd)
end
success &&= $?.success?
end
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
### 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 "Upload release"
task :upload do
uploader = setup_uploader
# Upload minified first, so non-minified shows up on top
upload_file(uploader, "ember-#{EMBER_VERSION}.min.js", "Ember.js #{EMBER_VERSION} (minified)", "dist/ember.min.js")
upload_file(uploader, "ember-#{EMBER_VERSION}.js", "Ember.js #{EMBER_VERSION}", "dist/ember.js")
end
desc "Prepare for a new release"
task :prepare => [:update, :changelog, :bump_version]
desc "Commit the new release"
task :deploy => [:commit, :tag, :push, :upload]
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
file "dist/ember.js" => :dist
file "dist/ember.min.js" => :dist
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 "Upload release"
task :upload do
uploader = setup_uploader("tmp/starter-kit")
# Upload minified first, so non-minified shows up on top
upload_file(uploader, "starter-kit.#{EMBER_VERSION}.zip", "Ember.js #{EMBER_VERSION} Starter Kit", "dist/starter-kit.#{EMBER_VERSION}.zip")
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, :upload]
end
namespace :examples do
ember_min_output = "tmp/examples/lib/ember.min.js"
task :pull => "tmp/examples" do
Dir.chdir("tmp/examples") do
sh "git pull origin master"
end
end
task :clean => :pull do
Dir.chdir("tmp/examples") do
rm_rf Dir["lib/ember.min.js"]
end
end
file "tmp/examples" do
mkdir_p "tmp"
Dir.chdir("tmp") do
sh "git clone [email protected]:emberjs/examples.git"
end
end
file ember_min_output => [:clean, "tmp/examples", "dist/ember.min.js"] do
sh "cp dist/ember.min.js #{ember_min_output}"
end
desc "Update examples repo"
task :update => ember_min_output do
puts "Updating examples repo"
unless pretend?
Dir.chdir("tmp/examples") do
sh "git add -A"
sh "git commit -m 'Updated to #{EMBER_VERSION}'"
print "Are you sure you want to push the examples 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 "Prepare examples for release"
task :prepare => []
desc "Update examples repo"
task :deploy => [:update]
end
namespace :website do
file "tmp/website" do
mkdir_p "tmp"
Dir.chdir("tmp") do
sh "git clone [email protected]:emberjs/website.git"
end
end
task :pull => "tmp/website" do
Dir.chdir("tmp/website") do
sh "git pull origin master"
end
end
file "dist/ember.min.js" => :dist
file "tmp/website/source/about.html.erb" => [:pull, "dist/ember.min.js"] do
require 'zlib'
about = File.read("tmp/website/source/about.html.erb")
min_gz = Zlib::Deflate.deflate(File.read("dist/ember.min.js")).bytes.count / 1024
about.gsub! %r{https://github\.com/downloads/emberjs/ember\.js/ember-\d(\.\d+)*\.min\.js},
%{https://github.com/downloads/emberjs/ember.js/ember-#{EMBER_VERSION}.min.js}
about.gsub! %r{https://github\.com/downloads/emberjs/starter-kit/starter-kit\.\d(\.\d+)*\.zip},
%{https://github.com/downloads/emberjs/starter-kit/starter-kit.#{EMBER_VERSION}.zip}
about.gsub! /Ember \d(\.\d+)*/, "Ember #{EMBER_VERSION}"
about.gsub! /\d+k min\+gzip/, "#{min_gz}k min+gzip"
File.open("tmp/website/source/about.html.erb", "w") { |f| f.write about }
end
task :about => "tmp/website/source/about.html.erb"
desc "Update website repo"
task :update => :about do
puts "Updating website repo"
unless pretend?
Dir.chdir("tmp/website") do
sh "git add -A"
sh "git commit -m 'Updated to #{EMBER_VERSION}'"
print "Are you sure you want to push the website 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
puts "NOTE: You still need to run `rake deploy` from within the website repo."
end
end
desc "Prepare website for release"
task :prepare => []
desc "Update website repo"
task :deploy => [:update]
end
desc "Prepare Ember for new release"
task :prepare => [:clean, 'framework:prepare', 'starter_kit:prepare', 'examples:prepare', 'website:prepare']
desc "Deploy a new Ember release"
task :deploy => ['framework:deploy', 'starter_kit:deploy', 'examples:deploy', 'website:deploy']
end
task :default => :dist