forked from cloudfoundry-community/cf-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
79 lines (64 loc) · 1.55 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
require 'erb'
require 'json'
def _site
File.join(Dir::pwd, "_site")
end
def _site_index_html
File.join(_site, "index.html")
end
task :build do
File.open("data.json", "r") do |f|
@categories = JSON.parse(f.read)["categories"]
end
File.open("index.html.erb", "r") do |f|
@template = f.read
end
p "Building template..."
index_html = ERB.new(@template).result(binding)
p "Making _site..."
if FileTest::directory?(_site)
FileUtils.rm_rf(_site, secure: true)
end
Dir::mkdir(_site)
p "Writing index.html..."
File.open(_site_index_html, "w") do |f|
f.write(index_html)
end
p "Copying assets..."
assets = File.join(Dir::pwd, "sample", "assets")
FileUtils.cp_r(assets, File.join(_site, "assets"))
p "Done!"
end
task :open do
`open #{_site_index_html}`
end
task :deploy do
system 'git checkout master'
system 'rm -rf ./_site'
system 'rake build'
system 'rm -rf ../_site'
system 'cp -r ./_site ../_site'
system 'git checkout gh-pages'
Dir[`pwd`[0..-2] + "/*"].each do |file|
skip = ["CNAME", "sitemap", "Rakefile", "README"]
skipping = false
skip.each do |skip_file|
skipping = true if skip_file.include? file
end
next if skipping
begin
FileUtils.rm_rf(file)
rescue
FileUtils.rm(file)
end
end
system 'mv ../_site/* ./'
system 'git status'
msg = `git status`
system 'git add .'
system "git commit -m 'Sync gh-pages \n #{msg}'"
system 'git push origin gh-pages'
system 'git checkout master'
system 'git checkout .'
system 'rm -rf ../_site'
end