Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions jsdocs/plugins/yamlGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
}

function serializeIndex(classes) {
if (!packageName) {
return;
}
var serializer = require('js-yaml');
var fs = require('fs');
if (!fs.existsSync(base)) {
Expand Down Expand Up @@ -100,8 +103,8 @@
if (classItem.items && classItem.items.length) {
index.items[0].children.push(classItem.items[0].uid);
index.references.push({
uid : classItem.items[0].uid,
name : classItem.items[0].name
uid: classItem.items[0].uid,
name: classItem.items[0].name
});
}
}
Expand All @@ -115,12 +118,33 @@
function serializeToc(classes, fileMap) {
var serializer = require('js-yaml');
var fs = require('fs');

if (!fs.existsSync(base)) {
fs.mkdirSync(base);
}

var toc = [];
let namespaceMap = {};
let classToNamespaceMap = {};
let toc = [];

for (var id in classes) {
let classItem = classes[id];
let lastDot = id.lastIndexOf('.');
if (lastDot > 0) {
let ns = id.substring(0, lastDot);
namespaceMap[ns] = namespaceMap[ns] || {};
classToNamespaceMap[id] = namespaceMap[ns];
if (ns !== globalUid && !namespaceMap[ns].toc) {
namespaceMap[ns].toc = {
uid: ns,
name: ns,
items: []
};
toc.push(namespaceMap[ns].toc);
}
}
}

for (var id in classes) {
var classItem = classes[id];
// build references
Expand Down Expand Up @@ -159,11 +183,16 @@
var tocItem = {
uid: id,
name: classItem.items[0].name
};

toc.push(tocItem);
};
// Add to namespace children in ToC, or root if global
if (classToNamespaceMap[id]) {
classToNamespaceMap[id].toc.items.push(tocItem);
} else {
toc.push(tocItem);
}
}
toc.sort(function (a, b) {

let sortFn = function (a, b) {
var nameA = a.name.toUpperCase();
var nameB = b.name.toUpperCase();
if (nameA < nameB) {
Expand All @@ -174,6 +203,14 @@
}

return 0;
};

// Sort the toc items, followed by sorting their children.
toc.sort(sortFn);
toc.forEach(function (rootTocitem) {
if (rootTocitem.items) {
rootTocitem.items.sort(sortFn);
}
});

fs.writeFileSync(base + '/toc.yml', serializer.safeDump(toc));
Expand All @@ -200,7 +237,7 @@
return;
}
// ignore unexported global member
if (doclet.memberof === undefined && doclet.kind != 'class' && !(doclet.meta && doclet.meta.code && typeof(doclet.meta.code.name) === 'string' && doclet.meta.code.name.indexOf('exports') == 0)) {
if (doclet.memberof === undefined && doclet.kind != 'class' && !(doclet.meta && doclet.meta.code && typeof (doclet.meta.code.name) === 'string' && doclet.meta.code.name.indexOf('exports') == 0)) {
return;
}
// ignore inner function or member
Expand Down Expand Up @@ -257,7 +294,7 @@
parseBegin: function () {
var fse = require('fs-extra');
config = fse.readJsonSync(jsdocConfigPath);

if (config.repo && config.repo.url && !config.repo.url.endsWith('.git')) {
config.repo.url = config.repo.url + '.git';
}
Expand Down