forked from nijikokun/minami
-
Notifications
You must be signed in to change notification settings - Fork 4
/
publish.js
884 lines (733 loc) · 25.5 KB
/
publish.js
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
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
/* global env: true */
'use strict';
var doop = require('jsdoc/util/doop');
var fs = require('jsdoc/fs');
var helper = require('jsdoc/util/templateHelper');
var logger = require('jsdoc/util/logger');
var parseMarkdown = require('jsdoc/util/markdown').getParser()
var path = require('jsdoc/path');
var taffy = require('taffydb').taffy;
var template = require('jsdoc/template');
var util = require('util');
var _ = require('lodash');
var catharsis = require('catharsis');
var htmlsafe = helper.htmlsafe;
var resolveAuthorLinks = helper.resolveAuthorLinks;
var hasOwnProp = Object.prototype.hasOwnProperty;
var data;
var view;
var outdir = path.normalize(env.opts.destination);
var sections = ['index', 'api', 'tutorials'];
var urls = {};
// These next two are lifted out of jsdoc3/util/templateHelper.js
function isComplexTypeExpression(expr) {
// record types, type unions, and type applications all count as "complex"
return /^{.+}$/.test(expr) || /^.+\|.+$/.test(expr) || /^.+<.+>$/.test(expr);
}
function parseType(longname) {
var err;
try {
return catharsis.parse(longname, {jsdoc: true});
}
catch (e) {
err = new Error('unable to parse ' + longname + ': ' + e.message);
logger.error(err);
return longname;
}
}
function headingId(heading) {
return _.kebabCase(heading.toLowerCase().replace(/[^a-z ]/g, ''));
}
function getHeadings(html, level) {
var result = [];
var regexString = util.format('<h%s>(.*)</h%s>', level, level);
var regex = new RegExp(regexString, 'gi');
html.replace(regex, function (whole, heading) {
result.push(heading);
return whole;
});
return result;
}
function addHeadingIds(html) {
return html.replace(/<h([0-9])>(.*?)<\/h[0-9]>/g, function(all, level, heading) {
return util.format(
'<h%s id="%s">%s</h%s>',
level, headingId(heading), heading, level
);
});
}
function formatType(type) {
switch (type.type) {
case 'NameExpression':
return linkto(type.name);
case 'UndefinedLiteral':
return 'undefined';
case 'NullLiteral':
return 'null';
case 'TypeApplication':
if (type.expression.name === 'Array') {
return util.format('%s[]', type.applications.map(formatType).join(''));
}
return util.format('%s<%s>', formatType(type.expression),type.applications.map(formatType).join(''));
case 'TypeUnion':
return type.elements.map(formatType).join('|');
default:
throw new Error('Unknown type: `' + type.type + '`\nProblematic type:\n' + util.inspect(type, {depth: 10}));
}
}
function generateTutorial(title, tutorial, filename) {
var tutorialData = {
type: 'tutorial',
title: title,
header: tutorial.title,
content: tutorial.parse(),
children: tutorial.children
};
var tutorialPath = path.join(outdir, filename);
var html = view.render('tutorial.tmpl', tutorialData);
html = helper.resolveLinks(html);
fs.writeFileSync(tutorialPath, html, 'utf8');
}
/**
* Recursively generate all tutorials starting with the base one.
*/
function generateTutorials(tutorial) {
tutorial.children.forEach(function(child) {
if (child.longname === 'index') return;
generateTutorial(child.title, child, helper.tutorialToUrl(child.name));
generateTutorials(child);
});
}
function tutoriallink(tutorial) {
return helper.toTutorial(tutorial, null, { tag: 'em', classname: 'disabled', prefix: 'Tutorial: ' });
}
function linkToTutorial(longName, name) {
return tutoriallink(name);
}
function createLink(doclet) {
var id = _.isString(doclet) ? doclet : elementId(doclet);
return util.format('%s#%s', urls.api, id);
}
function linkto() {
var target = arguments[0];
var display = arguments[1] || target;
if (isComplexTypeExpression(target) && !_.startsWith(target, '{@')) {
var parsed = parseType(target);
return formatType(parsed);
}
var doclet = find({longname: target})[0] || find({name: target})[0];
if (doclet) {
return util.format(
'<a href="%s">%s</a>',
createLink(doclet),
htmlsafe(display)
);
} else {
return helper.linkto.apply(helper, arguments);
}
}
function sectionId(doclet) {
return util.format('section-%s', elementId(doclet));
}
function subsectionId(doclet, subsection) {
return util.format('%s-subsection-%s', elementId(doclet), subsection);
}
function sectionLink(section) {
return createLink(sectionId(section));
}
function subsectionLink(doclet, subsection) {
return createLink(subsectionId(doclet, subsection));
}
function elementId(doclet) {
return (doclet.longname || doclet.name || '')
.replace('#event:', '-event-')
.replace('#', '-instance-')
.replace('.', '-static-')
.replace('"', '');
}
function find(spec) {
return helper.find(data, spec);
}
function simplifyEventName(namepath) {
var regex = /#(event:)?(.*)$/;
var matches = namepath.match(regex);
return matches[2] || namepath;
}
function formattedParent(data) {
var parent = data.memberof;
if (parent) {
return data.isStatic || data.kind === 'class' ? parent : _.camelCase(parent);
} else {
return '';
}
}
function getAncestorLinks(doclet) {
return helper.getAncestorLinks(data, doclet);
}
function hashToLink(doclet, hash) {
if (!/^(#.+)/.test(hash)) { return hash; }
var url = createLink(doclet).replace(/(#.+|$)/, hash);
return '<a href="' + url + '">' + hash + '</a>';
}
function isLodashMethod(doclet) {
return !!_.find(doclet.see, function(name) {
return _.includes(name, 'lodash.com');
});
}
function needsFunctionSignature(doclet) {
var needsSig = false;
// function and class definitions always get a signature
if (doclet.kind === 'function' || doclet.kind === 'class') {
needsSig = true;
}
// typedefs that contain functions get a signature, too
else if (doclet.kind === 'typedef' && doclet.type && doclet.type.names && doclet.type.names.length) {
for (var i = 0, l = doclet.type.names.length; i < l; i++) {
if (doclet.type.names[i].toLowerCase() === 'function') {
needsSig = true;
break;
}
}
}
return needsSig;
}
function needsEventSignature(doclet) {
return doclet.kind === 'event';
}
function getSignatureAttributes(item) {
var attributes = [];
if (item.nullable === true) {
attributes.push('nullable');
}
else if (item.nullable === false) {
attributes.push('non-null');
}
return attributes;
}
function updateItemName(item, options) {
options = _.extend({default: false}, options);
var attributes = getSignatureAttributes(item);
var itemName = item.name || '';
itemName = util.format('<span class="item-name">%s</span>', itemName);
// Prefix varargs parameter with ellipsis.
if (item.variable) {
itemName = '<span class="variable-ellipsis">…</span>' + itemName;
}
if (options.default && !_.isUndefined(item.defaultvalue)) {
itemName += '<span class="default-value"><span class="default-equals">=</span><span class="default-value">' +
item.defaultvalue + '</span></span>';
}
// Embracket optional param.
if (item.optional) {
itemName = '<span class="optional-bracket">[</span>' + itemName + '<span class="optional-bracket">]</span>';
}
if (attributes && attributes.length) {
itemName = util.format('%s<span class="signature-attributes">%s</span>', itemName, attributes.join(' '));
}
return itemName;
}
function addParamAttributes(params) {
return params.filter(function(param) {
return param.name && param.name.indexOf('.') === -1;
}).map(updateItemName);
}
function buildItemTypeStrings(item) {
var types = [];
if (item && item.type && item.type.names) {
item.type.names.forEach(function(name) {
types.push( linkto(name, htmlsafe(name)) );
});
}
return types;
}
function buildAttribsString(attribs) {
var attribsString = '';
if (attribs && attribs.length) {
attribsString = htmlsafe( util.format('(%s) ', attribs.join(', ')) );
}
return attribsString;
}
function addNonParamAttributes(items) {
var types = [];
items.forEach(function(item) {
types = types.concat( buildItemTypeStrings(item) );
});
return types;
}
function ensureQuotes(string) {
return string[0] === '"' ? string : util.format('"%s"', string);
}
function stripQuotes(string) {
return string.replace(/^"|"$/g, '');
}
function paren(isOpening) {
return '<span class="parenthesis">' + (isOpening ? '(' : ')') + '</span>';
}
function comma() {
return '<span class="comma">, </span>'
}
function parens(string) {
return paren(true) + string + paren(false);
}
function parameterList(params) {
params = params ? addParamAttributes(params) : [];
return parens(params.join(comma()));
}
function addEventSignature(doclet) {
doclet.signature = util.format(
'<span class="event-on">on</span>%s%s%s %s <span class="fat-arrow">=></span>',
paren(true),
linkto(doclet.longname, ensureQuotes(doclet.name)),
comma(),
parameterList(doclet.params)
);
}
function addSignatureName(doclet) {
var target = doclet.isLodashMethod ? doclet.see[0] : doclet.longname ;
doclet.signature = util.format('<span class="name">%s</span>%s', linkto(target, doclet.name), doclet.signature || '');
}
function addSignatureParams(f) {
f.signature = util.format('%s%s', f.signature, parameterList(f.params));
}
function addSignatureReturns(f) {
var attribs = [];
var attribsString = '';
var returnTypes = [];
var returnTypesString = '';
// jam all the return-type attributes into an array. this could create odd
// results (for example, if there are both nullable and non-nullable return
// types), but let's assume that most people who use multiple @return tags
// aren't using Closure Compiler type annotations, and vice-versa.
if (f.returns) {
f.returns.forEach(function(item) {
helper.getAttribs(item).forEach(function(attrib) {
if (attribs.indexOf(attrib) === -1) {
attribs.push(attrib);
}
});
});
attribsString = buildAttribsString(attribs);
}
if (f.returns) {
returnTypes = addNonParamAttributes(f.returns);
}
if (returnTypes.length) {
returnTypesString = util.format(
' → %s %s',
attribsString ? util.format('(%s)', attribsString) : '',
returnTypes.join('|')
);
}
f.signature = '<span class="parameters">' + (f.signature || '') + '</span><span class="type-signature">' +
returnTypesString + '</span>';
}
function addSignatureTypes(f) {
var types = f.type ? buildItemTypeStrings(f) : [];
f.signature = (f.signature || '') + '<span class="type-signature">' + (types.length ? ' :' + types.join('|') : '') +
'</span>';
}
function addAttribs(f) {
var attribs = helper.getAttribs(f);
// Manually assign `isStatic`.
f.isStatic = _.includes(attribs, 'static');
if (f.isStatic) _.pull(attribs, 'static');
// Remove `static` from list. TODO: Do this for all 'attributes'.
var attribsString = buildAttribsString(attribs);
f.attribs = util.format('<span class="type-signature">%s</span>', attribsString);
}
function shortenPaths(files, commonPrefix) {
Object.keys(files).forEach(function(file) {
// always use forward slashes
files[file].shortened = files[file].resolved.replace(commonPrefix, '').replace(/\\/g, '/');
});
return files;
}
function getPathFromDoclet(doclet) {
if (!doclet.meta) {
return null;
}
return doclet.meta.path && doclet.meta.path !== 'null' ?
path.join(doclet.meta.path, doclet.meta.filename) :
doclet.meta.filename;
}
function generateTutorialsIndex(title, tutorials, filename) {
var outpath = path.join(outdir, filename);
var indexTutorial = tutorials.children.find(function(tutorial) {
return tutorial.longname === 'index';
});
var html = view.render('tutorials.tmpl', {
title: title || '',
type: 'tutorial',
tutorialsIndex: buildTutorialsNav(tutorials.children),
text: indexTutorial && indexTutorial.parse()
});
fs.writeFileSync(outpath, html, 'utf8');
}
function generate(type, title, docs, filename, resolveLinks) {
var docData = {
type: type,
title: title,
docs: docs
};
var outpath = path.join(outdir, filename)
var html = view.render('container.tmpl', docData);
if (resolveLinks !== false) {
html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
}
fs.writeFileSync(outpath, html, 'utf8');
}
function generateSourceFiles(sourceFiles, encoding) {
encoding = encoding || 'utf8';
Object.keys(sourceFiles).forEach(function(file) {
var source;
// links are keyed to the shortened path in each doclet's `meta.shortpath` property
var sourceOutfile = path.join(helper.getUniqueFilename(sourceFiles[file].shortened));
helper.registerLink(sourceFiles[file].shortened, sourceOutfile);
try {
source = {
kind: 'source',
code: helper.htmlsafe( fs.readFileSync(sourceFiles[file].resolved, encoding) )
};
}
catch(e) {
logger.error('Error while generating source file %s: %s', file, e.message);
}
generate('source', sourceFiles[file].shortened, [source], sourceOutfile, false);
});
}
/**
* Look for classes or functions with the same name as modules (which indicates that the module
* exports only that class or function), then attach the classes or functions to the `module`
* property of the appropriate module doclets. The name of each class or function is also updated
* for display purposes. This function mutates the original arrays.
*
* @private
* @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
* check.
* @param {Array.<module:jsdoc/doclet.Doclet>} modules - The array of module doclets to search.
*/
function attachModuleSymbols(doclets, modules) {
var symbols = {};
// build a lookup table
doclets.forEach(function(symbol) {
symbols[symbol.longname] = symbols[symbol.longname] || [];
symbols[symbol.longname].push(symbol);
});
return modules.map(function(module) {
if (symbols[module.longname]) {
module.modules = symbols[module.longname].filter(function(symbol) {
// Only show symbols that have a description. Make an exception for classes, because
// we want to show the constructor-signature heading no matter what.
return symbol.description || symbol.kind === 'class';
}).map(function(symbol) {
symbol = doop(symbol);
if (symbol.kind === 'class' || symbol.kind === 'function') {
symbol.name = symbol.name.replace('module:', '(require("') + '"))';
}
return symbol;
});
}
});
}
function buildSubsectionLink(doclet, subsection, title) {
return util.format(
'<h4><a href="%s">%s</a></h4>',
subsectionLink(doclet, subsection),
title
);
}
function buildNavItemList(items, className, linktoFn) {
var listItems = items.map(function (item) {
return '<li>' + linktoFn(item.longname, stripQuotes(item.title || item.name)) + '</li>';
});
return util.format('<ul class="%s">%s</ul>', className || '', listItems.join(''));
}
function buildTutorialsNav(tutorials) {
var listItems = tutorials.reduce(function(html, tutorial) {
if (tutorial.longname === 'index') return html;
var result = linkToTutorial(null, tutorial.longname);
if (tutorial.children) result += buildTutorialsNav(tutorial.children);
return html + '<li>' + result + '</li>';
}, '');
return util.format('<ul class="tutorials">%s</ul>', listItems);
}
function buildReadmeNav(readme) {
var headings = getHeadings(readme, 2);
var items = headings.map(function(heading) {
return util.format('<li><a href="#%s">%s</a></li>', headingId(heading), heading);
}).join('\n');
return items;
}
function buildChangelogNav() {
return '<li><a href="#changelog">Change log</a></li>';
}
function buildMemberNav(item) {
var itemsNav = '';
var statics = find({kind:'function', isStatic: true, memberof: item.longname});
var members = find({kind:'member', memberof: item.longname});
var methods = find({
kind:'function',
isInitialize: false,
isLodashMethod: false,
isStatic: false,
memberof: item.longname
});
var lodash = find({kind:'function', isLodashMethod: true, memberof: item.longname});
var events = find({kind:'event', memberof: item.longname});
var classes = find({kind:'class', memberof: item.longname});
var initialize = find({
kind: 'function',
isInitialize: true,
isLodashMethod: false,
isStatic: false,
memberof: item.longname
});
if (!hasOwnProp.call(item, 'longname')) {
itemsNav += '<li>' + linkto('', item.name) + '</li>';
}
else {
itemsNav += '<li>';
itemsNav += util.format('<h3><a href="%s">%s</a></h3>', sectionLink(item), item.name.replace(/^module:/, ''));
itemsNav += buildSubsectionLink(item, 'construction', 'Construction');
itemsNav += buildNavItemList([item].concat(initialize), 'construction', linkto);
if (statics.length) {
itemsNav += buildSubsectionLink(item, 'static', 'Static');
itemsNav += buildNavItemList(statics, 'static', linkto);
}
if (members.length) {
itemsNav += buildSubsectionLink(item, 'members', 'Members');
itemsNav += buildNavItemList(members, 'members', linkto);
}
if (methods.length) {
itemsNav += buildSubsectionLink(item, 'methods', 'Methods');
itemsNav += buildNavItemList(methods, 'methods', linkto);
}
if (lodash.length) {
itemsNav += buildSubsectionLink(item, 'lodash-methods', 'Lodash Methods');
itemsNav += buildNavItemList(lodash, 'lodash-methods', linkto);
}
if (events.length) {
itemsNav += buildSubsectionLink(item, 'events', 'Events');
itemsNav += buildNavItemList(events, 'events', linkto);
}
itemsNav += '</li>';
}
itemsNav += classes.map(buildMemberNav).join('');
return itemsNav;
}
function buildMemberNavs(items) {
if (!items.length) return '';
var navItems = items.map(buildMemberNav).join('');
return util.format('<ul>%s</ul>', navItems);
}
/**
* Create the navigation sidebar for the home page.
*
* @param {object} readme The readme file in the project.
* @return {string} The HTML for the navigation sidebar.
*/
function buildIndexNav(readme) {
var nav = '';
nav += buildReadmeNav(readme);
nav += buildChangelogNav();
return util.format('<h2>Home</h2><ul>%s</ul>', nav);
}
/**
@param {TAFFY} taffyData See <http://taffydb.com/>.
@param {object} opts
@param {Tutorial} tutorials
*/
exports.publish = function(taffyData, opts, tutorials) {
var conf = env.conf.templates || {};
var templatePath = path.normalize(opts.template);
var sourceFiles = {};
var sourceFilePaths = [];
data = helper.prune(taffyData);
conf.default = conf.default || {};
view = new template.Template(path.join(templatePath, 'tmpl'));
view.layout = conf.default.layoutFile ?
path.getResourcePath(path.dirname(conf.default.layoutFile), path.basename(conf.default.layoutFile)) :
'layout.tmpl';
sections.forEach(function(section) {
urls[section] = helper.getUniqueFilename(section);
helper.registerLink(section, urls[section]);
});
helper.setTutorials(tutorials);
helper.addEventListeners(data);
data.sort('longname, version, since');
data().each(function(doclet) {
doclet.attribs = '';
// Identify Lodash methods to be stubbed.
doclet.isLodashMethod = isLodashMethod(doclet);
doclet.isInitialize = doclet.name == 'initialize';
if (doclet.examples) {
doclet.examples = doclet.examples.map(function(example) {
var caption, code;
if (example.match(/^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i)) {
caption = RegExp.$1;
code = RegExp.$3;
}
return {
caption: caption || '',
code: code || example
};
});
}
if (doclet.see) {
doclet.see.forEach(function(seeItem, i) {
doclet.see[i] = hashToLink(doclet, seeItem);
});
}
// build a list of source files
var sourcePath;
if (doclet.meta) {
sourcePath = getPathFromDoclet(doclet);
sourceFiles[sourcePath] = {
resolved: sourcePath,
shortened: null
};
if (sourceFilePaths.indexOf(sourcePath) === -1) {
sourceFilePaths.push(sourcePath);
}
}
});
// update outdir if necessary, then create outdir
var packageInfo = (find({kind: 'package'}) || [])[0];
if (packageInfo && packageInfo.name) {
outdir = path.join(outdir, packageInfo.name, (packageInfo.version || ''));
}
fs.mkPath(outdir);
// copy the template's static files to outdir
var fromDir = path.join(templatePath, 'static');
var staticFiles = fs.ls(fromDir, 3);
staticFiles.forEach(function(fileName) {
var toDir = fs.toDir(fileName.replace(fromDir, outdir));
fs.mkPath(toDir);
fs.copyFileSync(fileName, toDir);
});
// copy user-specified static files to outdir
var staticFilePaths;
var staticFileFilter;
var staticFileScanner;
if (conf.default.staticFiles) {
// The canonical property name is `include`. We accept `paths` for backwards compatibility
// with a bug in JSDoc 3.2.x.
staticFilePaths = conf.default.staticFiles.include || conf.default.staticFiles.paths || [];
staticFileFilter = new (require('jsdoc/src/filter')).Filter(conf.default.staticFiles);
staticFileScanner = new (require('jsdoc/src/scanner')).Scanner();
staticFilePaths.forEach(function(filePath) {
var extraStaticFiles = staticFileScanner.scan([filePath], 10, staticFileFilter);
extraStaticFiles.forEach(function(fileName) {
var sourcePath = fs.toDir(filePath);
var toDir = fs.toDir(fileName.replace(sourcePath, outdir));
fs.mkPath(toDir);
fs.copyFileSync(fileName, toDir);
});
});
}
if (sourceFilePaths.length) {
sourceFiles = shortenPaths(sourceFiles, path.commonPrefix(sourceFilePaths));
}
data().each(function(doclet) {
var url = createLink(doclet);
helper.registerLink(doclet.longname, url);
// add a shortened version of the full path
var docletPath;
if (doclet.meta) {
docletPath = sourceFiles[getPathFromDoclet(doclet)].shortened;
if (docletPath) {
doclet.meta.shortpath = docletPath;
}
}
});
data().each(function(doclet) {
doclet.id = elementId(doclet);
if (needsFunctionSignature(doclet)) {
addSignatureName(doclet);
addSignatureParams(doclet);
addSignatureReturns(doclet);
addAttribs(doclet);
}
else if (needsEventSignature(doclet)) {
addEventSignature(doclet);
}
});
// do this after the urls have all been generated
data().each(function(doclet) {
doclet.ancestors = getAncestorLinks(doclet);
if (doclet.kind === 'member') {
addSignatureName(doclet);
addSignatureTypes(doclet);
addAttribs(doclet);
}
if (doclet.kind === 'constant') {
addSignatureTypes(doclet);
addAttribs(doclet);
doclet.kind = 'member';
}
});
var members = helper.getMembers(data);
members.tutorials = tutorials.children;
// set up the lists that we'll use to generate pages
var classes = taffy(members.classes);
var topLevelClasses = helper.find(classes, {memberof: {isUndefined: true}});
var whitelist = opts.whitelist;
if (whitelist) {
topLevelClasses = whitelist.map(function(longname) {
var result = _.find(topLevelClasses, {longname: longname});
if (!result) throw new Error('White listed class `' + longname + '` not found');
return result;
});
}
// output pretty-printed source files by default
var outputSourceFiles = conf.default && conf.default.outputSourceFiles !== false;
var showInheritedFrom = conf.default && conf.default.showInheritedFrom !== false;
// add template helpers
view.find = find;
view.hasReference = topLevelClasses.length;
view.hasTutorials = members.tutorials.length;
view.linkto = linkto;
view.updateItemName = updateItemName;
view.elementId = elementId;
view.sectionId = sectionId;
view.subsectionId = subsectionId;
view.simplifyEventName = simplifyEventName;
view.formattedParent = formattedParent;
view.resolveAuthorLinks = resolveAuthorLinks;
view.htmlsafe = htmlsafe;
view.outputSourceFiles = outputSourceFiles;
view.showInheritedFrom = showInheritedFrom;
view.generateTutorial = generateTutorial;
view.projectTitle = opts.title;
view.indexSidenav = buildIndexNav(opts.readme);
view.indexTitle = opts.mainPageTitle || 'Home';
view.apiSidenav = buildMemberNavs(topLevelClasses);
view.apiTitle = opts.apiTitle || 'API Reference';
view.tutorialsSidenav = buildTutorialsNav(members.tutorials);
view.tutorialsTitle = opts.tutorialsTitle || 'Tutorials';
view.tutoriallink = tutoriallink;
view.showGeneratedDate = conf.default && conf.default.includeDate !== false;
attachModuleSymbols(find({longname: {left: 'module:'}}), members.modules);
// generate the pretty-printed source files first so other pages can link to them
if (outputSourceFiles) {
generateSourceFiles(sourceFiles, opts.encoding);
}
if (view.hasReference) {
generate('api', view.apiTitle, topLevelClasses, urls.api);
}
if (view.hasTutorials) {
generateTutorialsIndex(opts.tutorialsTitle, tutorials, urls.tutorials);
generateTutorials(tutorials);
}
// index page displays information from package.json and lists files
var files = find({kind: 'file'});
var packages = find({kind: 'package'});
var rawChangelog = opts.changelog ? fs.readFileSync(opts.changelog, opts.encoding) : '';
var readme = [{
kind: 'mainpage',
readme: addHeadingIds(opts.readme)
}];
var changelog = {kind: 'mainpage', changelog: parseMarkdown(rawChangelog)};
var home = packages.concat(readme, files, changelog);
generate('index', view.indexTitle, home, urls.index);
};