This repository has been archived by the owner on Oct 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathRakefile
264 lines (200 loc) · 6.56 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# --------------------------------------------------------- #
# This rake file is borrowed from EmberJS
# https://github.com/emberjs/website/blob/master/Rakefile
# --------------------------------------------------------- #
require "bundler/setup"
require "fileutils"
require 'semantic'
require "json"
def git_initialize(repository)
unless File.exist?(".git")
system "git init"
system "git remote add heroku [email protected]:#{repository}.git"
end
end
def marionette_path
File.expand_path("../../backbone.marionette", __FILE__)
end
def current_path
File.expand_path(File.dirname(__FILE__))
end
def build
generate_marionette_docs
get_anotated_source
system "middleman build"
Dir.chdir "build" do
system "cp ../config.ru ."
system "cp ../Procfile ."
end
end
def generate_marionette_api
repo_path = marionette_path
site_path = current_path
puts "Generating api from #{repo_path}... "
api = {}
api['properties'] = {}
api['functions'] = {}
api['classes'] = []
# build the most recent jsdoc
Dir.chdir(repo_path) do
system("grunt api")
my_hash = JSON.parse('{"hello": "goodbye"}')
filenames = Dir.glob('jsdoc/*.json')
filenames.each do |filename|
doc = File.open(filename, "r").read
api_hash = JSON.parse(doc)
if api_hash.has_key?("class")
api['classes'] << api_hash
else
api['properties'].merge! api_hash['properties'] unless api_hash['properties'].empty?
api['functions'].merge! api_hash['functions'] unless api_hash['functions'].empty?
end
end
end
Dir.chdir("#{site_path}/source/api-assets") do
FileUtils.mkdir_p("#{site_path}/source/api") unless File.directory?("#{site_path}/source/api")
File.write("jsDocFile.json", JSON.pretty_generate(api))
system("node build.js");
end
end
def generate_marionette_docs
# output_path = 'api.yml'
repo_path = marionette_path
site_path = current_path
current_tag = ""
select_box = "<select id=\"version\" class=\"form-control\">"
tags = Array.new
print "Generating docs data from #{repo_path}... "
Dir.chdir(repo_path) do
system("git checkout master")
describe = `git describe --tags --abbrev=0 --always`.strip
current_tag = describe.gsub("\n", "")
# get list of tags in marionette repo
describe = `git tag`.strip
tags = describe.split("\n")
tags = tags.sort do |tag, tag2|
if tag == "v1.7"
tag = "v1.7.0"
end
if tag2 == "v1.7"
tag2 = "v1.7.0"
end
if tag == "v1.4.0beta"
tag = "v1.4.0-beta"
end
if tag2 == "v1.4.0beta"
tag2 = "v1.4.0-beta"
end
if tag == "v0.4.1a"
tag = "v0.4.1-a"
end
if tag2 == "v0.4.1a"
tag2 = "v0.4.1-a"
end
tag = tag.gsub('v', '')
tag2 = tag2.gsub('v', '')
version1 = Semantic::Version.new tag
version2 = Semantic::Version.new tag2
version1 <=> version2
end
tags = tags.reverse
tags.each do |tag|
tag = tag.gsub("\n", "")
system("git checkout tags/#{tag}")
filenames = Dir.glob('docs/*.md')
if filenames.count > 0
FileUtils.mkdir_p("#{site_path}/source/docs/#{tag}")
if tag == current_tag
select_box += "<option value=\"#{tag}\">#{tag} (current)</option>"
else
select_box += "<option value=\"#{tag}\">#{tag}</option>"
end
end
filenames.each do |filename|
newfilename = File.basename(filename, ".*" )
FileUtils.cp(filename, "#{site_path}/source/docs/#{tag}/#{newfilename}.md")
end
end
select_box += "</select>"
# checkout latest tag
system("git checkout tags/#{current_tag}")
FileUtils.mkdir_p("#{site_path}/source/docs/current")
filenames = Dir.glob('docs/*.md')
filenames.each do |filename|
newfilename = File.basename(filename, ".*" )
FileUtils.cp(filename, "#{site_path}/source/docs/current/#{newfilename}.md")
end
end
# generate current docs
tags.each do |tag|
if File.directory?("#{site_path}/source/docs/#{tag}")
Dir.chdir("#{site_path}/source/docs/#{tag}") do
system("node ../../doc-assets/build.js");
system("rm *.md");
text = File.read('sidebar_.html')
File.write('sidebar_.html', text.gsub('{select_box}', select_box))
end
end
end
Dir.chdir("#{site_path}/source/docs/current") do
system("node ../../doc-assets/build.js");
system("rm *.md");
text = File.read('sidebar_.html')
File.write('sidebar_.html', text.gsub('{select_box}', select_box))
end
FileUtils.mkdir_p("#{site_path}/backbone.marionette/#{current_tag}")
system("curl https://raw.githubusercontent.com/marionettejs/backbone.marionette/#{current_tag}/lib/backbone.marionette.js > backbone.marionette/#{current_tag}/backbone.marionette.js")
system("./node_modules/.bin/docco backbone.marionette/#{current_tag}/backbone.marionette.js -o source/annotated-src/#{current_tag}")
system("./node_modules/.bin/docco backbone.marionette/#{current_tag}/backbone.marionette.js -o source/annotated-src")
system("rm -rdf backbone.marionette")
end
def get_anotated_source
# output_path = 'api.yml'
repo_path = marionette_path
site_path = current_path
current_tag = ""
tags = Array.new
Dir.chdir(repo_path) do
# get list of tags in marionette repo
describe = `git tag`.strip
tags = describe.split("\n")
end
print "Generating annotated src data from #{repo_path}... "
tags.each do |tag|
tag = tag.gsub("\n", "")
FileUtils.mkdir_p("#{site_path}/backbone.marionette/#{tag}")
system("curl https://raw.githubusercontent.com/marionettejs/backbone.marionette/#{tag}/lib/backbone.marionette.js > backbone.marionette/#{tag}/backbone.marionette.js")
system("./node_modules/.bin/docco backbone.marionette/#{tag}/backbone.marionette.js -o source/annotated-src/#{tag}")
end
system("rm -rdf backbone.marionette");
end
task :generate_docs do
generate_marionette_docs
end
task :api do
generate_marionette_api
end
task :backfill_anotated_source do
get_anotated_source
end
task :build do
build
end
desc "Build and deploy the website to github pages"
task :deploy do
require "highline/import"
message = "Deploy marionettejs.com"
mkdir_p "build"
Dir.chdir "build" do
system "cp ../Gemfile ."
system "cp ../Gemfile.lock ."
git_initialize("marionette-www")
system "git remote add heroku [email protected]:marionette-www.git"
end
build
Dir.chdir "build" do
system "git add -A"
system "git commit -m '#{message.gsub("'", "\\'")}'"
system "git push --force heroku master"
end
end