mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-08 23:12:16 +02:00
Cleaned up gravprep.js
This commit is contained in:
parent
3455dd296b
commit
9c664a2512
2 changed files with 377 additions and 387 deletions
|
@ -2,12 +2,26 @@
|
|||
|
||||
##Prerequisites
|
||||
|
||||
* Install node.js
|
||||
* Install node.js.
|
||||
* Install jsdoc via npm. `npm install jsdoc -g`
|
||||
|
||||
Run npm install if you would like th extra functionality for gravPrep.
|
||||
|
||||
To generate html documentation for the High Fidelity JavaScript API:
|
||||
|
||||
* `cd tools/jsdoc`
|
||||
* `jsdoc . -c config.json`
|
||||
|
||||
The out folder should contain index.html.
|
||||
|
||||
To generate the grav automation files, run node gravPrep.js after you have made a JSdoc output folder.
|
||||
|
||||
This will create files that are needed for hifi-grav and hifi-grav-content repos
|
||||
|
||||
The md files for hifi-grav-content are located in out/grav/06.api-reference.
|
||||
|
||||
The template twig html files for hifi-grav are located out/grav/templates.
|
||||
|
||||
if you would like to copy these to a local version of the docs on your system you can run with the follows args:
|
||||
|
||||
* node grav true "path/to/grav/" "path/to/grav/content"
|
|
@ -120,7 +120,7 @@ function allLinksToLowerCase(match, p1, p2, p3) {
|
|||
return [p1, p2, p3].join("");
|
||||
}
|
||||
|
||||
// Return the right group for where the method or type came from
|
||||
// Helper for fixing formatting of page links
|
||||
function fixLinkGrouping(match, p1, p2, p3) {
|
||||
// Handle if referencing ID
|
||||
let count = (p2.match(/\./g) || []).length;
|
||||
|
@ -149,6 +149,7 @@ function fixLinkGrouping(match, p1, p2, p3) {
|
|||
}
|
||||
}
|
||||
|
||||
// Return the right group for where the method or type came from
|
||||
function returnRightGroup(methodToCheck) {
|
||||
for (var key in groupNameMemberMap) {
|
||||
for (i = 0; i < groupNameMemberMap[key].length; i++) {
|
||||
|
@ -232,16 +233,16 @@ function prepareHtml(source) {
|
|||
function makeMdSource(title) {
|
||||
return dedent(
|
||||
`
|
||||
---
|
||||
title: ${title}
|
||||
taxonomy:
|
||||
category:
|
||||
- docs
|
||||
visible: true
|
||||
highlight:
|
||||
enabled: false
|
||||
---
|
||||
`
|
||||
---
|
||||
title: ${title}
|
||||
taxonomy:
|
||||
category:
|
||||
- docs
|
||||
visible: true
|
||||
highlight:
|
||||
enabled: false
|
||||
---
|
||||
`
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -249,35 +250,35 @@ function makeMdSource(title) {
|
|||
function makeTwigFile(contentHtml) {
|
||||
return dedent(
|
||||
`
|
||||
{% extends 'partials/base_noGit.html.twig' %}
|
||||
{% set tags = page.taxonomy.tag %}
|
||||
{% if tags %}
|
||||
{% set progress = page.collection({'items':{'@taxonomy':{'category': 'docs', 'tag': tags}},'order': {'by': 'default', 'dir': 'asc'}}) %}
|
||||
{% else %}
|
||||
{% set progress = page.collection({'items':{'@taxonomy':{'category': 'docs'}},'order': {'by': 'default', 'dir': 'asc'}}) %}
|
||||
{% endif %}
|
||||
|
||||
{% block navigation %}
|
||||
<div id="navigation">
|
||||
{% if not progress.isFirst(page.path) %}
|
||||
<a class="nav nav-prev" href="{{ progress.nextSibling(page.path).url }}"> <img src="{{ url('theme://images/left-arrow.png') }}"></a>
|
||||
{% extends 'partials/base_noGit.html.twig' %}
|
||||
{% set tags = page.taxonomy.tag %}
|
||||
{% if tags %}
|
||||
{% set progress = page.collection({'items':{'@taxonomy':{'category': 'docs', 'tag': tags}},'order': {'by': 'default', 'dir': 'asc'}}) %}
|
||||
{% else %}
|
||||
{% set progress = page.collection({'items':{'@taxonomy':{'category': 'docs'}},'order': {'by': 'default', 'dir': 'asc'}}) %}
|
||||
{% endif %}
|
||||
|
||||
{% if not progress.isLast(page.path) %}
|
||||
<a class="nav nav-next" href="{{ progress.prevSibling(page.path).url }}"><img src="{{ url('theme://images/right-arrow.png') }}"></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="api-specific">
|
||||
<div id="body-inner">
|
||||
<h1>{{ page.title }}</h1>
|
||||
${contentHtml}
|
||||
|
||||
{% block navigation %}
|
||||
<div id="navigation">
|
||||
{% if not progress.isFirst(page.path) %}
|
||||
<a class="nav nav-prev" href="{{ progress.nextSibling(page.path).url }}"> <img src="{{ url('theme://images/left-arrow.png') }}"></a>
|
||||
{% endif %}
|
||||
|
||||
{% if not progress.isLast(page.path) %}
|
||||
<a class="nav nav-next" href="{{ progress.prevSibling(page.path).url }}"><img src="{{ url('theme://images/right-arrow.png') }}"></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
`
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="api-specific">
|
||||
<div id="body-inner">
|
||||
<h1>{{ page.title }}</h1>
|
||||
${contentHtml}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
`
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -315,388 +316,363 @@ function makeGroupTOC(group) {
|
|||
let htmlGroup = mappedGroup.map(item => {
|
||||
return dedent(
|
||||
`
|
||||
<div>
|
||||
<a href="/api-reference/${
|
||||
!Array.isArray(group)
|
||||
? `${group.toLowerCase()}/` + item.toLowerCase()
|
||||
: item.toLowerCase()
|
||||
}/">${item}</a>
|
||||
</div>
|
||||
`
|
||||
)
|
||||
})
|
||||
return htmlGroup.join("\n");
|
||||
}
|
||||
<div>
|
||||
<a href="/api-reference/${
|
||||
!Array.isArray(group)
|
||||
? `${group.toLowerCase()}/` + item.toLowerCase()
|
||||
: item.toLowerCase()
|
||||
}/">${item}</a>
|
||||
</div>
|
||||
`
|
||||
)
|
||||
})
|
||||
return htmlGroup.join("\n");
|
||||
}
|
||||
|
||||
// Handle Class TOCS
|
||||
function makeClassTOC(group){
|
||||
let linkArray = []
|
||||
group.forEach( item => {
|
||||
linkArray.push(`<div><h5>${item.type}</h5></div>`)
|
||||
item.array.forEach( link => {
|
||||
if ( link.indexOf('.') > -1 ){
|
||||
linkArray.push(`<div><a href="#${link}">${link.slice(1)}</a></div>`);
|
||||
} else {
|
||||
linkArray.push(`<div><a href="#${link}">${link}</a></div>`);
|
||||
|
||||
// Handle Class TOCS
|
||||
function makeClassTOC(group){
|
||||
let linkArray = []
|
||||
group.forEach( item => {
|
||||
linkArray.push(`<div><h5>${item.type}</h5></div>`)
|
||||
item.array.forEach( link => {
|
||||
if ( link.indexOf('.') > -1 ){
|
||||
linkArray.push(`<div><a href="#${link}">${link.slice(1)}</a></div>`);
|
||||
} else {
|
||||
linkArray.push(`<div><a href="#${link}">${link}</a></div>`);
|
||||
|
||||
}
|
||||
})
|
||||
linkArray.push("<br>");
|
||||
})
|
||||
return linkArray.join("\n");
|
||||
}
|
||||
|
||||
// Extract IDS for TOC
|
||||
function extractIDs(groupToExtract){
|
||||
let firstLine = "";
|
||||
let id = "";
|
||||
let extractedIDs = [];
|
||||
groupToExtract.forEach((item)=>{
|
||||
firstLine = item.split("\n")[0];
|
||||
try {
|
||||
id = firstLine.split('id="')[1].split(`"`)[0];
|
||||
} catch (e){
|
||||
id = "";
|
||||
}
|
||||
if (id){
|
||||
extractedIDs.push(id)
|
||||
}
|
||||
})
|
||||
linkArray.push("<br>");
|
||||
})
|
||||
return linkArray.join("\n");
|
||||
}
|
||||
return extractedIDs;
|
||||
}
|
||||
|
||||
// Extract IDS for TOC
|
||||
function extractIDs(groupToExtract){
|
||||
let firstLine = "";
|
||||
let id = "";
|
||||
let extractedIDs = [];
|
||||
groupToExtract.forEach((item)=>{
|
||||
firstLine = item.split("\n")[0];
|
||||
try {
|
||||
id = firstLine.split('id="')[1].split(`"`)[0];
|
||||
} catch (e){
|
||||
id = "";
|
||||
}
|
||||
if (id){
|
||||
extractedIDs.push(id)
|
||||
}
|
||||
})
|
||||
return extractedIDs;
|
||||
}
|
||||
|
||||
// Helper for splitting up html
|
||||
// Takes: Content to split, SearchTerm to Split by, and term to End Splitting By
|
||||
// Returns: [newContent after Split, Array of extracted ]
|
||||
function splitBy(content, searchTerm, endSplitTerm, title){
|
||||
let foundArray = [];
|
||||
let curIndex = -1;
|
||||
let afterCurSearchIndex = -1
|
||||
let nextIndex = 0;
|
||||
let findbyNameLength = searchTerm.length;
|
||||
let curEndSplitTermIndex = -1;
|
||||
let classHeader;
|
||||
do {
|
||||
// Find the index of where to stop searching
|
||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||
// console.log("curEndSplitTermIndex", curEndSplitTermIndex)
|
||||
// Find the index of the the next Search term
|
||||
curIndex = content.indexOf(searchTerm);
|
||||
// console.log("curIndex", curIndex)
|
||||
|
||||
// The index of where the next search will start
|
||||
afterCurSearchIndex = curIndex+findbyNameLength;
|
||||
// Find the content of the next Index
|
||||
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||
// If the next index isn't found, then next index === index of the end term
|
||||
if (nextIndex === -1){
|
||||
nextIndex = curEndSplitTermIndex;
|
||||
}
|
||||
if (curIndex > curEndSplitTermIndex){
|
||||
break;
|
||||
}
|
||||
// Push from the cur index to the next found || the end term
|
||||
let contentSlice = content.slice(curIndex, nextIndex);
|
||||
if (contentSlice.indexOf(`id="${title}"`) === -1){
|
||||
foundArray.push(contentSlice);
|
||||
} else {
|
||||
classHeader = contentSlice;
|
||||
}
|
||||
|
||||
// Remove that content
|
||||
content = content.replace(contentSlice, "");
|
||||
|
||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||
// Handle if nextIndex goes beyond endSplitTerm
|
||||
if (nextIndex > curEndSplitTermIndex) {
|
||||
// Helper for splitting up html
|
||||
// Takes: Content to split, SearchTerm to Split by, and term to End Splitting By
|
||||
// Returns: [newContent after Split, Array of extracted ]
|
||||
function splitBy(content, searchTerm, endSplitTerm, title){
|
||||
let foundArray = [];
|
||||
let curIndex = -1;
|
||||
let afterCurSearchIndex = -1
|
||||
let nextIndex = 0;
|
||||
let findbyNameLength = searchTerm.length;
|
||||
let curEndSplitTermIndex = -1;
|
||||
let classHeader;
|
||||
do {
|
||||
// Find the index of where to stop searching
|
||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||
// console.log("curEndSplitTermIndex", curEndSplitTermIndex)
|
||||
// Find the index of the the next Search term
|
||||
curIndex = content.indexOf(searchTerm);
|
||||
contentSlice = content.slice(curIndex, curEndSplitTermIndex);
|
||||
// console.log("curIndex", curIndex)
|
||||
|
||||
// The index of where the next search will start
|
||||
afterCurSearchIndex = curIndex+findbyNameLength;
|
||||
// Find the content of the next Index
|
||||
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||
// If the next index isn't found, then next index === index of the end term
|
||||
if (nextIndex === -1){
|
||||
nextIndex = curEndSplitTermIndex;
|
||||
}
|
||||
if (curIndex > curEndSplitTermIndex){
|
||||
break;
|
||||
}
|
||||
// Push from the cur index to the next found || the end term
|
||||
let contentSlice = content.slice(curIndex, nextIndex);
|
||||
if (contentSlice.indexOf(`id="${title}"`) === -1){
|
||||
foundArray.push(contentSlice);
|
||||
} else {
|
||||
classHeader = contentSlice;
|
||||
}
|
||||
|
||||
// Remove that content
|
||||
content = content.replace(contentSlice, "");
|
||||
break;
|
||||
|
||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||
// Handle if nextIndex goes beyond endSplitTerm
|
||||
if (nextIndex > curEndSplitTermIndex) {
|
||||
curIndex = content.indexOf(searchTerm);
|
||||
contentSlice = content.slice(curIndex, curEndSplitTermIndex);
|
||||
if (contentSlice.indexOf(`id="${title}"`) === -1){
|
||||
foundArray.push(contentSlice);
|
||||
}
|
||||
content = content.replace(contentSlice, "");
|
||||
break;
|
||||
}
|
||||
} while (curIndex > -1)
|
||||
if (classHeader){
|
||||
content = append(content, html_reg_findByArticleClose, classHeader, true);
|
||||
}
|
||||
} while (curIndex > -1)
|
||||
if (classHeader){
|
||||
content = append(content, html_reg_findByArticleClose, classHeader, true);
|
||||
return [content, foundArray];
|
||||
}
|
||||
return [content, foundArray];
|
||||
}
|
||||
|
||||
// Split the signals and methods [Might make this more generic]
|
||||
function splitMethodsSignals(allItemToSplit){
|
||||
let methodArray = [];
|
||||
let signalArray = [];
|
||||
|
||||
allItemToSplit.forEach( (content, index) => {
|
||||
firstLine = content.split("\n")[0];
|
||||
if (firstLine.indexOf("{Signal}") > -1){
|
||||
signalArray.push(content);
|
||||
} else if (firstLine.indexOf("span") > -1) {
|
||||
methodArray.push(content);
|
||||
} else {
|
||||
}
|
||||
})
|
||||
return [methodArray, signalArray];
|
||||
}
|
||||
|
||||
// Helper to append
|
||||
// Takes content, the search term to appendTo, the content to append,
|
||||
// and bool if the append is before the found area
|
||||
function append(content, searchTermToAppendto, contentToAppend, appendBefore){
|
||||
let contentArray = content.split("\n");
|
||||
let foundIndex = findArrayTrim(contentArray, searchTermToAppendto)
|
||||
foundIndex = appendBefore ? foundIndex : foundIndex +1
|
||||
|
||||
contentArray.splice(foundIndex,0,contentToAppend)
|
||||
return contentArray.join("\n")
|
||||
}
|
||||
|
||||
// Helper function for append
|
||||
function findArrayTrim(array, searchTerm){
|
||||
var index = -1;
|
||||
for (var i = 0; i < array.length; i++){
|
||||
index = array[i].trim().indexOf(searchTerm.trim());
|
||||
if (index > -1){
|
||||
return i
|
||||
}
|
||||
// Split the signals and methods [Might make this more generic]
|
||||
function splitMethodsSignals(allItemToSplit){
|
||||
let methodArray = [];
|
||||
let signalArray = [];
|
||||
|
||||
allItemToSplit.forEach( (content, index) => {
|
||||
firstLine = content.split("\n")[0];
|
||||
if (firstLine.indexOf("{Signal}") > -1){
|
||||
signalArray.push(content);
|
||||
} else if (firstLine.indexOf("span") > -1) {
|
||||
methodArray.push(content);
|
||||
} else {
|
||||
}
|
||||
})
|
||||
return [methodArray, signalArray];
|
||||
}
|
||||
|
||||
// Helper to append
|
||||
// Takes content, the search term to appendTo, the content to append,
|
||||
// and bool if the append is before the found area
|
||||
function append(content, searchTermToAppendto, contentToAppend, appendBefore){
|
||||
let contentArray = content.split("\n");
|
||||
let foundIndex = findArrayTrim(contentArray, searchTermToAppendto)
|
||||
foundIndex = appendBefore ? foundIndex : foundIndex +1
|
||||
|
||||
contentArray.splice(foundIndex,0,contentToAppend)
|
||||
return contentArray.join("\n")
|
||||
}
|
||||
|
||||
// Helper function for append
|
||||
function findArrayTrim(array, searchTerm){
|
||||
var index = -1;
|
||||
for (var i = 0; i < array.length; i++){
|
||||
index = array[i].trim().indexOf(searchTerm.trim());
|
||||
if (index > -1){
|
||||
return i
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
// Remove grav directory if exists to make sure old files aren't kept
|
||||
if (fs.existsSync(dir_grav)){
|
||||
console.log("dir_grav exists");
|
||||
rimraf.sync(dir_grav);
|
||||
}
|
||||
if (fs.existsSync(dir_grav)){
|
||||
console.log("dir_grav exists");
|
||||
rimraf.sync(dir_grav);
|
||||
}
|
||||
|
||||
// Create Grav directories in JSDOC output
|
||||
dirArray.forEach(function(dir){
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
})
|
||||
dirArray.forEach(function(dir){
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
})
|
||||
|
||||
// Create baseMD files
|
||||
baseMDDirectories.forEach( md => {
|
||||
createMD(md, map_dir_md[md]);
|
||||
})
|
||||
baseMDDirectories.forEach( md => {
|
||||
createMD(md, map_dir_md[md]);
|
||||
})
|
||||
|
||||
// Read jsdoc output folder and process html files
|
||||
let links = [];
|
||||
let unTouchedLinks = [];
|
||||
let links = [];
|
||||
let unTouchedLinks = [];
|
||||
|
||||
let files = fs.readdirSync(dir_out);
|
||||
// Create initial Group name member map to handle individual link :: TODO find better way to do this
|
||||
files.forEach(function (file){
|
||||
let curSource = path.join(dir_out, file);
|
||||
if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") {
|
||||
let loadedHtml = prepareHtml(curSource);
|
||||
let splitTitle = loadedHtml("title").text().split(": ");
|
||||
let groupName = splitTitle[1];
|
||||
let htmlTitle = splitTitle.pop();
|
||||
let files = fs.readdirSync(dir_out);
|
||||
// Create initial Group name member map to handle individual link
|
||||
files.forEach(function (file){
|
||||
let curSource = path.join(dir_out, file);
|
||||
if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") {
|
||||
let loadedHtml = prepareHtml(curSource);
|
||||
let splitTitle = loadedHtml("title").text().split(": ");
|
||||
let groupName = splitTitle[1];
|
||||
let htmlTitle = splitTitle.pop();
|
||||
switch(groupName){
|
||||
case "Namespace":
|
||||
groupNameMemberMap["Namespaces"].push(htmlTitle);
|
||||
break;
|
||||
case "Class":
|
||||
groupNameMemberMap["Objects"].push(htmlTitle);
|
||||
break;
|
||||
default:
|
||||
console.log(`Case not handled for ${groupName}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
files.forEach(function (file, index){
|
||||
// For testing individual files
|
||||
// if (index !== 59) return;
|
||||
let curSource = path.join(dir_out, file);
|
||||
if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") {
|
||||
// Clean up the html source
|
||||
let loadedHtml = prepareHtml(curSource);
|
||||
|
||||
// Extract the title, group name, and the main div
|
||||
let splitTitle = loadedHtml("title").text().split(": ");
|
||||
let groupName = splitTitle[1];
|
||||
let htmlTitle = splitTitle.pop();
|
||||
console.log("html title", htmlTitle)
|
||||
let mainDiv = loadedHtml("#main")
|
||||
|
||||
let methodIDs = [];
|
||||
let signalIDs = [];
|
||||
let typeDefIDs = [];
|
||||
// Basic Regex HTML edits
|
||||
let currentContent = mainDiv.html()
|
||||
.replace(html_reg_findByMethod, "") //Remove Method title to be remade later
|
||||
.replace(html_reg_static,"") // Remove static from the file names
|
||||
.replace(html_reg_title,"") // Remove title
|
||||
.replace(html_reg_objectHeader,"") // Remove extra Object Header
|
||||
// .replace(html_reg_htmlExt,"")
|
||||
.replace(html_reg_dlClassDetails, "") // Remove unneccsary dlClassDetails Tag
|
||||
.replace(html_reg_allNonHTTPLinks, removeHTML) // Remove the .html extension from all links
|
||||
.replace(html_reg_allNonHTTPLinks, allLinksToLowerCase) // Turn all links into lowercase before ID tags
|
||||
.replace(html_reg_allNonHTTPLinks, fixLinkGrouping) // Make sure links refer to correct grouping
|
||||
.replace(html_reg_propertiesHeaderEdit, html_reg_propertiesHeaderEdit_Replace) // Remove : from Properties
|
||||
.replace(html_reg_typeEdit, html_reg_typeEdit_replace) // Put type on the same line
|
||||
.replace(html_reg_returnSize, html_reg_returnSize_replace) // Make return size h6 instead of h5
|
||||
.replace(html_reg_methodSize, html_reg_methodSize_replace) // Make method size into h5
|
||||
.replace(html_reg_pretty, html_reg_pretty_replace) // remove the references to pretty
|
||||
.replace(html_reg_classDefinitonsTitle, html_reg_classDefinitonsTitle_replace) // Change the class def titles
|
||||
.replace(html_reg_depreciated, html_reg_depreciated_replace); // format depreciated better
|
||||
|
||||
// Further HTML Manipulation
|
||||
// Make end term either Type Definitions or by the article
|
||||
let endTerm;
|
||||
let foundTypeDefinitions;
|
||||
let foundSignalsAndMethods;
|
||||
if (currentContent.indexOf("Type Definitions") > -1){
|
||||
// console.log("Found Type Definitions");
|
||||
endTerm = `<h3 class="subsection-title">Type Definitions</h3>`;
|
||||
// Split HTML by Each named entry
|
||||
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm, htmlTitle);
|
||||
foundSignalsAndMethods = contentSplitArray[1];
|
||||
// console.log("foundSignalsAndMethods", foundSignalsAndMethods)
|
||||
// Create a reference to the current content after split and the split functions
|
||||
currentContent = contentSplitArray[0]
|
||||
.replace(html_reg_typeDefType, html_reg_typeDefType_replace) // Edit how the typedef type looks
|
||||
.replace(html_reg_typeDefinitonsTitle, ""); // Remove Type Definitions Title to be remade later;
|
||||
endTerm = html_reg_findByArticleClose;
|
||||
// Grab split Type Definitions
|
||||
let contentSplitArrayForTypeDefs = splitBy(currentContent, html_reg_findByName, endTerm, htmlTitle);
|
||||
currentContent = contentSplitArrayForTypeDefs[0];
|
||||
foundTypeDefinitions = contentSplitArrayForTypeDefs[1];
|
||||
// console.log("foundTypeDefinitions", foundTypeDefinitions)
|
||||
|
||||
} else {
|
||||
endTerm = html_reg_findByArticleClose;
|
||||
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm, htmlTitle);
|
||||
foundSignalsAndMethods = contentSplitArray[1];
|
||||
currentContent = contentSplitArray[0];
|
||||
}
|
||||
|
||||
// Create references to the split methods and signals
|
||||
let processedMethodsSignalsAndTypeDefs = splitMethodsSignals(foundSignalsAndMethods);
|
||||
let splitMethods = processedMethodsSignalsAndTypeDefs[0];
|
||||
let splitSignals = processedMethodsSignalsAndTypeDefs[1];
|
||||
let splitTypeDefinitionIDS;
|
||||
// let splitDescription = processedMethodsSignalsAndTypeDefs[3];
|
||||
let splitMethodIDS = extractIDs(splitMethods);
|
||||
let splitSignalIDS = extractIDs(splitSignals);
|
||||
if (foundTypeDefinitions){
|
||||
splitTypeDefinitionIDS = extractIDs(foundTypeDefinitions);
|
||||
}
|
||||
let arrayToPassToClassToc = [];
|
||||
|
||||
// if (splitDescription) {
|
||||
// currentContent = append(currentContent, html_reg_containerOverview, splitDescription);
|
||||
// }
|
||||
if (splitMethods.length > 0) {
|
||||
arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS});
|
||||
// Add the Signals header to the Signals HTML
|
||||
splitMethods.unshift(html_reg_findByMethod_replace)
|
||||
currentContent = append(currentContent, html_reg_findByArticleClose, splitMethods.join('\n'), true);
|
||||
}
|
||||
if (splitSignals.length > 0) {
|
||||
arrayToPassToClassToc.push({type: "Signals", array: splitSignalIDS});
|
||||
// Add the Signals header to the Signals HTML
|
||||
splitSignals.unshift(html_reg_signalTitle)
|
||||
currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true);
|
||||
}
|
||||
if (foundTypeDefinitions && foundTypeDefinitions.length > 0) {
|
||||
arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS});
|
||||
// Add the Signals header to the Signals HTML
|
||||
foundTypeDefinitions.unshift(html_reg_typeDefinitonsTitle_replace)
|
||||
currentContent = append(currentContent, html_reg_findByArticleClose, foundTypeDefinitions.join('\n'), true);
|
||||
}
|
||||
|
||||
let classTOC = makeClassTOC(arrayToPassToClassToc);
|
||||
if (groupName === "Global"){
|
||||
currentContent = append(currentContent, html_reg_findByTitle, classTOC);
|
||||
} else if (htmlTitle === "Controller") {
|
||||
// currentContent = currentContent.replace(html_reg_availableIn, "");
|
||||
let curatedList = currentContent.match(html_reg_findControllerCuratedList);
|
||||
currentContent = currentContent.replace(html_reg_findControllerCuratedList, "");
|
||||
let entityMethods = currentContent.match(html_reg_findEntityMethods);
|
||||
currentContent = currentContent.replace(html_reg_findEntityMethods, "");
|
||||
currentContent = append(currentContent, html_reg_firstDivClose, [classTOC, curatedList, entityMethods].join("\n"));
|
||||
currentContent = currentContent.replace(html_reg_EntityMethodsHeader, html_reg_EntityMethodsHeader_replace);
|
||||
} else {
|
||||
currentContent = append(currentContent, html_reg_firstDivClose, classTOC);
|
||||
}
|
||||
|
||||
// Final Pretty Content
|
||||
currentContent = htmlclean(currentContent);
|
||||
currentContent = pretty(currentContent);
|
||||
|
||||
// Handle Unique Categories
|
||||
switch(groupName){
|
||||
case "Namespace":
|
||||
groupNameMemberMap["Namespaces"].push(htmlTitle);
|
||||
handleNamespace(htmlTitle, currentContent);
|
||||
break;
|
||||
case "Class":
|
||||
groupNameMemberMap["Objects"].push(htmlTitle);
|
||||
handleClass(htmlTitle, currentContent);
|
||||
break;
|
||||
case "Global":
|
||||
handleGlobal(htmlTitle, currentContent);
|
||||
break;
|
||||
default:
|
||||
console.log(`Case not handled for ${groupName}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
files.forEach(function (file, index){
|
||||
// For testing individual files
|
||||
// if (index !== 59) return;
|
||||
let curSource = path.join(dir_out, file);
|
||||
if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") {
|
||||
// Clean up the html source
|
||||
let loadedHtml = prepareHtml(curSource);
|
||||
|
||||
// Extract the title, group name, and the main div
|
||||
let splitTitle = loadedHtml("title").text().split(": ");
|
||||
let groupName = splitTitle[1];
|
||||
let htmlTitle = splitTitle.pop();
|
||||
console.log("html title", htmlTitle)
|
||||
let mainDiv = loadedHtml("#main")
|
||||
|
||||
let methodIDs = [];
|
||||
let signalIDs = [];
|
||||
let typeDefIDs = [];
|
||||
// Basic Regex HTML edits
|
||||
let currentContent = mainDiv.html()
|
||||
.replace(html_reg_findByMethod, "") //Remove Method title to be remade later
|
||||
.replace(html_reg_static,"") // Remove static from the file names
|
||||
.replace(html_reg_title,"") // Remove title
|
||||
.replace(html_reg_objectHeader,"") // Remove extra Object Header
|
||||
// .replace(html_reg_htmlExt,"")
|
||||
.replace(html_reg_dlClassDetails, "") // Remove unneccsary dlClassDetails Tag
|
||||
.replace(html_reg_allNonHTTPLinks, removeHTML) // Remove the .html extension from all links
|
||||
.replace(html_reg_allNonHTTPLinks, allLinksToLowerCase) // Turn all links into lowercase before ID tags
|
||||
.replace(html_reg_allNonHTTPLinks, fixLinkGrouping) // Make sure links refer to correct grouping
|
||||
.replace(html_reg_propertiesHeaderEdit, html_reg_propertiesHeaderEdit_Replace) // Remove : from Properties
|
||||
.replace(html_reg_typeEdit, html_reg_typeEdit_replace) // Put type on the same line
|
||||
.replace(html_reg_returnSize, html_reg_returnSize_replace) // make return size h6 instead of h5
|
||||
.replace(html_reg_methodSize, html_reg_methodSize_replace) // make method size into h5
|
||||
.replace(html_reg_pretty, html_reg_pretty_replace)
|
||||
.replace(html_reg_classDefinitonsTitle, html_reg_classDefinitonsTitle_replace)
|
||||
.replace(html_reg_depreciated, html_reg_depreciated_replace); // format depreciated better
|
||||
|
||||
// Further HTML Manipulation
|
||||
// Make end term either Type Definitions or by the article
|
||||
let endTerm;
|
||||
let foundTypeDefinitions;
|
||||
let foundSignalsAndMethods;
|
||||
if (currentContent.indexOf("Type Definitions") > -1){
|
||||
// console.log("Found Type Definitions");
|
||||
endTerm = `<h3 class="subsection-title">Type Definitions</h3>`;
|
||||
// Split HTML by Each named entry
|
||||
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm, htmlTitle);
|
||||
foundSignalsAndMethods = contentSplitArray[1];
|
||||
// console.log("foundSignalsAndMethods", foundSignalsAndMethods)
|
||||
// Create a reference to the current content after split and the split functions
|
||||
currentContent = contentSplitArray[0]
|
||||
.replace(html_reg_typeDefType, html_reg_typeDefType_replace) // Edit how the typedef type looks
|
||||
.replace(html_reg_typeDefinitonsTitle, ""); // Remove Type Definitions Title to be remade later;
|
||||
endTerm = html_reg_findByArticleClose;
|
||||
// Grab split Type Definitions
|
||||
let contentSplitArrayForTypeDefs = splitBy(currentContent, html_reg_findByName, endTerm, htmlTitle);
|
||||
currentContent = contentSplitArrayForTypeDefs[0];
|
||||
foundTypeDefinitions = contentSplitArrayForTypeDefs[1];
|
||||
// console.log("foundTypeDefinitions", foundTypeDefinitions)
|
||||
|
||||
} else {
|
||||
endTerm = html_reg_findByArticleClose;
|
||||
let contentSplitArray = splitBy(currentContent, html_reg_findByName, endTerm, htmlTitle);
|
||||
foundSignalsAndMethods = contentSplitArray[1];
|
||||
currentContent = contentSplitArray[0];
|
||||
}
|
||||
|
||||
// Create references to the split methods and signals
|
||||
let processedMethodsSignalsAndTypeDefs = splitMethodsSignals(foundSignalsAndMethods);
|
||||
let splitMethods = processedMethodsSignalsAndTypeDefs[0];
|
||||
let splitSignals = processedMethodsSignalsAndTypeDefs[1];
|
||||
let splitTypeDefinitionIDS;
|
||||
// let splitDescription = processedMethodsSignalsAndTypeDefs[3];
|
||||
let splitMethodIDS = extractIDs(splitMethods);
|
||||
let splitSignalIDS = extractIDs(splitSignals);
|
||||
if (foundTypeDefinitions){
|
||||
splitTypeDefinitionIDS = extractIDs(foundTypeDefinitions);
|
||||
}
|
||||
let arrayToPassToClassToc = [];
|
||||
|
||||
// if (splitDescription) {
|
||||
// currentContent = append(currentContent, html_reg_containerOverview, splitDescription);
|
||||
// }
|
||||
if (splitMethods.length > 0) {
|
||||
arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS});
|
||||
// Add the Signals header to the Signals HTML
|
||||
splitMethods.unshift(html_reg_findByMethod_replace)
|
||||
currentContent = append(currentContent, html_reg_findByArticleClose, splitMethods.join('\n'), true);
|
||||
}
|
||||
if (splitSignals.length > 0) {
|
||||
arrayToPassToClassToc.push({type: "Signals", array: splitSignalIDS});
|
||||
// Add the Signals header to the Signals HTML
|
||||
splitSignals.unshift(html_reg_signalTitle)
|
||||
currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true);
|
||||
}
|
||||
if (foundTypeDefinitions && foundTypeDefinitions.length > 0) {
|
||||
arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS});
|
||||
// Add the Signals header to the Signals HTML
|
||||
foundTypeDefinitions.unshift(html_reg_typeDefinitonsTitle_replace)
|
||||
currentContent = append(currentContent, html_reg_findByArticleClose, foundTypeDefinitions.join('\n'), true);
|
||||
}
|
||||
|
||||
let classTOC = makeClassTOC(arrayToPassToClassToc);
|
||||
if (groupName === "Global"){
|
||||
currentContent = append(currentContent, html_reg_findByTitle, classTOC);
|
||||
} else if (htmlTitle === "Controller") {
|
||||
// currentContent = currentContent.replace(html_reg_availableIn, "");
|
||||
let curatedList = currentContent.match(html_reg_findControllerCuratedList);
|
||||
currentContent = currentContent.replace(html_reg_findControllerCuratedList, "");
|
||||
let entityMethods = currentContent.match(html_reg_findEntityMethods);
|
||||
currentContent = currentContent.replace(html_reg_findEntityMethods, "");
|
||||
currentContent = append(currentContent, html_reg_firstDivClose, [classTOC, curatedList, entityMethods].join("\n"));
|
||||
currentContent = currentContent.replace(html_reg_EntityMethodsHeader, html_reg_EntityMethodsHeader_replace);
|
||||
} else {
|
||||
currentContent = append(currentContent, html_reg_firstDivClose, classTOC);
|
||||
}
|
||||
|
||||
// Final Pretty Content
|
||||
currentContent = htmlclean(currentContent);
|
||||
currentContent = pretty(currentContent);
|
||||
|
||||
// Handle Unique Categories
|
||||
switch(groupName){
|
||||
case "Namespace":
|
||||
handleNamespace(htmlTitle, currentContent);
|
||||
break;
|
||||
case "Class":
|
||||
handleClass(htmlTitle, currentContent);
|
||||
break;
|
||||
case "Global":
|
||||
handleGlobal(htmlTitle, currentContent);
|
||||
break;
|
||||
default:
|
||||
console.log(`Case not handled for ${groupName}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// Create the base Templates after processing individual files
|
||||
createTemplate("API-Reference", makeGroupTOC(["Namespaces", "Objects", "Globals"]));
|
||||
createTemplate("Namespaces", makeGroupTOC("Namespaces"));
|
||||
createTemplate("Objects", makeGroupTOC("Objects"));
|
||||
createTemplate("API-Reference", makeGroupTOC(["Namespaces", "Objects", "Globals"]));
|
||||
createTemplate("Namespaces", makeGroupTOC("Namespaces"));
|
||||
createTemplate("Objects", makeGroupTOC("Objects"));
|
||||
|
||||
// Copy the files to the target Directories if Local
|
||||
if (copyLocal){
|
||||
// Copy files to the Twig Directory
|
||||
let templateFiles = fs.readdirSync(path.resolve(targetTemplateDirectory));
|
||||
// Remove Existing API files
|
||||
templateFiles.forEach(function(file){
|
||||
let curSource = path.join(targetTemplateDirectory, file);
|
||||
|
||||
if(path.basename(file, '.html').indexOf("API") > -1){
|
||||
fs.unlink(curSource);
|
||||
}
|
||||
if (copyLocal){
|
||||
// Copy files to the Twig Directory
|
||||
let templateFiles = fs.readdirSync(path.resolve(targetTemplateDirectory));
|
||||
// Remove Existing API files
|
||||
templateFiles.forEach(function(file){
|
||||
let curSource = path.join(targetTemplateDirectory, file);
|
||||
|
||||
})
|
||||
copyFolderRecursiveSync(dir_template, targetTemplateDirectory);
|
||||
|
||||
// Copy files to the Md Directory
|
||||
let baseMdRefDir = path.join(targetMDDirectory,"06.api-reference");
|
||||
// Remove existing MD directory
|
||||
if (fs.existsSync(baseMdRefDir)){
|
||||
rimraf.sync(baseMdRefDir);
|
||||
if(path.basename(file, '.html').indexOf("API") > -1){
|
||||
fs.unlink(curSource);
|
||||
}
|
||||
copyFolderRecursiveSync(dir_md, targetMDDirectory);
|
||||
|
||||
})
|
||||
copyFolderRecursiveSync(dir_template, targetTemplateDirectory);
|
||||
|
||||
// Copy files to the Md Directory
|
||||
let baseMdRefDir = path.join(targetMDDirectory,"06.api-reference");
|
||||
// Remove existing MD directory
|
||||
if (fs.existsSync(baseMdRefDir)){
|
||||
rimraf.sync(baseMdRefDir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
const html_reg_subsectionEdit_replace = '<h4 class="subsection-title">$2</h4>';
|
||||
const html_reg_subsectionEdit = /(<h. class="subsection-title">)([\s\S]*?)(<\/h.>)/g;
|
||||
const html_reg_brRemove = /<br>[\s\S]+?<br>/;
|
||||
const html_reg_typeDefSize = /(<h4)( class="name"[\s\S]*?)(<\/h4>\n)/g;
|
||||
const html_reg_typeDefSize_replace = '<h5$2</h5>';
|
||||
const html_reg_typeReturnSize = /<h5>Type:\<\/h5>/g;
|
||||
const html_reg_typeReturnSize_replace = '<h6>Type:<h6>';
|
||||
const html_reg_containerOverview = `<div class="container-overview">`
|
||||
|
||||
const html_reg_findByArticleOpen = `<article>`
|
||||
const html_reg_fixLinkHashIssue = /(<a href=")(.*?)(\.)(.*?">)/g;
|
||||
const html_reg_fixLinkHashIssue_replace = "$1$2#$4"
|
||||
const html_reg_findLinks = /(<a href="[\s\S]+?<\/a>)/g;
|
||||
const html_reg_findLinksNoHashes = /(<a href=")([^#]+?)(">[\s\S]+?<\/a>)/g;
|
||||
const html_reg_findGeneralLinks = /(<a href=")([A-Z])([\s\S]*?)("[\s\S]*?<\/a>)/g;
|
||||
const html_reg_findClassLinks = /(<a href=")([\.|\w]+?)(#[\.|\w]+?)(">[\s\S]+?<\/a>)/g;
|
||||
const html_reg_findControllerPropertiesHeader = "<h5>Properties</h5>";
|
||||
|
||||
// .replace(html_reg_brRemove, "") // Remove extra Brs
|
||||
// .replace(html_reg_code, html_reg_code_replace)
|
||||
*/
|
||||
copyFolderRecursiveSync(dir_md, targetMDDirectory);
|
||||
}
|
Loading…
Reference in a new issue