forked from emberjs/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
158 lines (125 loc) · 3.89 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
# Deploy with new API:
# - rake preview
# - visit http://0.0.0.0:4567 and verify everything was generated correctly
# - ensure data/api.yml has the correct sha/tag, if not just simply update it and use middleman to re-preview
# Deploy without updating the API:
# - middleman
# - visit http://0.0.0.0:4567 and verify everything was generated correctly
# - rake deploy
require "bundler/setup"
require 'yaml'
def git_initialize(repository)
unless File.exist?(".git")
system "git init"
system "git remote add origin [email protected]:emberjs/#{repository}.git"
end
end
def git_update
system "git fetch origin"
system "git reset --hard origin/master"
# Remove all files so we don't accidentally keep old stuff
# These will be regenerated by the build process
system "rm `git ls-files`"
end
def ember_path
File.expand_path(ENV['EMBER_PATH'] || File.expand_path("../../ember.js", __FILE__))
end
def ember_data_path
File.expand_path(ENV['EMBER_DATA_PATH'] || File.expand_path("../../ember-data", __FILE__))
end
def generate_ember_docs
output_path = 'api.yml'
repo_path = ember_path
sha = ENV['EMBER_SHA']
print "Generating docs data from #{repo_path}... "
Dir.chdir(repo_path) do
# returns either `tag` or `tag-numcommits-gSHA`
unless sha
describe = `git describe --tags --always`.strip
sha = describe =~ /-g(.+)/ ? $1 : describe
end
Bundler.with_clean_env do
unless system('bundle check')
puts "You are missing dependencies for #{repo_path}. Attempting to install now."
sh('bundle install')
end
sh("bundle exec rake docs")
end
end
# JSON is valid YAML
data = YAML.load_file(File.join(repo_path, "docs/build/data.json"))
data["project"]["sha"] = sha
File.open(File.expand_path("../data/#{output_path}", __FILE__), "w") do |f|
YAML.dump(data, f)
end
puts "Built #{repo_path} with SHA #{sha}"
end
def generate_ember_data_docs
output_path = 'data_api.yml'
repo_path = ember_data_path
sha = ENV['EMBER_DATA_SHA']
print "Generating docs data from #{repo_path}... "
Dir.chdir(repo_path) do
# returns either `tag` or `tag-numcommits-gSHA`
unless sha
describe = `git describe --tags --always`.strip
sha = describe =~ /-g(.+)/ ? $1 : describe
end
sh("npm install && grunt docs")
end
# JSON is valid YAML
data = YAML.load_file(File.join(repo_path, "docs/build/data.json"))
data["project"]["sha"] = sha
File.open(File.expand_path("../data/#{output_path}", __FILE__), "w") do |f|
YAML.dump(data, f)
end
puts "Built #{repo_path} with SHA #{sha}"
end
def build
system "middleman build"
end
desc "Generate API Docs"
task :generate_docs do
generate_ember_docs
generate_ember_data_docs
end
desc "Build the website"
task :build => :generate_docs do
build
end
desc "Preview"
task :preview do
require 'listen'
Rake::Task["generate_docs"].execute
paths = Dir.glob(File.join(ember_path, "packages/*/lib")) +
Dir.glob(File.join(ember_data_path, "packages/*/lib"))
listener = Listen.to(*paths, :filter => /\.js$/)
listener.change { Rake::Task["generate_docs"].execute }
listener.start(false)
system "middleman server"
end
desc "Deploy the website to github pages"
task :deploy do |t, args|
require "highline/import"
message = ask("Provide a deployment message: ") do |q|
q.validate = /\w/
q.responses[:not_valid] = "Can't be empty."
end
mkdir_p "build"
Dir.chdir "build" do
git_initialize("emberjs.github.com")
git_update
unless build
puts "The build failed, stopping deploy. Please fix build errors before re-deploying."
exit 1
end
# This screws up the build and isn't necessary
# rm_r "source/examples"
File.open("CNAME", 'w') do |f|
f.write "emberjs.com"
end
system "git add -A"
system "git commit -m '#{message.gsub("'", "\\'")}'"
system "git push origin master" unless ENV['NODEPLOY']
end
end