clean-jsdoc-theme 4.3.0 → 5.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +117 -625
  2. package/dist/publish.d.mts +218 -0
  3. package/dist/publish.d.ts +218 -0
  4. package/dist/publish.js +641 -0
  5. package/dist/publish.js.map +1 -0
  6. package/dist/publish.mjs +605 -0
  7. package/dist/publish.mjs.map +1 -0
  8. package/package.json +65 -55
  9. package/.eslintignore +0 -5
  10. package/.eslintrc.js +0 -3
  11. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -43
  12. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -27
  13. package/.github/dependabot.yml +0 -9
  14. package/.github/pull_request_template.md +0 -16
  15. package/.github/workflows/codeql.yml +0 -72
  16. package/.github/workflows/greetings.yml +0 -16
  17. package/.prettierignore +0 -2
  18. package/.prettierrc +0 -5
  19. package/.stylelintignore +0 -4
  20. package/.stylelintrc +0 -18
  21. package/.travis.yml +0 -30
  22. package/CHANGELOG.md +0 -260
  23. package/CODE_OF_CONDUCT.md +0 -76
  24. package/CODE_OF_CONDUCT_HINDI.md +0 -61
  25. package/CONTRIBUTING.md +0 -36
  26. package/LICENSE +0 -21
  27. package/SECURITY.md +0 -21
  28. package/clean-jsdoc-theme-defaults.js +0 -37
  29. package/clean-jsdoc-theme-helper.js +0 -186
  30. package/css-property-order-fix.js +0 -56
  31. package/helpers/Environment.html +0 -3
  32. package/helpers/down-arrow.js +0 -9
  33. package/jsdoc-config.json +0 -102
  34. package/minify.js +0 -72
  35. package/publish.js +0 -1104
  36. package/static/fonts/Inconsolata-Regular.ttf +0 -0
  37. package/static/fonts/OpenSans-Regular.ttf +0 -0
  38. package/static/fonts/WorkSans-Bold.ttf +0 -0
  39. package/static/scripts/core.js +0 -726
  40. package/static/scripts/core.min.js +0 -23
  41. package/static/scripts/resize.js +0 -90
  42. package/static/scripts/search.js +0 -265
  43. package/static/scripts/search.min.js +0 -6
  44. package/static/scripts/third-party/Apache-License-2.0.txt +0 -202
  45. package/static/scripts/third-party/fuse.js +0 -9
  46. package/static/scripts/third-party/hljs-line-num-original.js +0 -369
  47. package/static/scripts/third-party/hljs-line-num.js +0 -1
  48. package/static/scripts/third-party/hljs-original.js +0 -5171
  49. package/static/scripts/third-party/hljs.js +0 -1
  50. package/static/scripts/third-party/popper.js +0 -5
  51. package/static/scripts/third-party/tippy.js +0 -1
  52. package/static/scripts/third-party/tocbot.js +0 -672
  53. package/static/scripts/third-party/tocbot.min.js +0 -1
  54. package/static/styles/clean-jsdoc-theme-base.css +0 -1159
  55. package/static/styles/clean-jsdoc-theme-dark.css +0 -412
  56. package/static/styles/clean-jsdoc-theme-light.css +0 -482
  57. package/static/styles/clean-jsdoc-theme-scrollbar.css +0 -30
  58. package/static/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -1
  59. package/static/styles/clean-jsdoc-theme.min.css +0 -1
  60. package/tmpl/augments.tmpl +0 -10
  61. package/tmpl/container.tmpl +0 -208
  62. package/tmpl/details.tmpl +0 -207
  63. package/tmpl/example.tmpl +0 -3
  64. package/tmpl/examples.tmpl +0 -48
  65. package/tmpl/exceptions.tmpl +0 -32
  66. package/tmpl/icons.tmpl +0 -73
  67. package/tmpl/include-target-script-and-styles.tmpl +0 -43
  68. package/tmpl/layout.tmpl +0 -167
  69. package/tmpl/mainpage.tmpl +0 -10
  70. package/tmpl/members.tmpl +0 -42
  71. package/tmpl/method.tmpl +0 -175
  72. package/tmpl/mobile-sidebar.tmpl +0 -21
  73. package/tmpl/navbar-actions.tmpl +0 -19
  74. package/tmpl/navbar-menu.tmpl +0 -25
  75. package/tmpl/navbar.tmpl +0 -14
  76. package/tmpl/params.tmpl +0 -131
  77. package/tmpl/properties.tmpl +0 -109
  78. package/tmpl/returns.tmpl +0 -19
  79. package/tmpl/search.tmpl +0 -17
  80. package/tmpl/sidebar-items.tmpl +0 -24
  81. package/tmpl/sidebar-title.tmpl +0 -8
  82. package/tmpl/sidebar.tmpl +0 -9
  83. package/tmpl/source.tmpl +0 -13
  84. package/tmpl/toc.tmpl +0 -4
  85. package/tmpl/tutorial.tmpl +0 -32
  86. package/tmpl/type.tmpl +0 -13
package/publish.js DELETED
@@ -1,1104 +0,0 @@
1
- const _ = require('lodash');
2
- const env = require('jsdoc/env');
3
- const fs = require('fs-extra');
4
- const helper = require('jsdoc/util/templateHelper');
5
- const logger = require('jsdoc/util/logger');
6
- const path = require('jsdoc/path');
7
- const { taffy } = require('@jsdoc/salty');
8
- const template = require('jsdoc/template');
9
- const htmlMinify = require('html-minifier-terser');
10
-
11
- const {
12
- buildFooter,
13
- codepen,
14
- createDynamicStyleSheet,
15
- createDynamicsScripts,
16
- getBaseURL,
17
- getFavicon,
18
- getMetaTagData,
19
- getTheme,
20
- includeCss,
21
- includeScript,
22
- moduleHeader,
23
- resizeable,
24
- returnPathOfScriptScr,
25
- returnPathOfStyleSrc,
26
- copyStaticFolder,
27
- getProcessedYield,
28
- lsSync,
29
- } = require('./clean-jsdoc-theme-helper');
30
-
31
- const {
32
- HTML_MINIFY_OPTIONS,
33
- SECTION_TYPE,
34
- defaultSections,
35
- } = require('./clean-jsdoc-theme-defaults');
36
-
37
- const htmlsafe = helper.htmlsafe;
38
- const linkto = helper.linkto;
39
- const resolveAuthorLinks = helper.resolveAuthorLinks;
40
- const hasOwnProp = Object.prototype.hasOwnProperty;
41
-
42
- const themeOpts = (env && env.opts && env.opts.theme_opts) || {};
43
-
44
- let data;
45
- let view;
46
- /**
47
- * @type {Array<{title: string, link: string, description: string}>}
48
- */
49
- const searchList = [];
50
- const hasSearch =
51
- themeOpts.search === undefined ? true : Boolean(themeOpts.search);
52
-
53
- // eslint-disable-next-line no-restricted-globals
54
- let outdir = path.resolve(path.normalize(env.opts.destination));
55
-
56
- function mkdirSync(filepath) {
57
- return fs.mkdirSync(filepath, { recursive: true });
58
- }
59
-
60
- function sourceToDestination(parentDir, sourcePath, destDir) {
61
- const relativeSource = path.relative(parentDir, sourcePath);
62
-
63
- return path.resolve(path.join(destDir, relativeSource));
64
- }
65
-
66
- function find(spec) {
67
- return helper.find(data, spec);
68
- }
69
-
70
- function tutoriallink(tutorial) {
71
- return helper.toTutorial(tutorial, null, {
72
- tag: 'em',
73
- classname: 'disabled',
74
- prefix: 'Tutorial: ',
75
- });
76
- }
77
-
78
- function getAncestorLinks(doclet) {
79
- return helper.getAncestorLinks(data, doclet);
80
- }
81
-
82
- function hashToLink(doclet, hash, dependencies) {
83
- let url;
84
-
85
- if (!/^(#.+)/.test(hash)) {
86
- return hash;
87
- }
88
-
89
- url = helper.createLink(doclet, dependencies);
90
- url = url.replace(/(#.+|$)/, hash);
91
-
92
- return `<a href="${url}">${hash}</a>`;
93
- }
94
-
95
- function needsSignature({ kind, type, meta }) {
96
- let needsSig = false;
97
-
98
- // function and class definitions always get a signature
99
- if (kind === 'function' || kind === 'class') {
100
- needsSig = true;
101
- }
102
-
103
- // typedefs that contain functions get a signature, too
104
- else if (kind === 'typedef' && type && type.names && type.names.length) {
105
- for (let i = 0, l = type.names.length; i < l; i++) {
106
- if (type.names[i].toLowerCase() === 'function') {
107
- needsSig = true;
108
- break;
109
- }
110
- }
111
- }
112
-
113
- // and namespaces that are functions get a signature (but finding them is a
114
- // bit messy)
115
- else if (
116
- kind === 'namespace' &&
117
- meta &&
118
- meta.code &&
119
- meta.code.type &&
120
- meta.code.type.match(/[Ff]unction/)
121
- ) {
122
- needsSig = true;
123
- }
124
-
125
- return needsSig;
126
- }
127
-
128
- function getSignatureAttributes({ optional, nullable }) {
129
- const attributes = [];
130
-
131
- if (optional) {
132
- attributes.push('opt');
133
- }
134
-
135
- if (nullable === true) {
136
- attributes.push('nullable');
137
- } else if (nullable === false) {
138
- attributes.push('non-null');
139
- }
140
-
141
- return attributes;
142
- }
143
-
144
- function updateItemName(item) {
145
- const attributes = getSignatureAttributes(item);
146
- let itemName = item.name || '';
147
-
148
- if (item.variable) {
149
- itemName = '&hellip;' + itemName;
150
- }
151
-
152
- if (attributes && attributes.length) {
153
- itemName = `${itemName}<span class="signature-attributes">${attributes.join(
154
- ', '
155
- )}</span>`;
156
- }
157
-
158
- return itemName;
159
- }
160
-
161
- function addParamAttributes(params) {
162
- return params
163
- .filter(({ name }) => name && !name.includes('.'))
164
- .map(updateItemName);
165
- }
166
-
167
- function buildItemTypeStrings(item) {
168
- const types = [];
169
-
170
- if (item && item.type && item.type.names) {
171
- item.type.names.forEach(function (name) {
172
- types.push(linkto(name, htmlsafe(name)));
173
- });
174
- }
175
-
176
- return types;
177
- }
178
-
179
- function buildAttribsString(attribs) {
180
- let attribsString = '';
181
-
182
- if (attribs && attribs.length) {
183
- attribsString = htmlsafe(`(${attribs.join(', ')}) `);
184
- }
185
-
186
- return attribsString;
187
- }
188
-
189
- function addNonParamAttributes(items) {
190
- let types = [];
191
-
192
- items.forEach(function (item) {
193
- types = types.concat(buildItemTypeStrings(item));
194
- });
195
-
196
- return types;
197
- }
198
-
199
- function addSignatureParams(f) {
200
- const params = f.params ? addParamAttributes(f.params) : [];
201
-
202
- f.signature = `${f.signature || ''}(${params.join(', ')})`;
203
- }
204
-
205
- function addSignatureReturns(f) {
206
- const attribs = [];
207
- let attribsString = '';
208
- let returnTypes = [];
209
- let returnTypesString = '';
210
- const source = f.yields || f.returns;
211
-
212
- // jam all the return-type attributes into an array. this could create odd results (for example,
213
- // if there are both nullable and non-nullable return types), but let's assume that most people
214
- // who use multiple @return tags aren't using Closure Compiler type annotations, and vice-versa.
215
- if (source) {
216
- source.forEach((item) => {
217
- helper.getAttribs(item).forEach((attrib) => {
218
- if (!attribs.includes(attrib)) {
219
- attribs.push(attrib);
220
- }
221
- });
222
- });
223
-
224
- attribsString = buildAttribsString(attribs);
225
- }
226
-
227
- if (source) {
228
- returnTypes = addNonParamAttributes(source);
229
- }
230
- if (returnTypes.length) {
231
- returnTypesString = ` &rarr; ${attribsString}{${returnTypes.join(
232
- '|'
233
- )}}`;
234
- }
235
-
236
- let signatureOutput = '';
237
-
238
- if (f.signature) {
239
- signatureOutput =
240
- '<span class="signature">' + (f.signature || '') + '</span>';
241
- }
242
- if (returnTypesString) {
243
- signatureOutput +=
244
- '<span class="type-signature">' + returnTypesString + '</span>';
245
- }
246
-
247
- f.signature = signatureOutput;
248
- }
249
-
250
- function addSignatureTypes(f) {
251
- const types = f.type ? buildItemTypeStrings(f) : [];
252
-
253
- f.signature =
254
- `${f.signature || ''}<span class="type-signature">` +
255
- `${types.length ? ` :${types.join('|')}` : ''}</span>`;
256
- }
257
-
258
- function addAttribs(f) {
259
- const attribs = helper.getAttribs(f);
260
- const attribsString = buildAttribsString(attribs);
261
-
262
- f.attribs = `<span class="type-signature">${attribsString}</span>`;
263
- }
264
-
265
- function shortenPaths(files, commonPrefix) {
266
- Object.keys(files).forEach(function (file) {
267
- files[file].shortened = files[file].resolved
268
- .replace(commonPrefix, '')
269
- // always use forward slashes
270
- .replace(/\\/g, '/');
271
- });
272
-
273
- return files;
274
- }
275
-
276
- function getPathFromDoclet({ meta }) {
277
- if (!meta) {
278
- return null;
279
- }
280
-
281
- return meta.path && meta.path !== 'null'
282
- ? path.join(meta.path, meta.filename)
283
- : meta.filename;
284
- }
285
-
286
- function createPrettyAnchor(elementType, ancestor, name, href) {
287
- return `<${elementType} ${href ? `href="${href}"` : ''} class="has-anchor">
288
- <span class="ancestors">
289
- ${ancestor}~
290
- </span>
291
- ${name}
292
- </${elementType}>`;
293
- }
294
-
295
- function prefixModuleToItemAnchor(item) {
296
- let { anchor } = item;
297
-
298
- let anchorLink = anchor.split('href="')[1].split('"')[0];
299
- let cleanLink = anchorLink.replace(/\.html$/, '');
300
-
301
- let prettyAnchor;
302
-
303
- cleanLink.replace(
304
- /module-([^-]+)(?:-|\.)(.*)/,
305
- (_match, modulename, methodname) => {
306
- prettyAnchor = createPrettyAnchor(
307
- 'a',
308
- modulename,
309
- methodname,
310
- anchorLink
311
- );
312
- }
313
- );
314
-
315
- return prettyAnchor || anchor;
316
- }
317
-
318
- async function generate(title, docs, filename, resolveLinks) {
319
- let docData;
320
- let html;
321
- let outpath;
322
-
323
- docData = {
324
- env: env,
325
- title: title,
326
- docs: docs,
327
- filename,
328
- };
329
-
330
- outpath = path.join(outdir, filename);
331
- html = view.render('container.tmpl', docData);
332
-
333
- if (resolveLinks !== false) {
334
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
335
- }
336
-
337
- const minifiedHtml = await htmlMinify.minify(html, HTML_MINIFY_OPTIONS);
338
-
339
- fs.writeFileSync(outpath, minifiedHtml, 'utf8');
340
- }
341
-
342
- function generateSourceFiles(sourceFiles, encoding = 'utf8') {
343
- Object.keys(sourceFiles).forEach(function (file) {
344
- let source;
345
- // links are keyed to the shortened path in each doclet's `meta.shortpath` property
346
- const sourceOutFile = helper.getUniqueFilename(
347
- sourceFiles[file].shortened
348
- );
349
-
350
- helper.registerLink(sourceFiles[file].shortened, sourceOutFile);
351
-
352
- try {
353
- source = {
354
- kind: 'source',
355
- title: sourceOutFile.replace('.html', ''),
356
- code: helper.htmlsafe(
357
- fs.readFileSync(sourceFiles[file].resolved, encoding)
358
- ),
359
- };
360
- } catch (e) {
361
- logger.error(
362
- 'Error while generating source file %s: %s',
363
- file,
364
- e.message
365
- );
366
- }
367
-
368
- generate(
369
- `Source: ${sourceFiles[file].shortened}`,
370
- [source],
371
- sourceOutFile,
372
- false
373
- );
374
- });
375
- }
376
-
377
- /**
378
- * Look for classes or functions with the same name as modules (which indicates that the module
379
- * exports only that class or function), then attach the classes or functions to the `module`
380
- * property of the appropriate module doclets. The name of each class or function is also updated
381
- * for display purposes. This function mutates the original arrays.
382
- *
383
- * @private
384
- * @param {Array.<module:jsdoc/doclet.Doclet>} doclets - The array of classes and functions to
385
- * check.
386
- * @param {Array.<module:jsdoc/doclet.Doclet>} modules - The array of module doclets to search.
387
- */
388
- function attachModuleSymbols(doclets, modules) {
389
- const symbols = {};
390
-
391
- // build a lookup table
392
- doclets.forEach((symbol) => {
393
- symbols[symbol.longname] = symbols[symbol.longname] || [];
394
- symbols[symbol.longname].push(symbol);
395
- });
396
-
397
- modules.forEach((module) => {
398
- if (symbols[module.longname]) {
399
- module.modules = symbols[module.longname]
400
- // Only show symbols that have a description. Make an exception for classes, because
401
- // we want to show the constructor-signature heading no matter what.
402
- .filter(
403
- ({ description, kind }) => description || kind === 'class'
404
- )
405
- .map((symbol) => {
406
- symbol = _.cloneDeep(symbol);
407
-
408
- if (symbol.kind === 'class' || symbol.kind === 'function') {
409
- symbol.name = `${symbol.name.replace(
410
- 'module:',
411
- '(require("'
412
- )}"))`;
413
- }
414
-
415
- return symbol;
416
- });
417
- }
418
- });
419
- }
420
-
421
- function buildSidebarMembers({
422
- items,
423
- itemHeading,
424
- itemsSeen,
425
- linktoFn,
426
- sectionName,
427
- }) {
428
- const navProps = {
429
- name: itemHeading,
430
- items: [],
431
- id: `sidebar-${itemHeading.toLowerCase()}`,
432
- };
433
-
434
- if (items.length) {
435
- items.forEach(function (item) {
436
- const currentItem = {
437
- name: item.name,
438
- anchor: item.longname
439
- ? linktoFn(item.longname, item.name)
440
- : linktoFn('', item.name),
441
- children: [],
442
- };
443
-
444
- const methods =
445
- sectionName === SECTION_TYPE.Tutorials ||
446
- sectionName === SECTION_TYPE.Global
447
- ? []
448
- : find({
449
- kind: 'function',
450
- memberof: item.longname,
451
- inherited: {
452
- '!is': Boolean(themeOpts.exclude_inherited),
453
- },
454
- });
455
-
456
- if (!hasOwnProp.call(itemsSeen, item.longname)) {
457
- currentItem.anchor = linktoFn(
458
- item.longname,
459
- item.name.replace(/^module:/, '')
460
- );
461
-
462
- if (methods.length) {
463
- methods.forEach(function (method) {
464
- const itemChild = {
465
- name: method.longName,
466
- link: linktoFn(method.longname, method.name),
467
- };
468
-
469
- currentItem.children.push(itemChild);
470
- });
471
- }
472
- itemsSeen[item.longname] = true;
473
- }
474
-
475
- navProps.items.push(currentItem);
476
- });
477
- }
478
-
479
- return navProps;
480
- }
481
-
482
- function buildSearchListForData() {
483
- data().each((item) => {
484
- if (item.kind !== 'package' && !item.inherited) {
485
- searchList.push({
486
- title: item.longname,
487
- link: linkto(item.longname, item.name),
488
- description: item.description,
489
- });
490
- }
491
- });
492
- }
493
-
494
- function linktoTutorial(longName, name) {
495
- return tutoriallink(name);
496
- }
497
-
498
- function linktoExternal(longName, name) {
499
- return linkto(longName, name.replace(/(^"|"$)/g, ''));
500
- }
501
-
502
- /**
503
- * This function is added by clean-jsdoc-theme devs
504
- * This function is added by clean-jsdoc-theme devs
505
- * This function is added by clean-jsdoc-theme devs
506
- *
507
- */
508
- function buildNavbar() {
509
- return {
510
- menu: themeOpts.menu || undefined,
511
- search: hasSearch,
512
- };
513
- }
514
-
515
- /**
516
- * This function is added by clean-jsdoc-theme devs
517
- * This function is added by clean-jsdoc-theme devs
518
- * This function is added by clean-jsdoc-theme devs
519
- *
520
- * @param {object} members The members that will be used to create the sidebar.
521
- * @param {array<object>} members.classes
522
- * @param {array<object>} members.externals
523
- * @param {array<object>} members.globals
524
- * @param {array<object>} members.mixins
525
- * @param {array<object>} members.modules
526
- * @param {array<object>} members.namespaces
527
- * @param {array<object>} members.tutorials
528
- * @param {array<object>} members.events
529
- * @param {array<object>} members.interfaces
530
- * @return {string} The HTML for the navigation sidebar.
531
- */
532
- function buildSidebar(members) {
533
- const title = themeOpts.title;
534
-
535
- const isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);
536
-
537
- const nav = {
538
- sections: [],
539
- };
540
-
541
- if (!isHTML(title)) {
542
- nav.title = {
543
- title,
544
- isHTML: false,
545
- };
546
- } else {
547
- nav.title = {
548
- title,
549
- isHTML: true,
550
- };
551
- }
552
-
553
- const seen = {};
554
- const seenTutorials = {};
555
- const seenGlobal = {};
556
-
557
- const sectionsOrder = themeOpts.sections || defaultSections;
558
-
559
- const sections = {
560
- [SECTION_TYPE.Modules]: buildSidebarMembers({
561
- itemHeading: 'Modules',
562
- items: members.modules,
563
- itemsSeen: seen,
564
- linktoFn: linkto,
565
- sectionName: SECTION_TYPE.Modules,
566
- }),
567
-
568
- [SECTION_TYPE.Classes]: buildSidebarMembers({
569
- itemHeading: 'Classes',
570
- items: members.classes,
571
- itemsSeen: seen,
572
- linktoFn: linkto,
573
- sectionName: SECTION_TYPE.Classes,
574
- }),
575
-
576
- [SECTION_TYPE.Externals]: buildSidebarMembers({
577
- itemHeading: 'Externals',
578
- items: members.externals,
579
- itemsSeen: seen,
580
- linktoFn: linktoExternal,
581
- sectionName: SECTION_TYPE.Externals,
582
- }),
583
-
584
- [SECTION_TYPE.Events]: buildSidebarMembers({
585
- itemHeading: 'Events',
586
- items: members.events,
587
- itemsSeen: seen,
588
- linktoFn: linkto,
589
- sectionName: SECTION_TYPE.Events,
590
- }),
591
-
592
- [SECTION_TYPE.Namespaces]: buildSidebarMembers({
593
- itemHeading: 'Namespaces',
594
- items: members.namespaces,
595
- itemsSeen: seen,
596
- linktoFn: linkto,
597
- sectionName: SECTION_TYPE.Namespaces,
598
- }),
599
-
600
- [SECTION_TYPE.Mixins]: buildSidebarMembers({
601
- itemHeading: 'Mixins',
602
- items: members.mixins,
603
- itemsSeen: seen,
604
- linktoFn: linkto,
605
- sectionName: SECTION_TYPE.Mixins,
606
- }),
607
-
608
- [SECTION_TYPE.Tutorials]: buildSidebarMembers({
609
- itemHeading: 'Tutorials',
610
- items: members.tutorials,
611
- itemsSeen: seenTutorials,
612
- linktoFn: linktoTutorial,
613
- sectionName: SECTION_TYPE.Tutorials,
614
- }),
615
-
616
- [SECTION_TYPE.Interfaces]: buildSidebarMembers({
617
- itemHeading: 'Interfaces',
618
- items: members.interfaces,
619
- itemsSeen: seen,
620
- linktoFn: linkto,
621
- sectionName: SECTION_TYPE.Interfaces,
622
- }),
623
-
624
- [SECTION_TYPE.Global]: buildSidebarMembers({
625
- itemHeading: 'Global',
626
- items: members.globals,
627
- itemsSeen: seenGlobal,
628
- linktoFn: linkto,
629
- sectionName: SECTION_TYPE.Global,
630
- }),
631
- };
632
-
633
- sectionsOrder.forEach((section) => {
634
- if (SECTION_TYPE[section] !== undefined) {
635
- nav.sections.push(sections[section]);
636
- } else {
637
- const errorMsg = `While building nav. Section name: ${section} is not recognized.
638
- Accepted sections are: ${defaultSections.join(', ')}
639
- `;
640
-
641
- throw new Error(errorMsg);
642
- }
643
- });
644
-
645
- return nav;
646
- }
647
-
648
- /**
649
- @param {TAFFY} taffyData See <http://taffydb.com/>.
650
- @param {object} opts
651
- @param {Tutorial} tutorials
652
- */
653
- exports.publish = async function (taffyData, opts, tutorials) {
654
- let classes;
655
- let conf;
656
- let externals;
657
- let files;
658
- let fromDir;
659
- let globalUrl;
660
- let indexUrl;
661
- let interfaces;
662
- let members;
663
- let mixins;
664
- let modules;
665
- let namespaces;
666
- let outputSourceFiles;
667
- let packageInfo;
668
- let packages;
669
- const sourceFilePaths = [];
670
- let sourceFiles = {};
671
- let staticFileFilter;
672
- let staticFilePaths;
673
- let staticFiles;
674
- let staticFileScanner;
675
- let templatePath;
676
-
677
- data = taffyData;
678
-
679
- conf = env.conf.templates || {};
680
- conf.default = conf.default || {};
681
-
682
- templatePath = path.normalize(opts.template);
683
- view = new template.Template(path.join(templatePath, 'tmpl'));
684
-
685
- // claim some special filenames in advance, so the All-Powerful Overseer of Filename Uniqueness
686
- // doesn't try to hand them out later
687
- indexUrl = helper.getUniqueFilename('index');
688
- // don't call registerLink() on this one! 'index' is also a valid longname
689
-
690
- globalUrl = helper.getUniqueFilename('global');
691
- helper.registerLink('global', globalUrl);
692
-
693
- // set up templating
694
- view.layout = conf.default.layoutFile
695
- ? path.resolve(conf.default.layoutFile)
696
- : 'layout.tmpl';
697
-
698
- // set up tutorials for helper
699
- helper.setTutorials(tutorials);
700
-
701
- data = helper.prune(data);
702
-
703
- // eslint-disable-next-line no-extra-boolean-cast, no-implicit-coercion
704
- if (themeOpts.sort !== false) {
705
- data.sort('longname, version, since');
706
- }
707
-
708
- helper.addEventListeners(data);
709
-
710
- data().each((doclet) => {
711
- let sourcePath;
712
-
713
- doclet.attribs = '';
714
-
715
- if (doclet.examples) {
716
- doclet.examples = doclet.examples.map((example) => {
717
- let caption;
718
- let code;
719
-
720
- if (
721
- example.match(
722
- /^\s*<caption>([\s\S]+?)<\/caption>(\s*[\n\r])([\s\S]+)$/i
723
- )
724
- ) {
725
- caption = RegExp.$1;
726
- code = RegExp.$3;
727
- }
728
-
729
- return {
730
- caption: caption || '',
731
- code: code || example,
732
- };
733
- });
734
- }
735
-
736
- if (doclet.see) {
737
- doclet.see.forEach(function (seeItem, i) {
738
- doclet.see[i] = hashToLink(doclet, seeItem);
739
- });
740
- }
741
-
742
- // build a list of source files
743
- if (doclet.meta) {
744
- sourcePath = getPathFromDoclet(doclet);
745
- sourceFiles[sourcePath] = {
746
- resolved: sourcePath,
747
- shortened: null,
748
- };
749
- if (sourceFilePaths.indexOf(sourcePath) === -1) {
750
- sourceFilePaths.push(sourcePath);
751
- }
752
- }
753
-
754
- // added by clean-jsdoc-theme-dev.
755
- // to process yields.
756
- if (doclet.yields) {
757
- doclet.yields = getProcessedYield(doclet.yields);
758
- }
759
- });
760
-
761
- // update outdir if necessary, then create outdir
762
- packageInfo = (find({ kind: 'package' }) || [])[0];
763
- if (packageInfo && packageInfo.name) {
764
- outdir = path.join(outdir, packageInfo.name, packageInfo.version || '');
765
- }
766
- mkdirSync(outdir);
767
-
768
- // copy external static folders
769
- copyStaticFolder(themeOpts, outdir);
770
-
771
- // copy the template's static files to outdir
772
- fromDir = path.join(templatePath, 'static');
773
- staticFiles = lsSync(fromDir);
774
-
775
- staticFiles.forEach((fileName) => {
776
- const toPath = sourceToDestination(fromDir, fileName, outdir);
777
-
778
- mkdirSync(path.dirname(toPath));
779
- fs.copyFileSync(fileName, toPath);
780
- });
781
-
782
- // copy user-specified static files to outdir
783
- if (conf.default.staticFiles) {
784
- // The canonical property name is `include`. We accept `paths` for backwards compatibility
785
- // with a bug in JSDoc 3.2.x.
786
- staticFilePaths =
787
- conf.default.staticFiles.include ||
788
- conf.default.staticFiles.paths ||
789
- [];
790
- staticFileFilter = new (require('jsdoc/src/filter').Filter)(
791
- conf.default.staticFiles
792
- );
793
- staticFileScanner = new (require('jsdoc/src/scanner').Scanner)();
794
-
795
- staticFilePaths.forEach((filePath) => {
796
- filePath = path.resolve(env.pwd, filePath);
797
- const extraStaticFiles = staticFileScanner.scan(
798
- [filePath],
799
- 10,
800
- staticFileFilter
801
- );
802
-
803
- extraStaticFiles.forEach((fileName) => {
804
- const toPath = sourceToDestination(filePath, fileName, outdir);
805
-
806
- mkdirSync(path.dirname(toPath));
807
- fs.copyFileSync(fileName, toPath);
808
- });
809
- });
810
- }
811
-
812
- if (sourceFilePaths.length) {
813
- sourceFiles = shortenPaths(
814
- sourceFiles,
815
- path.commonPrefix(sourceFilePaths)
816
- );
817
- }
818
-
819
- data().each(function (doclet) {
820
- let docletPath;
821
- const url = helper.createLink(doclet);
822
-
823
- helper.registerLink(doclet.longname, url);
824
-
825
- // add a shortened version of the full path
826
- if (doclet.meta) {
827
- docletPath = getPathFromDoclet(doclet);
828
- docletPath = sourceFiles[docletPath].shortened;
829
- if (docletPath) {
830
- doclet.meta.shortpath = docletPath;
831
- }
832
- }
833
- });
834
-
835
- data().each(function (doclet) {
836
- const url = helper.longnameToUrl[doclet.longname];
837
-
838
- if (url.indexOf('#') > -1) {
839
- doclet.id = helper.longnameToUrl[doclet.longname].split(/#/).pop();
840
- } else {
841
- doclet.id = doclet.name;
842
- }
843
-
844
- if (needsSignature(doclet)) {
845
- addSignatureParams(doclet);
846
- addSignatureReturns(doclet);
847
- addAttribs(doclet);
848
- }
849
- });
850
-
851
- // do this after the urls have all been generated
852
- data().each((doclet) => {
853
- doclet.ancestors = getAncestorLinks(doclet);
854
-
855
- if (doclet.kind === 'member') {
856
- addSignatureTypes(doclet);
857
- addAttribs(doclet);
858
- }
859
-
860
- if (doclet.kind === 'constant') {
861
- addSignatureTypes(doclet);
862
- addAttribs(doclet);
863
- doclet.kind = 'member';
864
- }
865
- });
866
-
867
- members = helper.getMembers(data);
868
- members.tutorials = tutorials.children;
869
-
870
- // output pretty-printed source files by default
871
- outputSourceFiles = Boolean(
872
- conf.default && conf.default.outputSourceFiles !== false
873
- );
874
-
875
- // add template helpers
876
- view.find = find;
877
- view.linkto = linkto;
878
- view.resolveAuthorLinks = resolveAuthorLinks;
879
- view.tutoriallink = tutoriallink;
880
- view.htmlsafe = htmlsafe;
881
- view.outputSourceFiles = outputSourceFiles;
882
- view.footer = buildFooter(themeOpts);
883
- view.displayModuleHeader = moduleHeader(themeOpts);
884
- view.favicon = getFavicon(themeOpts);
885
- view.dynamicStyle = createDynamicStyleSheet(themeOpts);
886
- view.dynamicStyleSrc = returnPathOfStyleSrc(themeOpts);
887
- view.dynamicScript = createDynamicsScripts(themeOpts);
888
- view.dynamicScriptSrc = returnPathOfScriptScr(themeOpts);
889
- view.includeScript = includeScript(themeOpts, outdir);
890
- view.includeCss = includeCss(themeOpts, outdir);
891
- view.meta = getMetaTagData(themeOpts);
892
- view.theme = getTheme(themeOpts);
893
- // once for all
894
- view.sidebar = buildSidebar(members);
895
- view.navbar = buildNavbar(themeOpts);
896
- view.resizeable = resizeable(themeOpts);
897
- view.codepen = codepen(themeOpts);
898
- view.excludeInherited = Boolean(themeOpts.exclude_inherited);
899
- view.baseURL = getBaseURL(themeOpts);
900
- view.shouldRemoveScrollbarStyle = Boolean(
901
- themeOpts.shouldRemoveScrollbarStyle
902
- );
903
- attachModuleSymbols(
904
- find({ longname: { left: 'module:' } }),
905
- members.modules
906
- );
907
-
908
- if (themeOpts.prefixModuleToSidebarItems_experimental) {
909
- view.sidebar.sections.forEach((section, i) => {
910
- view.sidebar.sections[i].items = section.items.map((item) => {
911
- item.anchor = prefixModuleToItemAnchor(item);
912
-
913
- return item;
914
- });
915
- });
916
- }
917
-
918
- // generate the pretty-printed source files first so other pages can link to them
919
- if (outputSourceFiles) {
920
- generateSourceFiles(sourceFiles, opts.encoding);
921
- }
922
-
923
- if (members.globals.length) {
924
- await generate('Global', [{ kind: 'globalobj' }], globalUrl);
925
- }
926
-
927
- // index page displays information from package.json and lists files
928
- files = find({ kind: 'file' });
929
- packages = find({ kind: 'package' });
930
- // added by clean-jsdoc-theme-devs
931
- const homepageTitle = themeOpts.homepageTitle || 'Home';
932
- const includeFilesListInHomepage =
933
- themeOpts.includeFilesListInHomepage || false;
934
-
935
- await generate(
936
- homepageTitle,
937
- packages
938
- .concat([
939
- {
940
- kind: 'mainpage',
941
- readme: opts.readme,
942
- longname: opts.mainpagetitle
943
- ? opts.mainpagetitle
944
- : 'Main Page',
945
- },
946
- ])
947
- .concat(includeFilesListInHomepage ? files : []),
948
- indexUrl
949
- );
950
-
951
- // set up the lists that we'll use to generate pages
952
- classes = taffy(members.classes);
953
- modules = taffy(members.modules);
954
- namespaces = taffy(members.namespaces);
955
- mixins = taffy(members.mixins);
956
- externals = taffy(members.externals);
957
- interfaces = taffy(members.interfaces);
958
-
959
- Object.keys(helper.longnameToUrl).forEach(async function (longname) {
960
- const myClasses = helper.find(classes, { longname: longname });
961
- const myExternals = helper.find(externals, { longname: longname });
962
- const myInterfaces = helper.find(interfaces, { longname: longname });
963
- const myMixins = helper.find(mixins, { longname: longname });
964
- const myModules = helper.find(modules, { longname: longname });
965
- const myNamespaces = helper.find(namespaces, { longname: longname });
966
-
967
- if (myModules.length) {
968
- await generate(
969
- `Module: ${myModules[0].name}`,
970
- myModules,
971
- helper.longnameToUrl[longname]
972
- );
973
- }
974
-
975
- if (myClasses.length) {
976
- await generate(
977
- `Class: ${myClasses[0].name}`,
978
- myClasses,
979
- helper.longnameToUrl[longname]
980
- );
981
- }
982
-
983
- if (myNamespaces.length) {
984
- await generate(
985
- `Namespace: ${myNamespaces[0].name}`,
986
- myNamespaces,
987
- helper.longnameToUrl[longname]
988
- );
989
- }
990
-
991
- if (myMixins.length) {
992
- await generate(
993
- `Mixin: ${myMixins[0].name}`,
994
- myMixins,
995
- helper.longnameToUrl[longname]
996
- );
997
- }
998
-
999
- if (myExternals.length) {
1000
- await generate(
1001
- `External: ${myExternals[0].name}`,
1002
- myExternals,
1003
- helper.longnameToUrl[longname]
1004
- );
1005
- }
1006
-
1007
- if (myInterfaces.length) {
1008
- await generate(
1009
- `Interface: ${myInterfaces[0].name}`,
1010
- myInterfaces,
1011
- helper.longnameToUrl[longname]
1012
- );
1013
- }
1014
- });
1015
-
1016
- // TODO: move the tutorial functions to templateHelper.js
1017
- async function generateTutorial(title, tutorial, filename) {
1018
- const tutorialData = {
1019
- title: title,
1020
- header: tutorial.title,
1021
- content: tutorial.parse(),
1022
- children: tutorial.children,
1023
- filename,
1024
- };
1025
-
1026
- const tutorialPath = path.join(outdir, filename);
1027
- let html = view.render('tutorial.tmpl', tutorialData);
1028
-
1029
- // yes, you can use {@link} in tutorials too!
1030
- html = helper.resolveLinks(html); // turn {@link foo} into <a href="foodoc.html">foo</a>
1031
-
1032
- const minifiedHTML = await htmlMinify.minify(html, HTML_MINIFY_OPTIONS);
1033
-
1034
- fs.writeFileSync(tutorialPath, minifiedHTML, 'utf8');
1035
-
1036
- // added by clean-jsdoc-theme-devs
1037
- // adding support for tutorial
1038
- if (!hasSearch) return;
1039
-
1040
- try {
1041
- const baseName = path.basename(tutorialPath);
1042
- let body = /<body.*?>([\s\S]*)<\/body>/.exec(tutorialData.content);
1043
- let description = '';
1044
-
1045
- if (!Array.isArray(body)) {
1046
- body = /<article.*?>([\s\S]*)<\/article>/.exec(
1047
- tutorialData.content
1048
- );
1049
- }
1050
-
1051
- if (Array.isArray(body) && typeof body[1] === 'string') {
1052
- description = body[1]
1053
- // Replacing all html tags
1054
- .replace(/(<([^>]+)>)/g, '')
1055
- // Replacing all kind of line breaks
1056
- .replace(/(\r\n|\n|\r)/gm, ' ')
1057
- // Replacing all multi spaces with single space
1058
- .replace(/\s+/gm, ' ')
1059
- // Taking only first 100 characters
1060
- .substring(0, 100);
1061
- }
1062
-
1063
- if (typeof baseName === 'string' && baseName) {
1064
- searchList.push({
1065
- title: tutorialData.header,
1066
- link: `<a href="${baseName}">${baseName}</a>`,
1067
- description,
1068
- });
1069
- }
1070
- } catch (error) {
1071
- console.error(
1072
- 'There was some error while creating search array for tutorial.'
1073
- );
1074
- console.error(error);
1075
- }
1076
- }
1077
-
1078
- // tutorials can have only one parent so there is no risk for loops
1079
- function saveChildren({ children }) {
1080
- children.forEach(function (child) {
1081
- generateTutorial(
1082
- `Tutorial: ${child.title}`,
1083
- child,
1084
- helper.tutorialToUrl(child.name)
1085
- );
1086
- saveChildren(child);
1087
- });
1088
- }
1089
-
1090
- saveChildren(tutorials);
1091
-
1092
- // added by clean-jsdoc-theme-devs
1093
- // output search file if search
1094
- if (hasSearch) {
1095
- buildSearchListForData();
1096
- mkdirSync(path.join(outdir, 'data'));
1097
- fs.writeFileSync(
1098
- path.join(outdir, 'data', 'search.json'),
1099
- JSON.stringify({
1100
- list: searchList,
1101
- })
1102
- );
1103
- }
1104
- };