forked from raciel/helabs.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
68 lines (47 loc) · 1.96 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
Dir['./lib/tasks/**/*.rake'].each { |f| load f }
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
desc 'Remove unused images'
task :prune_images do
require 'colored'
plain_files_content = ''
Dir['./**/*.{html,htm,scss,css,sass,yml,md,js,coffee,json,xml}'].each do |file_name|
File.open file_name, mode: 'r' do |file|
plain_files_content += file.readlines.join "\n"
end
end
unused_images = Dir['./images/**/*.{jpg,jpeg,gif,png}'].reject do |image_file_name|
plain_files_content.include? image_file_name.sub './', '/'
end
unused_images.each do |image_file_name|
puts "Deleting: #{image_file_name}...".red
File.delete image_file_name
end
puts "#{unused_images.count} unused images were deleted!".bold.red
end
desc 'Push to staging.helabs.com.br'
task :staging do
require 'colored'
puts '=> Memorizing current branch name...'.magenta
current_branch = `git branch | grep "*"`.gsub('*', '').strip
puts '=> Remove staging branch...'.magenta
system 'git branch -D staging'
puts '=> Create orphan staging branch...'.magenta
system 'git checkout --orphan staging'
puts '=> Disallow robots...'.magenta
File.open('robots.txt', 'w') { |file| file.write "User-agent: *\nDisallow: /" }
puts '=> Change CNAME...'.magenta
File.open('CNAME', 'w') { |file| file.write 'staging.helabs.com.br' }
puts '=> Add everything...'.magenta
system 'git add --all'
puts '=> Commit everything...'.magenta
system 'git commit -m "Staging commit"'
puts '=> Add staging remote...'.magenta
system 'git remote add staging [email protected]:Helabs/staging.helabs.com.br.git'
puts '=> Force push to staging. Get some coffee, it may take some time...'.magenta
system 'git push -f staging staging:gh-pages'
puts "=> Checkout #{current_branch} branch...".magenta
system "git checkout #{current_branch}"
puts '=> Done. It can take up to 10 minutes for your changes to appear staging.helabs.com.br'.yellow
end