mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-6659] cleanup unused docs utils (#9274)
* remove unused scripts * remove unused scripts * remove unused scripts * remove unused libs * remove unused code * remove unused code and libs, fix linting issues * code cleanup * linting fixes * linting fixes
This commit is contained in:
@@ -1,23 +1,19 @@
|
||||
var path = require("path");
|
||||
|
||||
var unist = require("../unistHelpers");
|
||||
|
||||
var seeAlsoHeading = "See Also";
|
||||
const path = require('path');
|
||||
const unist = require('../unistHelpers');
|
||||
const seeAlsoHeading = 'See Also';
|
||||
|
||||
module.exports = {
|
||||
"initPhase": initPhase,
|
||||
"readPhase": readPhase,
|
||||
"aggPhase": aggPhase,
|
||||
"updatePhase": updatePhase
|
||||
}
|
||||
|
||||
initPhase: initPhase,
|
||||
readPhase: readPhase,
|
||||
aggPhase: aggPhase,
|
||||
updatePhase: updatePhase
|
||||
};
|
||||
|
||||
function initPhase(aggData) {
|
||||
aggData.saGraph = {};
|
||||
aggData.saUpdateGraph = {};
|
||||
}
|
||||
|
||||
|
||||
function readPhase(tree, pathname, aggData) {
|
||||
var saHeadingOffset = findSeeAlsoSection(tree);
|
||||
|
||||
@@ -27,13 +23,9 @@ function readPhase(tree, pathname, aggData) {
|
||||
// Skip over non-list parts.
|
||||
var s;
|
||||
|
||||
for (
|
||||
s = saHeadingOffset;
|
||||
(s < tree.children.length) && !unist.isListUnordered(tree.children[s]);
|
||||
s++
|
||||
);
|
||||
for (s = saHeadingOffset; s < tree.children.length && !unist.isListUnordered(tree.children[s]); s++);
|
||||
|
||||
if ((s < tree.children.length) && unist.isListUnordered(tree.children[s])) {
|
||||
if (s < tree.children.length && unist.isListUnordered(tree.children[s])) {
|
||||
var list = tree.children[s];
|
||||
|
||||
for (var i = 0; i < list.children.length; i++) {
|
||||
@@ -46,17 +38,15 @@ function readPhase(tree, pathname, aggData) {
|
||||
}
|
||||
}
|
||||
|
||||
aggData.saGraph[path.basename(pathname, ".md")] = saNode;
|
||||
aggData.saGraph[path.basename(pathname, '.md')] = saNode;
|
||||
}
|
||||
|
||||
|
||||
function aggPhase(aggData) {
|
||||
aggData.saUpdateGraph = tidyGraph(aggData.saGraph);
|
||||
}
|
||||
|
||||
|
||||
function updatePhase(tree, pathname, aggData) {
|
||||
var currNodeName = path.basename(pathname, ".md");
|
||||
var currNodeName = path.basename(pathname, '.md');
|
||||
var currNodeArcs = aggData.saUpdateGraph[currNodeName];
|
||||
|
||||
if (currNodeArcs.length > 0) {
|
||||
@@ -64,7 +54,7 @@ function updatePhase(tree, pathname, aggData) {
|
||||
|
||||
for (var i = 0; i < currNodeArcs.length; i++) {
|
||||
var linkText = graphKeyToLinkName(currNodeArcs[i]);
|
||||
var linkTarget = currNodeArcs[i] + ".md";
|
||||
var linkTarget = currNodeArcs[i] + '.md';
|
||||
var link = unist.makeLink(unist.makeText(linkText), linkTarget);
|
||||
saListItems.push(unist.makeListItem(link));
|
||||
}
|
||||
@@ -75,11 +65,7 @@ function updatePhase(tree, pathname, aggData) {
|
||||
// Skip over non-list parts.
|
||||
var s;
|
||||
|
||||
for (
|
||||
s = saHeadingOffset;
|
||||
(s < tree.children.length) && !unist.isListUnordered(tree.children[s]);
|
||||
s++
|
||||
);
|
||||
for (s = saHeadingOffset; s < tree.children.length && !unist.isListUnordered(tree.children[s]); s++);
|
||||
|
||||
// Push all elements of the items array as if they were separate elements.
|
||||
Array.prototype.push.apply(tree.children[s].children, saListItems);
|
||||
@@ -93,39 +79,30 @@ function updatePhase(tree, pathname, aggData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function graphKeyToLinkName(key) {
|
||||
var mainSections = key.split(".");
|
||||
mainSections[0] = tidyName(mainSections[0]);
|
||||
return mainSections.join(" ");
|
||||
var mainSections = key.split('.');
|
||||
mainSections[0] = tidyName(mainSections[0]);
|
||||
return mainSections.join(' ');
|
||||
}
|
||||
|
||||
// Convert an Angular-style name (eg, "card-view") into one with correct spaces and uppercase (eg, "Card view").
|
||||
function tidyName(name) {
|
||||
var result = name.replace(/-/g, " ");
|
||||
var result = name.replace(/-/g, ' ');
|
||||
result = result.substr(0, 1).toUpperCase() + result.substr(1);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function makeEmptySAList() {
|
||||
var result = [];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Makes link symmetrical between items (ie, if A links to B but not the other way
|
||||
// around then it adds the missing link).
|
||||
function tidyGraph(graph) {
|
||||
var nodeNames = Object.keys(graph);
|
||||
var result = {};
|
||||
|
||||
for (var n = 0; n < nodeNames.length; n++) {
|
||||
for (let n = 0; n < nodeNames.length; n++) {
|
||||
result[nodeNames[n]] = [];
|
||||
}
|
||||
|
||||
for (var n = 0; n < nodeNames.length; n++) {
|
||||
for (let n = 0; n < nodeNames.length; n++) {
|
||||
var currNodeName = nodeNames[n];
|
||||
|
||||
var currNodeArcs = graph[currNodeName];
|
||||
@@ -146,29 +123,21 @@ function tidyGraph(graph) {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function findSeeAlsoSection(tree) {
|
||||
var i;
|
||||
|
||||
for (i = 0; i < tree.children.length; i++) {
|
||||
var child = tree.children[i];
|
||||
|
||||
if (unist.isHeading(child) && (child.children[0].value.toLowerCase() === seeAlsoHeading.toLowerCase()))
|
||||
return i;
|
||||
if (unist.isHeading(child) && child.children[0].value.toLowerCase() === seeAlsoHeading.toLowerCase()) return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
function getItemLinkInfo(listItem) {
|
||||
var linkTarget = listItem.children[0].children[0].url;
|
||||
|
||||
if (linkTarget.startsWith("http:") ||
|
||||
linkTarget.startsWith("#") ||
|
||||
!linkTarget.endsWith(".md"))
|
||||
return null;
|
||||
else
|
||||
return path.basename(linkTarget, ".md");
|
||||
if (linkTarget.startsWith('http:') || linkTarget.startsWith('#') || !linkTarget.endsWith('.md')) return null;
|
||||
else return path.basename(linkTarget, '.md');
|
||||
}
|
||||
|
||||
|
@@ -1,51 +1,43 @@
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const remark = require('remark');
|
||||
const replaceSection = require('mdast-util-heading-range');
|
||||
const { toString } = require('mdast-util-to-string');
|
||||
const ejs = require('ejs');
|
||||
const unist = require('../unistHelpers');
|
||||
const mdNav = require('../mdNav');
|
||||
|
||||
var remark = require("remark");
|
||||
//var tocGenerator = require("mdast-util-toc");
|
||||
var replaceSection = require("mdast-util-heading-range");
|
||||
var tostring = require("mdast-util-to-string");
|
||||
|
||||
var ejs = require("ejs");
|
||||
|
||||
var unist = require("../unistHelpers");
|
||||
var mdNav = require("../mdNav");
|
||||
|
||||
const contentsHeading = "Contents";
|
||||
const contentsHeading = 'Contents';
|
||||
const minHeadingsForToc = 8;
|
||||
const maxTocHeadingDepth = 3;
|
||||
|
||||
var templateFolder = path.resolve("tools", "doc", "templates");
|
||||
const templateFolder = path.resolve('tools', 'doc', 'templates');
|
||||
|
||||
module.exports = {
|
||||
"processDocs": processDocs
|
||||
}
|
||||
|
||||
processDocs: processDocs
|
||||
};
|
||||
|
||||
function processDocs(mdCache, aggData, errorMessages) {
|
||||
var pathnames = Object.keys(mdCache);
|
||||
const pathNames = Object.keys(mdCache);
|
||||
|
||||
pathnames.forEach(pathname => {
|
||||
pathNames.forEach((pathname) => {
|
||||
updateFile(mdCache[pathname].mdOutTree, pathname, aggData, errorMessages);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Find an existing Contents section or add a new empty one if needed.
|
||||
// Returns true if section is present/needed, false if not needed.
|
||||
function establishContentsSection(mdTree) {
|
||||
var firstL2HeadingPos = -1;
|
||||
var numTocHeadings = 0;
|
||||
var foundContentsHeading = false;
|
||||
let firstL2HeadingPos = -1;
|
||||
let numTocHeadings = 0;
|
||||
let foundContentsHeading = false;
|
||||
|
||||
for (let i = 0; i < mdTree.children.length; i++) {
|
||||
const child = mdTree.children[i];
|
||||
|
||||
for (var i = 0; i < mdTree.children.length; i++) {
|
||||
var child = mdTree.children[i];
|
||||
|
||||
// Look through all headings.
|
||||
if (child.type === "heading") {
|
||||
|
||||
if ((child.depth > 1) && (child.depth <= maxTocHeadingDepth)) {
|
||||
if (child.type === 'heading') {
|
||||
if (child.depth > 1 && child.depth <= maxTocHeadingDepth) {
|
||||
numTocHeadings++;
|
||||
}
|
||||
|
||||
@@ -57,7 +49,7 @@ function establishContentsSection(mdTree) {
|
||||
|
||||
// If it is also a Contents heading then we're done. We don't include the
|
||||
// Contents heading itself within the ToC, so decrement the count for that.
|
||||
if ((child.children[0].value === contentsHeading) && !foundContentsHeading) {
|
||||
if (child.children[0].value === contentsHeading && !foundContentsHeading) {
|
||||
foundContentsHeading = true;
|
||||
numTocHeadings--;
|
||||
}
|
||||
@@ -69,42 +61,38 @@ function establishContentsSection(mdTree) {
|
||||
// If there are enough headings for a ToC to be necessary then
|
||||
// add one in the right place.
|
||||
if (!foundContentsHeading) {
|
||||
var newContsHeading = unist.makeHeading(unist.makeText(contentsHeading), 2);
|
||||
const newHeading = unist.makeHeading(unist.makeText(contentsHeading), 2);
|
||||
|
||||
// If we found another L2 heading then add the Contents in just before it.
|
||||
if (firstL2HeadingPos != -1) {
|
||||
mdTree.children.splice(firstL2HeadingPos, 0, newContsHeading);
|
||||
if (firstL2HeadingPos !== -1) {
|
||||
mdTree.children.splice(firstL2HeadingPos, 0, newHeading);
|
||||
} else {
|
||||
// Otherwise, the unlikely situation where a ToC is required but there
|
||||
// are no L2 headings! Add it as the second element in the document.
|
||||
mdTree.children.splice(1, 0, newContsHeading);
|
||||
mdTree.children.splice(1, 0, newHeading);
|
||||
}
|
||||
}
|
||||
|
||||
return numTocHeadings;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function updateFile(tree, pathname, _aggData, _errorMessages) {
|
||||
if (path.basename(pathname, ".md").match(/README|versionIndex/)) {
|
||||
if (path.basename(pathname, '.md').match(/README|versionIndex/)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we need a contents section then add one or update the existing one.
|
||||
var numTocHeadings = establishContentsSection(tree);
|
||||
// If we need a contents section then add one or update the existing one.
|
||||
const numTocHeadings = establishContentsSection(tree);
|
||||
|
||||
if (numTocHeadings >= minHeadingsForToc) {
|
||||
var newToc = makeToc(tree); //tocGenerator(tree, {heading: contentsHeading, maxDepth: 3});
|
||||
const newToc = makeToc(tree);
|
||||
|
||||
replaceSection(tree, contentsHeading, function(before, oldSection, after) {
|
||||
replaceSection(tree, contentsHeading, function (before, oldSection, after) {
|
||||
return [before, newToc, after];
|
||||
});
|
||||
} else {
|
||||
// Otherwise, we don't need one, so remove any existing one.
|
||||
replaceSection(tree, contentsHeading, function(before, oldSection, after) {
|
||||
replaceSection(tree, contentsHeading, function (before, oldSection, after) {
|
||||
return [after];
|
||||
});
|
||||
}
|
||||
@@ -112,44 +100,39 @@ function updateFile(tree, pathname, _aggData, _errorMessages) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function makeToc(tree) {
|
||||
var nav = new mdNav.MDNav(tree);
|
||||
const nav = new mdNav.MDNav(tree);
|
||||
const headings = nav.headings((h) => h.depth > 1 && h.depth <= maxTocHeadingDepth);
|
||||
const context = { headings: [] };
|
||||
|
||||
var headings = nav.headings(h =>
|
||||
(h.depth > 1) &&
|
||||
(h.depth <= maxTocHeadingDepth) //&&
|
||||
//!((h.children[0].type === "text") && (h.children[0].value === "Contents"))
|
||||
);
|
||||
headings.forEach((heading) => {
|
||||
let linkTitle = '';
|
||||
|
||||
var context = {headings: []};
|
||||
|
||||
headings.forEach(heading => {
|
||||
var linkTitle = "";
|
||||
|
||||
if (!((heading.item.children.length > 0) && (heading.item.children[0].type === "text") && (heading.item.children[0].value === "Contents"))) {
|
||||
linkTitle = tostring(heading.item).trim();
|
||||
if (!(heading.item.children.length > 0 && heading.item.children[0].type === 'text' && heading.item.children[0].value === 'Contents')) {
|
||||
linkTitle = toString(heading.item).trim();
|
||||
}
|
||||
|
||||
if (linkTitle !== "") {
|
||||
if (linkTitle !== '') {
|
||||
context.headings.push({
|
||||
"level": heading.item.depth - 2,
|
||||
"title": linkTitle,
|
||||
//"anchor": "#" + linkTitle.toLowerCase().replace(/ /g, "-").replace(/[:;@\.,'"`$\(\)\/]/g ,"")
|
||||
"anchor": "#" + linkTitle.toLowerCase()
|
||||
.replace(/[^a-z0-9\s\-_]/g, '')
|
||||
.replace(/\s/g ,"-")
|
||||
.replace(/\-+$/, '')
|
||||
})
|
||||
};
|
||||
level: heading.item.depth - 2,
|
||||
title: linkTitle,
|
||||
anchor:
|
||||
'#' +
|
||||
linkTitle
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s\-_]/g, '')
|
||||
.replace(/\s/g, '-')
|
||||
.replace(/-+$/, '')
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var templateName = path.resolve(templateFolder, "toc.ejs");
|
||||
var templateSource = fs.readFileSync(templateName, "utf8");
|
||||
var template = ejs.compile(templateSource);
|
||||
const templateName = path.resolve(templateFolder, 'toc.ejs');
|
||||
const templateSource = fs.readFileSync(templateName, 'utf8');
|
||||
const template = ejs.compile(templateSource);
|
||||
|
||||
var mdText = template(context);
|
||||
var newMD = remark().parse(mdText);
|
||||
const mdText = template(context);
|
||||
const newMD = remark().parse(mdText);
|
||||
|
||||
return newMD.children[0];
|
||||
}
|
||||
}
|
||||
|
@@ -31,10 +31,10 @@ let nameExceptions;
|
||||
export function processDocs(mdCache, aggData) {
|
||||
nameExceptions = aggData.config.typeNameExceptions;
|
||||
|
||||
const pathnames = Object.keys(mdCache);
|
||||
const pathNames = Object.keys(mdCache);
|
||||
let internalErrors;
|
||||
|
||||
pathnames.forEach(pathname => {
|
||||
pathNames.forEach((pathname) => {
|
||||
internalErrors = [];
|
||||
updateFile(mdCache[pathname].mdOutTree, pathname, aggData, internalErrors);
|
||||
|
||||
@@ -47,7 +47,7 @@ export function processDocs(mdCache, aggData) {
|
||||
function showErrors(filename, errorMessages) {
|
||||
console.log(filename);
|
||||
|
||||
errorMessages.forEach(message => {
|
||||
errorMessages.forEach((message) => {
|
||||
console.log(' ' + message);
|
||||
});
|
||||
|
||||
@@ -55,7 +55,6 @@ function showErrors(filename, errorMessages) {
|
||||
}
|
||||
|
||||
function updateFile(tree, pathname, aggData, errorMessages) {
|
||||
|
||||
const className = ngNameToClassName(path.basename(pathname, '.md'), nameExceptions);
|
||||
const classTypeMatch = className.match(/component|directive|service/i);
|
||||
const compData = aggData.classInfo[className];
|
||||
@@ -67,8 +66,6 @@ function updateFile(tree, pathname, aggData, errorMessages) {
|
||||
const inputMD = getPropDocsFromMD(tree, 'Properties', 3);
|
||||
const outputMD = getPropDocsFromMD(tree, 'Events', 2);
|
||||
|
||||
|
||||
|
||||
updatePropDocsFromMD(compData, inputMD, outputMD, errorMessages);
|
||||
|
||||
if (classType === 'service') {
|
||||
@@ -81,7 +78,7 @@ function updateFile(tree, pathname, aggData, errorMessages) {
|
||||
const template = ejs.compile(templateSource);
|
||||
|
||||
let mdText = template(compData);
|
||||
mdText = mdText.replace(/^ +\|/mg, '|');
|
||||
mdText = mdText.replace(/^ +\|/gm, '|');
|
||||
|
||||
const newSection = remark().parse(mdText.trim()).children;
|
||||
|
||||
@@ -91,7 +88,7 @@ function updateFile(tree, pathname, aggData, errorMessages) {
|
||||
return newSection;
|
||||
});
|
||||
|
||||
compData.errors.forEach(err => {
|
||||
compData.errors.forEach((err) => {
|
||||
errorMessages.push(err);
|
||||
});
|
||||
}
|
||||
@@ -104,37 +101,31 @@ function getPropDocsFromMD(tree, sectionHeading, docsColumn) {
|
||||
|
||||
const nav = new MDNav(tree);
|
||||
|
||||
const classMemHeading = nav
|
||||
.heading(h => {
|
||||
return (h.children[0].type === 'text') && (h.children[0].value === 'Class members');
|
||||
});
|
||||
const classMemHeading = nav.heading((h) => {
|
||||
return h.children[0].type === 'text' && h.children[0].value === 'Class members';
|
||||
});
|
||||
|
||||
const propsTable = classMemHeading
|
||||
.heading(h => {
|
||||
return (h.children[0].type === 'text') && (h.children[0].value === sectionHeading);
|
||||
}).table();
|
||||
.heading((h) => {
|
||||
return h.children[0].type === 'text' && h.children[0].value === sectionHeading;
|
||||
})
|
||||
.table();
|
||||
|
||||
let propTableRow = propsTable.childNav
|
||||
.tableRow(() => true, 1).childNav;
|
||||
let propTableRow = propsTable.childNav.tableRow(() => true, 1).childNav;
|
||||
|
||||
let i = 1;
|
||||
|
||||
while (!propTableRow.empty) {
|
||||
const propName = propTableRow
|
||||
.tableCell().childNav
|
||||
.text().item.value;
|
||||
const propName = propTableRow.tableCell().childNav.text().item.value;
|
||||
|
||||
const propDocText = propTableRow
|
||||
.tableCell(() => true, docsColumn).childNav
|
||||
.text().item;
|
||||
const propDocText = propTableRow.tableCell(() => true, docsColumn).childNav.text().item;
|
||||
|
||||
if (propDocText) {
|
||||
result[propName] = propDocText.value;
|
||||
}
|
||||
|
||||
i++;
|
||||
propTableRow = propsTable.childNav
|
||||
.tableRow(() => true, i).childNav;
|
||||
propTableRow = propsTable.childNav.tableRow(() => true, i).childNav;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -145,25 +136,22 @@ function getMethodDocsFromMD(tree) {
|
||||
|
||||
const nav = new MDNav(tree);
|
||||
|
||||
const classMemHeading = nav
|
||||
.heading(h => {
|
||||
return (h.children[0].type === 'text') && (h.children[0].value === 'Class members');
|
||||
});
|
||||
const classMemHeading = nav.heading((h) => {
|
||||
return h.children[0].type === 'text' && h.children[0].value === 'Class members';
|
||||
});
|
||||
|
||||
const methListItems = classMemHeading
|
||||
.heading(h => {
|
||||
return (h.children[0].type === 'text') && (h.children[0].value === 'Methods');
|
||||
}).list().childNav;
|
||||
.heading((h) => {
|
||||
return h.children[0].type === 'text' && h.children[0].value === 'Methods';
|
||||
})
|
||||
.list().childNav;
|
||||
|
||||
let methItem = methListItems
|
||||
.listItem();
|
||||
let methItem = methListItems.listItem();
|
||||
|
||||
let i = 0;
|
||||
|
||||
while (!methItem.empty) {
|
||||
const methNameSection = methItem.childNav
|
||||
.paragraph().childNav
|
||||
.strong().childNav;
|
||||
const methNameSection = methItem.childNav.paragraph().childNav.strong().childNav;
|
||||
|
||||
let methName = '';
|
||||
|
||||
@@ -171,23 +159,19 @@ function getMethodDocsFromMD(tree) {
|
||||
if (!methNameSection.empty) {
|
||||
methName = methNameSection.text().item.value;
|
||||
|
||||
const methDoc = methItem.childNav
|
||||
.paragraph().childNav
|
||||
.html()
|
||||
.text().value;
|
||||
const methDoc = methItem.childNav.paragraph().childNav.html().text().value;
|
||||
|
||||
const params = getMDMethodParams(methItem);
|
||||
|
||||
result[methName] = {
|
||||
'docText': methDoc.replace(/^\n/, ''),
|
||||
'params': params
|
||||
docText: methDoc.replace(/^\n/, ''),
|
||||
params: params
|
||||
};
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
methItem = methListItems
|
||||
.listItem(l => true, i);
|
||||
methItem = methListItems.listItem((l) => true, i);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -198,31 +182,24 @@ function getMDMethodParams(methItem: MDNav) {
|
||||
|
||||
const paramList = methItem.childNav.list().childNav;
|
||||
|
||||
const paramListItems = paramList
|
||||
.listItems();
|
||||
const paramListItems = paramList.listItems();
|
||||
|
||||
paramListItems.forEach(paramListItem => {
|
||||
const paramNameNode = paramListItem.childNav
|
||||
.paragraph().childNav
|
||||
.emph().childNav;
|
||||
paramListItems.forEach((paramListItem) => {
|
||||
const paramNameNode = paramListItem.childNav.paragraph().childNav.emph().childNav;
|
||||
|
||||
let paramName;
|
||||
|
||||
if (!paramNameNode.empty) {
|
||||
paramName = paramNameNode.text().item.value.replace(/:/, '');
|
||||
} else {
|
||||
let item = paramListItem.childNav.paragraph().childNav
|
||||
.strong().childNav.text();
|
||||
let item = paramListItem.childNav.paragraph().childNav.strong().childNav.text();
|
||||
|
||||
if (paramName) {
|
||||
paramName = item.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const paramDoc = paramListItem.childNav
|
||||
.paragraph().childNav
|
||||
.text(t => true, 1).value; // item.value;
|
||||
const paramDoc = paramListItem.childNav.paragraph().childNav.text((t) => true, 1).value; // item.value;
|
||||
|
||||
result[paramName] = paramDoc.replace(/^[ -]+/, '');
|
||||
});
|
||||
@@ -231,7 +208,7 @@ function getMDMethodParams(methItem: MDNav) {
|
||||
}
|
||||
|
||||
function updatePropDocsFromMD(comp: ComponentInfo, inputDocs, outputDocs, errorMessages) {
|
||||
comp.properties.forEach(prop => {
|
||||
comp.properties.forEach((prop) => {
|
||||
let propMDDoc: string;
|
||||
|
||||
if (prop.isInput) {
|
||||
@@ -249,7 +226,7 @@ function updatePropDocsFromMD(comp: ComponentInfo, inputDocs, outputDocs, errorM
|
||||
}
|
||||
|
||||
function updateMethodDocsFromMD(comp: ComponentInfo, methodDocs, errorMessages) {
|
||||
comp.methods.forEach(meth => {
|
||||
comp.methods.forEach((meth) => {
|
||||
const currMethMD = methodDocs[meth.name];
|
||||
|
||||
// If JSDocs are empty but MD docs aren't then the Markdown is presumably more up-to-date.
|
||||
@@ -258,7 +235,7 @@ function updateMethodDocsFromMD(comp: ComponentInfo, methodDocs, errorMessages)
|
||||
errorMessages.push(`Warning: empty JSDocs for method sig "${meth.name}" may need sync with the .md file.`);
|
||||
}
|
||||
|
||||
meth.params.forEach(param => {
|
||||
meth.params.forEach((param) => {
|
||||
if (!param.docText && currMethMD && currMethMD.params[param.name]) {
|
||||
param.docText = currMethMD.params[param.name];
|
||||
errorMessages.push(`Warning: empty JSDocs for parameter "${param.name} (${meth.name})" may need sync with the .md file.`);
|
||||
|
@@ -40,13 +40,13 @@ function aggPhase() {
|
||||
const template = ejs.compile(templateSource);
|
||||
|
||||
let mdText = template(indexDocData);
|
||||
mdText = mdText.replace(/^ +\|/mg, '|');
|
||||
mdText = mdText.replace(/^ +\|/gm, '|');
|
||||
|
||||
const newSection = remark().use(frontMatter, ['yaml']).data('settings', {paddedTable: false, gfm: false}).parse(mdText.trim()).children;
|
||||
const newSection = remark().use(frontMatter, ['yaml']).data('settings', { paddedTable: false, gfm: false }).parse(mdText.trim()).children;
|
||||
|
||||
const tutIndexFile = path.resolve(tutFolder, 'README.md');
|
||||
const tutIndexText = fs.readFileSync(tutIndexFile, 'utf8');
|
||||
const tutIndexMD = remark().use(frontMatter, ['yaml']).data('settings', {paddedTable: false, gfm: false}).parse(tutIndexText);
|
||||
const tutIndexMD = remark().use(frontMatter, ['yaml']).data('settings', { paddedTable: false, gfm: false }).parse(tutIndexText);
|
||||
|
||||
replaceSection(tutIndexMD, 'Tutorials', (before, section, after) => {
|
||||
newSection.unshift(before);
|
||||
@@ -54,7 +54,10 @@ function aggPhase() {
|
||||
return newSection;
|
||||
});
|
||||
|
||||
fs.writeFileSync(tutIndexFile, remark().use(frontMatter, {type: 'yaml', fence: '---'}).data('settings', {paddedTable: false, gfm: false}).stringify(tutIndexMD));
|
||||
fs.writeFileSync(
|
||||
tutIndexFile,
|
||||
remark().use(frontMatter, { type: 'yaml', fence: '---' }).data('settings', { paddedTable: false, gfm: false }).stringify(tutIndexMD)
|
||||
);
|
||||
}
|
||||
|
||||
function getIndexDocData() {
|
||||
@@ -62,7 +65,7 @@ function getIndexDocData() {
|
||||
const summaryArray = JSON.parse(fs.readFileSync(indexFile, 'utf8'));
|
||||
let indexArray = [];
|
||||
|
||||
summaryArray.forEach(element => {
|
||||
summaryArray.forEach((element) => {
|
||||
if (element['title'] === 'Tutorials') {
|
||||
indexArray = element['children'];
|
||||
}
|
||||
@@ -72,7 +75,7 @@ function getIndexDocData() {
|
||||
tuts: []
|
||||
};
|
||||
|
||||
indexArray.forEach(element => {
|
||||
indexArray.forEach((element) => {
|
||||
const tutData = { link: element['file'] };
|
||||
|
||||
const tutFile = path.resolve(tutFolder, element['file']);
|
||||
@@ -89,21 +92,16 @@ function getIndexDocData() {
|
||||
|
||||
const briefDesc = getFirstParagraph(tutMD);
|
||||
|
||||
const briefDescText = remark()
|
||||
.use(frontMatter, {type: 'yaml', fence: '---'})
|
||||
.data('settings', {paddedTable: false, gfm: false})
|
||||
.stringify(briefDesc);
|
||||
|
||||
tutData['briefDesc'] = briefDescText;
|
||||
tutData['briefDesc'] = remark()
|
||||
.use(frontMatter, { type: 'yaml', fence: '---' })
|
||||
.data('settings', { paddedTable: false, gfm: false })
|
||||
.stringify(briefDesc);
|
||||
|
||||
const title = getFirstHeading(tutMD);
|
||||
|
||||
const titleText = remark()
|
||||
.use(frontMatter, {type: 'yaml', fence: '---'})
|
||||
.data('settings', {paddedTable: false, gfm: false})
|
||||
.stringify(title.children[0]);
|
||||
|
||||
tutData['title'] = titleText;
|
||||
tutData['title'] = remark()
|
||||
.use(frontMatter, { type: 'yaml', fence: '---' })
|
||||
.data('settings', { paddedTable: false, gfm: false })
|
||||
.stringify(title.children[0]);
|
||||
|
||||
result.tuts.push(tutData);
|
||||
});
|
||||
@@ -122,11 +120,10 @@ function getDocMetadata(tree) {
|
||||
function getFirstParagraph(tree) {
|
||||
let s = 0;
|
||||
|
||||
for (; (s < tree.children.length) && !unist.isParagraph(tree.children[s]); s++) {}
|
||||
for (; s < tree.children.length && !unist.isParagraph(tree.children[s]); s++) {}
|
||||
|
||||
if (s < tree.children.length) {
|
||||
return tree.children[s];
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@@ -135,11 +132,10 @@ function getFirstParagraph(tree) {
|
||||
function getFirstHeading(tree) {
|
||||
let s = 0;
|
||||
|
||||
for (; (s < tree.children.length) && !unist.isHeading(tree.children[s]); s++) {}
|
||||
for (; s < tree.children.length && !unist.isHeading(tree.children[s]); s++) {}
|
||||
|
||||
if (s < tree.children.length) {
|
||||
return tree.children[s];
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,30 +1,20 @@
|
||||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
var yaml = require("js-yaml");
|
||||
|
||||
var remark = require("remark");
|
||||
var stringify = require("remark-stringify");
|
||||
var zone = require("mdast-zone");
|
||||
var frontMatter = require("remark-frontmatter");
|
||||
|
||||
var ejs = require("ejs");
|
||||
|
||||
var unist = require("../unistHelpers");
|
||||
var ngHelpers = require("../ngHelpers");
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const yaml = require('js-yaml');
|
||||
const remark = require('remark');
|
||||
const zone = require('mdast-zone');
|
||||
const frontMatter = require('remark-frontmatter');
|
||||
const ejs = require('ejs');
|
||||
const ngHelpers = require('../ngHelpers');
|
||||
|
||||
module.exports = {
|
||||
"processDocs": processDocs
|
||||
processDocs: processDocs
|
||||
};
|
||||
|
||||
|
||||
var docsFolderPath = path.resolve("docs");
|
||||
var histFilePath = path.resolve(docsFolderPath, "versionIndex.md");
|
||||
|
||||
var initialVersion = "v2.0.0";
|
||||
|
||||
var templateFolder = path.resolve("tools", "doc", "templates");
|
||||
|
||||
const docsFolderPath = path.resolve('docs');
|
||||
const histFilePath = path.resolve(docsFolderPath, 'versionIndex.md');
|
||||
const initialVersion = 'v2.0.0';
|
||||
const templateFolder = path.resolve('tools', 'doc', 'templates');
|
||||
|
||||
function processDocs(mdCache, aggData) {
|
||||
initPhase(aggData);
|
||||
@@ -32,34 +22,29 @@ function processDocs(mdCache, aggData) {
|
||||
aggPhase(aggData);
|
||||
}
|
||||
|
||||
|
||||
function initPhase(aggData) {
|
||||
aggData.versions = { "v2.0.0":[] };
|
||||
aggData.versions = { 'v2.0.0': [] };
|
||||
}
|
||||
|
||||
|
||||
function readPhase(mdCache, aggData) {
|
||||
var pathnames = Object.keys(mdCache);
|
||||
const pathNames = Object.keys(mdCache);
|
||||
|
||||
pathnames.forEach(pathname => {
|
||||
pathNames.forEach((pathname) => {
|
||||
getFileData(mdCache[pathname].mdInTree, pathname, aggData);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getFileData(tree, pathname, aggData) {
|
||||
var compName = pathname;
|
||||
var angNameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(model)|(pipe)|(service)|(widget)|(dialog))/;
|
||||
const compName = pathname;
|
||||
const angNameRegex = /([a-zA-Z0-9\-]+)\.((component)|(directive)|(model)|(pipe)|(service)|(widget)|(dialog))/;
|
||||
|
||||
if (!compName.match(angNameRegex))
|
||||
return;
|
||||
if (!compName.match(angNameRegex)) return;
|
||||
|
||||
if (compName.match(/boilerplate/))
|
||||
return;
|
||||
if (compName.match(/boilerplate/)) return;
|
||||
|
||||
if (tree && tree.children[0] && tree.children[0].type == "yaml") {
|
||||
var metadata = yaml.load(tree.children[0].value);
|
||||
var version = metadata["Added"];
|
||||
if (tree && tree.children[0] && tree.children[0].type === 'yaml') {
|
||||
const metadata = yaml.load(tree.children[0].value);
|
||||
const version = metadata['Added'];
|
||||
|
||||
if (version) {
|
||||
if (aggData.versions[version]) {
|
||||
@@ -76,40 +61,43 @@ function getFileData(tree, pathname, aggData) {
|
||||
}
|
||||
|
||||
function aggPhase(aggData) {
|
||||
var histFileText = fs.readFileSync(histFilePath, "utf8");
|
||||
var histFileTree = remark().use(frontMatter, ["yaml"]).data("settings", {paddedTable: false, gfm: false}).parse(histFileText);
|
||||
const histFileText = fs.readFileSync(histFilePath, 'utf8');
|
||||
const histFileTree = remark()
|
||||
.use(frontMatter, ['yaml'])
|
||||
.data('settings', {
|
||||
paddedTable: false,
|
||||
gfm: false
|
||||
})
|
||||
.parse(histFileText);
|
||||
|
||||
var keys = Object.keys(aggData.versions);
|
||||
const keys = Object.keys(aggData.versions);
|
||||
keys.sort((a, b) => {
|
||||
if (a > b)
|
||||
return -1;
|
||||
else if (b > a)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
if (a > b) return -1;
|
||||
else if (b > a) return 1;
|
||||
else return 0;
|
||||
});
|
||||
|
||||
var templateName = path.resolve(templateFolder, "versIndex.ejs");
|
||||
var templateSource = fs.readFileSync(templateName, "utf8");
|
||||
var template = ejs.compile(templateSource);
|
||||
const templateName = path.resolve(templateFolder, 'versIndex.ejs');
|
||||
const templateSource = fs.readFileSync(templateName, 'utf8');
|
||||
const template = ejs.compile(templateSource);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var version = keys[i];
|
||||
var versionItems = aggData.versions[version];
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
const version = keys[i];
|
||||
const versionItems = aggData.versions[version];
|
||||
versionItems.sort((a, b) => {
|
||||
var aa = path.basename(a, ".md");
|
||||
var bb = path.basename(b, ".md");
|
||||
const aa = path.basename(a, '.md');
|
||||
const bb = path.basename(b, '.md');
|
||||
|
||||
return aa.localeCompare(bb);
|
||||
});
|
||||
|
||||
var versionTemplateData = {items: []};
|
||||
const versionTemplateData = { items: [] };
|
||||
|
||||
for (var v = 0; v < versionItems.length; v++) {
|
||||
var displayName = ngHelpers.ngNameToDisplayName(path.basename(versionItems[v], ".md"));
|
||||
var pageLink = versionItems[v];// + ".md";
|
||||
for (let v = 0; v < versionItems.length; v++) {
|
||||
const displayName = ngHelpers.ngNameToDisplayName(path.basename(versionItems[v], '.md'));
|
||||
let pageLink = versionItems[v]; // + ".md";
|
||||
pageLink = pageLink.replace(/\\/g, '/');
|
||||
pageLink = pageLink.substr(pageLink.indexOf("docs") + 5);
|
||||
pageLink = pageLink.substr(pageLink.indexOf('docs') + 5);
|
||||
|
||||
versionTemplateData.items.push({
|
||||
title: displayName,
|
||||
@@ -117,12 +105,18 @@ function aggPhase(aggData) {
|
||||
});
|
||||
}
|
||||
|
||||
var mdText = template(versionTemplateData);
|
||||
mdText = mdText.replace(/^ +-/mg, "-");
|
||||
let mdText = template(versionTemplateData);
|
||||
mdText = mdText.replace(/^ +-/gm, '-');
|
||||
|
||||
var newSection = remark().use(frontMatter, ["yaml"]).data("settings", {paddedTable: false, gfm: false}).parse(mdText.trim()).children;
|
||||
const newSection = remark()
|
||||
.use(frontMatter, ['yaml'])
|
||||
.data('settings', {
|
||||
paddedTable: false,
|
||||
gfm: false
|
||||
})
|
||||
.parse(mdText.trim()).children;
|
||||
|
||||
var versSectionName = version.replace(/\./g, "");;
|
||||
const versSectionName = version.replace(/\./g, '');
|
||||
|
||||
zone(histFileTree, versSectionName, (startComment, oldSection, endComment) => {
|
||||
newSection.unshift(startComment);
|
||||
@@ -131,5 +125,8 @@ function aggPhase(aggData) {
|
||||
});
|
||||
}
|
||||
|
||||
fs.writeFileSync(histFilePath, remark().use(frontMatter, {type: 'yaml', fence: '---'}).data("settings", {paddedTable: false, gfm: false}).stringify(histFileTree));
|
||||
fs.writeFileSync(
|
||||
histFilePath,
|
||||
remark().use(frontMatter, { type: 'yaml', fence: '---' }).data('settings', { paddedTable: false, gfm: false }).stringify(histFileTree)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user