forked from senchalabs/jsduck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
565 lines (495 loc) · 18.8 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
require 'rubygems'
require 'rake'
require 'json'
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
require 'rspec'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ["--color"]
spec.pattern = "spec/**/*_spec.rb"
end
def load_sdk_vars
if File.exists?("sdk-vars.rb")
require "sdk-vars.rb"
else
puts "Error: sdk-vars.rb not found."
puts
puts "Please create file sdk-vars.rb and define constants SDK_DIR and OUT_DIR in it."
puts
puts "For example:"
puts
puts " # path to Ext JS 4 build"
puts " EXT_DIR='/path/to/ext-4.0.6'"
puts " # where to output the docs"
puts " OUT_DIR='/path/to/ouput/dir'"
puts " # path to SDK (for developers at Sencha)"
puts " SDK_DIR='/path/to/SDK'"
puts " # path to Animator (for developers at Sencha)"
puts " ANIMATOR_DIR='/path/to/Animator'"
exit 1
end
end
# Compress JS/CSS file in-place
# Using a hackish way to access yui-compressor
def yui_compress(fname)
system "java -jar $(dirname $(which sencha))/../jsbuilder/ycompressor/ycompressor.jar -o #{fname} #{fname}"
end
# Reads in all CSS files referenced between BEGIN CSS and END CSS markers.
# Deletes those input CSS files and writes out concatenated CSS to
# resources/css/app.css
# Finally replaces the CSS section with <link> to that one CSS file.
def combine_css(html, dir, opts = :write)
css_section_re = /<!-- BEGIN CSS -->.*<!-- END CSS -->/m
css = []
css_section_re.match(html)[0].each_line do |line|
if line =~ /<link rel="stylesheet" href="(.*?)"/
file = $1
css << IO.read(dir + "/" + file)
system("rm", dir + "/" + file) if opts == :write
end
end
if opts == :write
fname = "#{dir}/resources/css/app.css"
File.open(fname, 'w') {|f| f.write(css.join("\n")) }
yui_compress(fname)
end
html.sub(css_section_re, '<link rel="stylesheet" href="resources/css/app.css" type="text/css" />')
end
# Same thing for JavaScript, result is written to: app.js
def combine_js(html, dir)
js_section_re = /<!-- BEGIN JS -->.*<!-- END JS -->/m
js = []
js_section_re.match(html)[0].each_line do |line|
if line =~ /<script .* src="(.*)">/
file = $1
js << IO.read(dir + "/" + file)
if file !~ /ext\.js/
system("rm", dir + "/" + file)
end
elsif line =~ /<script .*>(.*)<\/script>/
js << $1
end
end
fname = "#{dir}/app.js"
File.open(fname, 'w') {|f| f.write(js.join("\n")) }
yui_compress(fname)
html.sub(js_section_re, '<script type="text/javascript" src="app.js"></script>')
end
# Compress JavaScript and CSS files of JSDuck
def compress
load_sdk_vars
# Clean up template-min/ left over from previous compress task
system("rm", "-rf", "template-min")
# Copy template/ files to template-min/
system("cp", "-r", "template", "template-min")
# Now do everything that follows in template-min/ dir
dir = "template-min"
# Create JSB3 file for Docs app
system("sencha", "create", "jsb", "-a", "#{dir}/build-js.html", "-p", "#{dir}/app.jsb3")
# Concatenate files listed in JSB3 file
system("sencha", "build", "-p", "#{dir}/app.jsb3", "-d", dir)
# Remove intermediate build files
system("rm", "#{dir}/app.jsb3")
system("rm", "#{dir}/all-classes.js")
# Replace app.js with app-all.js
system("mv", "#{dir}/app-all.js", "#{dir}/app.js")
# Remove the entire app/ dir
system("rm", "-r", "#{dir}/app")
# Concatenate CSS in print-template.html file
print_template = "#{dir}/print-template.html";
html = IO.read(print_template);
# Just modify HTML to link app.css, don't write files.
html = combine_css(html, dir, :replace_html_only)
File.open(print_template, 'w') {|f| f.write(html) }
# Concatenate CSS and JS files referenced in template.html file
template_html = "#{dir}/template.html"
html = IO.read(template_html)
html = combine_css(html, dir)
html = combine_js(html, dir)
File.open(template_html, 'w') {|f| f.write(html) }
# Clean up SASS files
# (But keep prettify lib, which is needed for source files)
system "rm -rf #{dir}/resources/sass"
system "rm -rf #{dir}/resources/codemirror"
system "rm -rf #{dir}/resources/.sass-cache"
# Empty the extjs dir, leave only the main JS files, CSS and images
system "rm -rf #{dir}/extjs"
system "mkdir #{dir}/extjs"
system "cp #{EXT_DIR}/ext-all.js #{dir}/extjs"
system "cp #{EXT_DIR}/ext-all-debug.js #{dir}/extjs"
system "cp #{EXT_DIR}/bootstrap.js #{dir}/extjs"
system "mkdir -p #{dir}/extjs/resources/css"
system "cp #{EXT_DIR}/resources/css/ext-all.css #{dir}/extjs/resources/css"
system "mkdir -p #{dir}/extjs/resources/themes/images"
system "cp -r #{EXT_DIR}/resources/themes/images/default #{dir}/extjs/resources/themes/images"
end
class JsDuckRunner
def initialize
@options = []
load_sdk_vars
@sdk_dir = SDK_DIR
@out_dir = OUT_DIR
@ext_dir = EXT_DIR
@animator_dir = ANIMATOR_DIR
end
def add_options(options)
@options += options
end
def add_sdk
head_html = <<-EOHTML
<link rel="canonical" href="http://docs.sencha.com/ext-js/4-0/" />
<meta name="description" content="Ext JS 4.0 API Documentation from Sencha. Class documentation, Guides and Videos on how to create Javascript applications with Ext JS 4">
EOHTML
@options += [
"--title", "Sencha Docs - Ext JS 4.0",
"--head-html", head_html,
"--footer", "Ext JS 4.0.6 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> rev #{revision}",
"--welcome", "template/welcome.html",
"--guides", "#{@sdk_dir}/extjs/docs/guides.json",
"--videos", "#{@sdk_dir}/extjs/docs/videos.json",
"--examples", "#{@sdk_dir}/extjs/examples/examples.json",
"--categories", "#{@sdk_dir}/extjs/docs/categories.json",
"--output", "#{@out_dir}",
"--builtin-classes",
"--images", "#{@sdk_dir}/extjs/docs/resources",
"--images", "#{@sdk_dir}/platform/docs/resources",
"#{@sdk_dir}/extjs/src",
"#{@sdk_dir}/platform/src",
"#{@sdk_dir}/platform/core/src",
]
end
def add_ext4
@options += [
"--title", "Sencha Docs - Ext JS 4.0",
"--footer", "Ext JS 4.0 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
"--ignore-global",
"--no-warnings",
"--images", "#{@ext_dir}/docs/doc-resources",
"--output", "#{@out_dir}",
"#{@ext_dir}/src",
]
end
def add_touch
head_html = <<-EOHTML
<link rel="canonical" href="http://docs.sencha.com/touch/1-0/" />
<meta name="description" content="Sencha Touch 1.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch">
EOHTML
@options += [
"--title", "Sencha Docs - Touch 1.0",
"--head-html", head_html,
"--footer", "Sencha Touch 1.0 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
"--categories", "#{@sdk_dir}/touch/doc-resources/categories.json",
"--videos", "#{@sdk_dir}/touch/doc-resources/videos.json",
"--output", "#{@out_dir}",
"--external=google.maps.Map,google.maps.LatLng",
"--images", "#{@sdk_dir}/touch/doc-resources",
"#{@sdk_dir}/touch/resources/themes/stylesheets/sencha-touch/default",
]
@options += extract_jsb_build_files("#{@sdk_dir}/touch/sencha-touch.jsb3")
end
def add_touch2
head_html = <<-EOHTML
<link rel="canonical" href="http://docs.sencha.com/touch/2-0/" />
<meta name="description" content="Sencha Touch 2.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch">
EOHTML
@options += [
"--title", "Sencha Docs - Touch 2.0",
"--head-html", head_html,
"--footer", "Sencha Touch 2.0 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
"--categories", "#{@sdk_dir}/touch/docs/categories.json",
"--welcome", "template/touch-welcome.html",
"--videos", "#{@sdk_dir}/touch/docs/videos.json",
"--guides", "#{@sdk_dir}/touch/docs/guides.json",
"--examples", "#{@sdk_dir}/touch/docs/examples.json",
"--touch-examples-ui",
"--output", "#{@out_dir}",
"--external=google.maps.Map,google.maps.LatLng",
"--builtin-classes",
"--img", "<p class='screenshot'><img src='%u' alt='%a'><span>%a</span></p>",
"#{@sdk_dir}/touch/resources/themes/stylesheets/sencha-touch/default",
]
@options += extract_jsb_build_files("#{@sdk_dir}/touch/touch.jsb3")
end
def add_touch_export
@options += [
"--json",
"--output", "#{@out_dir}/../export/touch1",
"--external=google.maps.Map,google.maps.LatLng",
]
@options += extract_jsb_build_files("#{@sdk_dir}/touch/sencha-touch.jsb3")
end
def add_touch2_export
@options += [
"--json",
"--output", "#{@out_dir}/../export/touch2",
"--external=google.maps.Map,google.maps.LatLng",
]
@options += extract_jsb_build_files("#{@sdk_dir}/touch/touch.jsb3")
end
def set_touch2_src
relative_touch_path = "../"
touch_iframe = "template-min/touchIframe.html";
["template-min/touchIframe.html", "template-min/touch-welcome.html"].each do |file|
html = IO.read(file);
touch_src_re = /((src|href)="touch)/m
out = []
html.each_line do |line|
out << line.sub(/((src|href)="touch\/)/, '\2="' + relative_touch_path)
end
File.open(file, 'w') {|f| f.write(out) }
end
@options += [
"--welcome", "template-min/touch-welcome.html",
"--body-html",
'<script type="text/javascript">Docs.exampleBaseUrl = "' + relative_touch_path + 'examples/";if (Ext.is.Phone) { window.location = "' + relative_touch_path + 'examples/"; }</script>'
]
end
def add_animator
head_html = <<-EOHTML
<link rel="canonical" href="http://docs.sencha.com/animator/1-0/" />
<meta name="description" content="Sencha Animator 1.0 API Documentation from Sencha. Documentation on how to create Javascript applications with Sencha Touch">
EOHTML
@options += [
"--title", "Sencha Docs - Animator 1.0",
"--head-html", head_html,
"--footer", "Sencha Animator 1.0 Docs - Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> revison #{revision}",
# "--videos", "#{@animator_dir}/docs/videos.json",
"--guides", "#{@animator_dir}/docs/guides.json",
# "--examples", "#{@animator_dir}/docs/examples/examples.json",
"--output", "#{@out_dir}",
]
end
# Extracts files of first build in jsb file
def extract_jsb_build_files(jsb_file)
json = JSON.parse(IO.read(jsb_file))
basedir = File.dirname(jsb_file)
return json["builds"][0]["packages"].map do |package_id|
package = json["packages"].find {|p| p["id"] == package_id }
package["files"].map do |file|
basedir + "/" + file["path"] + file["name"]
end
end.flatten
end
# Returns shortened hash of naming current git revision
def revision
`git rev-parse HEAD`.slice(0, 7)
end
def add_debug
@options += [
"--extjs-path", "extjs/ext-all-debug.js",
"--template-links",
"--template", "template",
]
end
def add_seo
@options += [
"--seo",
]
end
def add_sdk_export_notice
@options += [
"--body-html", <<-EOHTML
<div id="notice-text" style="display: none">
Use <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a> for up to date documentation and features
</div>
EOHTML
]
end
def add_touch2_export_notice
@options += [
"--body-html", <<-EOHTML
<div id="notice-text" style="display: none">
Use <a href="http://docs.sencha.com/touch/2-0">http://docs.sencha.com/touch/2-0</a> for up to date documentation and features
</div>
EOHTML
]
end
def add_google_analytics
@options += [
"--body-html", <<-EOHTML
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1396058-10']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
Docs.initEventTracking = function() {
Docs.App.getController('Classes').addListener({
showClass: function(cls) {
_gaq.push(['_trackEvent', 'Classes', 'Show', cls]);
},
showMember: function(cls, anchor) {
_gaq.push(['_trackEvent', 'Classes', 'Member', cls + ' - ' + anchor]);
}
});
Docs.App.getController('Guides').addListener({
showGuide: function(guide) {
_gaq.push(['_trackEvent', 'Guides', 'Show', guide]);
}
});
Docs.App.getController('Videos').addListener({
showVideo: function(video) {
_gaq.push(['_trackEvent', 'Video', 'Show', video]);
}
});
Docs.App.getController('Examples').addListener({
showExample: function(example) {
_gaq.push(['_trackEvent', 'Example', 'Show', example]);
}
});
}
</script>
EOHTML
]
end
# Copy over SDK examples
def copy_sdk_examples
system "mkdir #{@out_dir}/extjs/builds"
system "cp #{@ext_dir}/builds/ext-core.js #{@out_dir}/extjs/builds/ext-core.js"
system "cp #{@ext_dir}/release-notes.html #{@out_dir}/extjs"
system "cp -r #{@ext_dir}/examples #{@out_dir}/extjs"
system "cp -r #{@ext_dir}/welcome #{@out_dir}/extjs"
end
def copy_animator_examples
system "mkdir -p #{@out_dir}/extjs"
system "cp -r #{@animator_dir}/docs/examples #{@out_dir}/extjs"
end
# Copy over Sencha Touch
def copy_touch2_build
system "cp -r #{@sdk_dir}/touch/build #{@out_dir}/touch"
end
def add_product_doc_urls
@options += [
"--body-html", <<-EOHTML
<script type="text/javascript">
Docs.otherProducts = [
{
text: 'Ext JS 4.0',
href: 'http://docs.sencha.com/ext-js/4-0'
},
{
text: 'Sencha Touch 2.0',
href: 'http://docs.sencha.com/touch/2-0'
},
{
text: 'Sencha Animator 1.0',
href: 'http://docs.sencha.com/animator/1-0'
}
];
</script>
EOHTML
]
end
def run
# Pass multiple arguments to system, so we'll take advantage of the built-in escaping
system(*["ruby", "bin/jsduck"].concat(@options))
end
end
# Run compass to generate CSS files
task :sass do
system "compass compile --quiet template/resources/sass"
end
desc "Updates JSB3 file for Docs app.\n"+
"Run this before every commit that changes JS dependencies."
task :jsb do
system("sencha", "create", "jsb", "-a", "template/build-js.html", "-p", "template/app.jsb3")
end
desc "Run JSDuck on Ext JS SDK (for internal use at Sencha)\n" +
"sdk - creates debug/development version\n" +
"sdk[export] - creates export version\n" +
"sdk[live] - create live version for deployment\n"
task :sdk, [:mode] => :sass do |t, args|
mode = args[:mode] || "debug"
throw "Unknown mode #{mode}" unless ["debug", "export", "live"].include?(mode)
compress if mode == "export" || mode == "live"
runner = JsDuckRunner.new
runner.add_sdk
runner.add_debug if mode == "debug"
runner.add_seo if mode == "debug" || mode == "live"
runner.add_sdk_export_notice if mode == "export"
runner.add_google_analytics if mode == "live"
runner.run
runner.copy_sdk_examples if mode == "export" || mode == "live"
end
desc "Run JSDuck on official Ext JS 4.0.2a build\n" +
"ext4 - creates debug/development version\n" +
"ext4[export] - creates export/deployable version\n"
task :ext4, [:mode] => :sass do |t, args|
mode = args[:mode] || "debug"
throw "Unknown mode #{mode}" unless ["debug", "export"].include?(mode)
compress if mode == "export"
runner = JsDuckRunner.new
runner.add_ext4
runner.add_debug if mode == "debug"
runner.add_seo
runner.run
end
desc "Run JSDuck on Sencha Touch (for internal use at Sencha)\n" +
"touch - creates debug/development version\n" +
"touch[live] - create live version for deployment\n"
task :touch, [:mode] => :sass do |t, args|
mode = args[:mode] || "debug"
throw "Unknown mode #{mode}" unless ["debug", "live"].include?(mode)
compress if mode == "live"
runner = JsDuckRunner.new
runner.add_touch
runner.add_debug if mode == "debug"
runner.add_seo if mode == "debug" || mode == "live"
runner.run
end
desc "Run JSDuck on Sencha Touch 2 (for internal use at Sencha)\n" +
"touch2 - creates debug/development version\n" +
"touch2[export] - creates export version\n" +
"touch2[live] - create live version for deployment\n"
task :touch2, [:mode] => :sass do |t, args|
mode = args[:mode] || "debug"
throw "Unknown mode #{mode}" unless ["debug", "export", "live"].include?(mode)
compress if mode == "live" || mode == "export"
runner = JsDuckRunner.new
runner.add_touch2
runner.add_debug if mode == "debug"
runner.add_touch2_export_notice if mode == "export"
runner.set_touch2_src if mode == "export"
runner.add_seo if mode == "debug" || mode == "live"
runner.add_product_doc_urls if mode == "live"
runner.run
runner.copy_touch2_build if mode != "export"
end
desc "Run JSDuck JSON Export (for internal use at Sencha)\n" +
"export[touch] - creates export for Touch 1\n" +
"export[touch2] - creates export for Touch 2"
task :export, [:mode] do |t, args|
mode = args[:mode]
throw "Unknown mode #{mode}" unless ["touch", "touch2"].include?(mode)
runner = JsDuckRunner.new
runner.add_touch_export if mode == "touch"
runner.add_touch2_export if mode == "touch2"
runner.run
end
desc "Run JSDuck on Sencha Animator (for internal use at Sencha)\n" +
"animator - creates debug/development version\n" +
"animator[export] - create live version for deployment\n"
"animator[live] - create live version for deployment\n"
task :animator, [:mode] => :sass do |t, args|
mode = args[:mode] || "debug"
throw "Unknown mode #{mode}" unless ["debug", "live", "export"].include?(mode)
compress if mode == "live"
runner = JsDuckRunner.new
runner.add_animator
runner.add_debug if mode == "debug"
runner.add_seo if mode == "debug" || mode == "live"
runner.run
runner.copy_animator_examples
end
desc "Build JSDuck gem"
task :gem => :sass do
compress
system "gem build jsduck.gemspec"
end
task :default => :spec