forked from emberjs/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
243 lines (193 loc) · 5.92 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
# 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'
require './lib/meetups_data'
begin
require 'openssl'
require 'open-uri'
open('https://raw.githubusercontent.com/emberjs/guides.emberjs.com/master/snapshots/versions.json')
rescue OpenSSL::SSL::SSLError
puts <<-NOTICE.gsub(/^ /, '')
IMPORTANT NOTICE
================
It looks like you haven't set up your certs correctly.
You probably want to run \033[1;33mrvm osx-ssl-certs update all\033[0m
If you're not on OSX, or want more information, please check out
\033[1;34mhttps://rvm.io/support/fixing-broken-ssl-certificates\033[0m
NOTICE
exit!
rescue Exception
puts "Attempting to download guides.emberjs.com/version.json failed."
puts "This will prevent the build from working correctly."
puts
raise
end
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
sh('npm install && npm run docs')
end
# JSON is valid YAML
data = YAML.load_file(File.join(repo_path, "docs/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 && npm run production")
end
# JSON is valid YAML
data = YAML.load_file(File.join(repo_path, "dist/docs/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 geocode_meetups
data_path = 'meetups.yml'
puts "Geocoding records from #{data_path}... "
data = YAML.load_file(File.expand_path("./data/#{data_path}"))
data["locations"].each do |loc|
loc["groups"].each do |group|
MeetupsData::GroupGeocoder.from_hash(group).find_location{|msg| puts msg}
end
end
File.open(File.expand_path("../data/#{data_path}", __FILE__), "w") do |f|
YAML.dump(data, f)
end
end
def find_meetup_organizers(update_all)
data_path = 'meetups.yml'
if ENV["MEETUP_API_KEY"].nil?
puts "Set ENV['MEETUP_API_KEY'] to connect to the meetup.com API"
return false
end
puts "Getting organizers data from api.meetup.com for #{data_path}..."
data = YAML.load_file(File.expand_path("./data/#{data_path}"))
data["locations"].each do |loc|
loc["groups"].each do |group|
MeetupsData::GroupOrganizer.from_hash(group).find_organizers(update_all)
end
end
File.open(File.expand_path("../data/#{data_path}", __FILE__), "w") do |f|
YAML.dump(data, f)
end
end
def build
system "middleman build"
end
desc "Generate API Docs"
task :generate_docs do
generate_ember_docs
generate_ember_data_docs
end
desc "Generate Ember Data docs only"
task :generate_ember_data_docs do
generate_ember_data_docs
end
desc "Generate Ember docs only"
task :generate_ember_docs do
generate_ember_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, :only => /\.js$/) do
Rake::Task["generate_docs"].execute
end
listener.start
trap :SIGINT do
exit 0
end
system "middleman server --reload-paths data/"
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
desc "Find coordinates for meetup locations"
task :geocode do
geocode_meetups
end
desc "Find organizers for meetup user group_urlname"
task :findorganizers do |t, args|
find_meetup_organizers(ENV['force'])
end
task "assets:precompile" do
build
end