forked from sharu725/online-cv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
109 lines (98 loc) · 2.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
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
require "reduce"
desc "Delete _site/"
task :delete do
puts "\## Deleting _site/"
status = system("rm -r _site")
puts status ? "Success" : "Failed"
end
desc "Preview _site/"
task :preview do
puts "\n## Opening _site/ in browser"
status = system("open http://0.0.0.0:4000/")
puts status ? "Success" : "Failed"
end
# Courtesy of https://github.com/pacbard/blog/blob/master/_rake/minify.rake
desc "Minify _site/"
task :minify do
puts "\n## Compressing static assets"
original = 0.0
compressed = 0
Dir.glob("_site/**/*.*") do |file|
case File.extname(file)
when ".css", ".gif", ".html", ".jpg", ".jpeg", ".js", ".png", ".xml"
puts "Processing: #{file}"
original += File.size(file).to_f
min = Reduce.reduce(file)
File.open(file, "w") do |f|
f.write(min)
end
compressed += File.size(file)
else
puts "Skipping: #{file}"
end
end
puts "Total compression %0.2f%%" % (((original-compressed)/original)*100)
end
desc "Recompile Sass"
task :recompile_sass do
puts "\n## Forcing Sass to recompile"
status = system("touch -m assets/scss/styles.scss")
puts status ? "Success" : "Failed"
end
namespace :build do
desc "Build _site/ for development"
task :dev => :recompile_sass do
puts "\n## Starting Sass and Jekyll"
pids = [
spawn("bundle exec jekyll serve")
]
trap "INT" do
Process.kill "INT", *pids
exit 1
end
loop do
sleep 1
end
end
desc "Build _site/ for production"
task :pro => :recompile_sass do
puts "\n## Building Jekyll to _site/"
status = system("bundle exec jekyll build")
puts status ? "Success" : "Failed"
Rake::Task["minify"].invoke
end
end
desc "Commit _site/"
task :commit do
puts "\n## Staging modified files"
status = system("git add _site")
puts status ? "Success" : "Failed"
puts "\n## Committing a site build at #{Time.now.utc}"
message = "Build site at #{Time.now.utc}"
status = system("git commit -m \"#{message}\"")
puts status ? "Success" : "Failed"
puts "\n## Pushing commits to remote"
status = system("git push origin gh-pages")
puts status ? "Success" : "Failed"
end
desc "Deploy _site/ to master branch"
task :deploy do
puts "\n## Deleting master branch"
status = system("git branch -D master")
puts status ? "Success" : "Failed"
puts "\n## Creating new master branch and switching to it"
status = system("git checkout -b master")
puts status ? "Success" : "Failed"
puts "\n## Forcing the _site subdirectory to be project root"
status = system("git filter-branch --subdirectory-filter _site/ -f")
puts status ? "Success" : "Failed"
puts "\n## Switching back to source branch"
status = system("git checkout gh-pages")
puts status ? "Success" : "Failed"
puts "\n## Pushing all branches to origin"
status = system("git push --all origin")
puts status ? "Success" : "Failed"
end
desc "Commit and deploy _site/"
task :commit_deploy => [:commit, :deploy] do
end