mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 02:16:56 +02:00
saved before laptop acts up more
This commit is contained in:
parent
aeb78e69f6
commit
ae935dcda5
4 changed files with 323 additions and 4954 deletions
1
tools/jsdoc/.gitignore
vendored
1
tools/jsdoc/.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
out
|
out
|
||||||
grav.bat
|
grav.bat
|
||||||
|
gravE.bat
|
||||||
gravPrep-Explore
|
gravPrep-Explore
|
||||||
Examine
|
Examine
|
File diff suppressed because it is too large
Load diff
|
@ -7,6 +7,16 @@
|
||||||
const rimraf = require('rimraf');
|
const rimraf = require('rimraf');
|
||||||
const dedent = require('dedent-js');
|
const dedent = require('dedent-js');
|
||||||
|
|
||||||
|
// Arg Vars
|
||||||
|
const copyLocal = process.argv[2];
|
||||||
|
console.log("copyLocal:", copyLocal);
|
||||||
|
let targetTemplateDirectory = ''
|
||||||
|
let targetMDDirectory = ''
|
||||||
|
if (copyLocal){
|
||||||
|
targetTemplateDirectory = process.argv[3];
|
||||||
|
targetMDDirectory = process.argv[4];;
|
||||||
|
}
|
||||||
|
|
||||||
// Required directories
|
// Required directories
|
||||||
let dir_out = path.join(__dirname, 'out');
|
let dir_out = path.join(__dirname, 'out');
|
||||||
|
|
||||||
|
@ -19,11 +29,7 @@
|
||||||
let dir_md_objects = path.join(dir_md, '02.Objects');
|
let dir_md_objects = path.join(dir_md, '02.Objects');
|
||||||
let dir_md_namespaces = path.join(dir_md, '01.Namespaces');
|
let dir_md_namespaces = path.join(dir_md, '01.Namespaces');
|
||||||
let dir_md_globals = path.join(dir_md, '03.Globals');
|
let dir_md_globals = path.join(dir_md, '03.Globals');
|
||||||
|
|
||||||
// Target Copy Directories
|
|
||||||
let targetTemplateDirectory = "D:/ROLC/Organize/O_Projects/Hifi/Docs/hifi-docs-grav/user/themes/learn2/";
|
|
||||||
let targetMDDirectory = "D:/ROLC/Organize/O_Projects/Hifi/Docs/hifi-docs-grav-content/";
|
|
||||||
|
|
||||||
// Array to itterate over and create if doesn't exist
|
// Array to itterate over and create if doesn't exist
|
||||||
let dirArray = [dir_grav, dir_css, dir_js, dir_template, dir_md, dir_md_objects, dir_md_namespaces, dir_md_globals];
|
let dirArray = [dir_grav, dir_css, dir_js, dir_template, dir_md, dir_md_objects, dir_md_namespaces, dir_md_globals];
|
||||||
|
|
||||||
|
@ -50,18 +56,22 @@
|
||||||
const html_reg_brRemove = /<br>[\s\S]+?<br>/;
|
const html_reg_brRemove = /<br>[\s\S]+?<br>/;
|
||||||
const html_reg_subsectionEdit = /(<h. class="subsection-title">)([\s\S]*?)(<\/h.>)/g;
|
const html_reg_subsectionEdit = /(<h. class="subsection-title">)([\s\S]*?)(<\/h.>)/g;
|
||||||
const html_reg_subsectionEdit_replace = '<h4 class="subsection-title">$2</h4>';
|
const html_reg_subsectionEdit_replace = '<h4 class="subsection-title">$2</h4>';
|
||||||
|
const html_reg_propertiesHeaderEdit = '<h4 class="subsection-title">Properties:</h4>';
|
||||||
|
const html_reg_propertiesHeaderEdit_Replace = '<h4 class="subsection-title">Properties</h4>';
|
||||||
const html_reg_typeEdit = /(<h5>Returns[\s\S]*?Type)(<\/dt[\s\S]*?type">)(.*?)(<\/span><\/dd>[\s\S]*?<\/dl>)/g;
|
const html_reg_typeEdit = /(<h5>Returns[\s\S]*?Type)(<\/dt[\s\S]*?type">)(.*?)(<\/span><\/dd>[\s\S]*?<\/dl>)/g;
|
||||||
const html_reg_typeEdit_replace = '$1: $3</dt></dl>'
|
const html_reg_typeEdit_replace = '$1: $3</dt></dl>'
|
||||||
const html_reg_methodSize = /(<h4)( class="name"[\s\S].*?<\/span>)(<\/h4>)/g;
|
const html_reg_methodSize = /(<h4)( class="name"[\s\S].*?<\/span>)(<\/h4>)/g;
|
||||||
const html_reg_methodSize_replace = '<h5$2</h5>';
|
const html_reg_methodSize_replace = '<h5$2</h5>';
|
||||||
|
const html_reg_typeDefSize = /(<h4)( class="name"[\s\S].*?)(<\/h4>)/g;
|
||||||
|
const html_reg_typeDefSize_replace = '<h5$2</h5>';
|
||||||
const html_reg_returnSize = /<h5>Returns:<\/h5>/g;
|
const html_reg_returnSize = /<h5>Returns:<\/h5>/g;
|
||||||
const html_reg_returnSize_replace = '<h6>Returns:<\/h6>';
|
const html_reg_returnSize_replace = '<h6>Returns:<\/h6>';
|
||||||
const html_reg_findByName = '<h5 class="name"';
|
const html_reg_findByName = '<h5 class="name"';
|
||||||
const html_reg_findByMethod = `<h4 class="subsection-title">Methods</h4>`
|
const html_reg_findByTitle = '<h1>';
|
||||||
|
const html_reg_findByMethod = `<h4 class="subsection-title">Methods</h4>`;
|
||||||
const html_reg_findByArticleClose = `</article>`
|
const html_reg_findByArticleClose = `</article>`
|
||||||
const html_reg_signalTitle = `<h4 class="subsection-title">Signals</h4>`;
|
const html_reg_signalTitle = `<h4 class="subsection-title">Signals</h4>`;
|
||||||
|
const html_reg_typeDefinitonsTitle = `<h4 class="subsection-title">Type Definitions</h4>`;
|
||||||
|
|
||||||
|
|
||||||
// Mapping for GroupNames and Members
|
// Mapping for GroupNames and Members
|
||||||
let groupNameMemberMap = {
|
let groupNameMemberMap = {
|
||||||
|
@ -71,6 +81,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Procedural functions
|
// Procedural functions
|
||||||
|
// Create the actual MD file
|
||||||
function createMD(title, directory, needsDir, isGlobal){
|
function createMD(title, directory, needsDir, isGlobal){
|
||||||
let mdSource = makeMdSource(title);
|
let mdSource = makeMdSource(title);
|
||||||
|
|
||||||
|
@ -84,14 +95,14 @@
|
||||||
fs.writeFileSync(destinationMDFile, mdSource);
|
fs.writeFileSync(destinationMDFile, mdSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create the actual Template file
|
||||||
function createTemplate(title,content){
|
function createTemplate(title,content){
|
||||||
// console.log("content:", content)
|
|
||||||
let twigBasePartial = makeTwigFile(content);
|
let twigBasePartial = makeTwigFile(content);
|
||||||
// console.log("TWIG BASE:", twigBasePartial)
|
|
||||||
let destinationFile = path.join(dir_template, `API_${title}.html.twig`);
|
let destinationFile = path.join(dir_template, `API_${title}.html.twig`);
|
||||||
fs.writeFileSync(destinationFile, twigBasePartial);
|
fs.writeFileSync(destinationFile, twigBasePartial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy file from source to target - used for recurssive call
|
||||||
function copyFileSync( source, target ) {
|
function copyFileSync( source, target ) {
|
||||||
let targetFile = target;
|
let targetFile = target;
|
||||||
|
|
||||||
|
@ -108,6 +119,7 @@
|
||||||
fs.writeFileSync(targetFile, fs.readFileSync(source));
|
fs.writeFileSync(targetFile, fs.readFileSync(source));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy file from source to target
|
||||||
function copyFolderRecursiveSync( source, target ) {
|
function copyFolderRecursiveSync( source, target ) {
|
||||||
var files = [];
|
var files = [];
|
||||||
|
|
||||||
|
@ -131,6 +143,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up the Html
|
||||||
function prepareHtml(source){
|
function prepareHtml(source){
|
||||||
let htmlBefore = fs.readFileSync(source, {encoding: 'utf8'});
|
let htmlBefore = fs.readFileSync(source, {encoding: 'utf8'});
|
||||||
let htmlAfter = htmlclean(htmlBefore);
|
let htmlAfter = htmlclean(htmlBefore);
|
||||||
|
@ -138,6 +151,7 @@
|
||||||
return cheerio.load(htmlAfterPretty);
|
return cheerio.load(htmlAfterPretty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base file for MD's
|
||||||
function makeMdSource(title){
|
function makeMdSource(title){
|
||||||
return dedent(
|
return dedent(
|
||||||
`
|
`
|
||||||
|
@ -152,6 +166,7 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base file for Templates
|
||||||
function makeTwigFile(contentHtml){
|
function makeTwigFile(contentHtml){
|
||||||
return dedent(
|
return dedent(
|
||||||
`
|
`
|
||||||
|
@ -185,15 +200,15 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle NameSpace Group
|
||||||
function handleNamespace(title, content){
|
function handleNamespace(title, content){
|
||||||
// console.log("Content from namespcae:", content)
|
|
||||||
groupNameMemberMap["Namespaces"].push(title);
|
groupNameMemberMap["Namespaces"].push(title);
|
||||||
let destinationDirectory = path.join(map_dir_md["Namespace"], title);
|
let destinationDirectory = path.join(map_dir_md["Namespace"], title);
|
||||||
|
|
||||||
createMD(title, destinationDirectory, true);
|
createMD(title, destinationDirectory, true);
|
||||||
createTemplate(title, content);
|
createTemplate(title, content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle Class Group
|
||||||
function handleClass(title, content){
|
function handleClass(title, content){
|
||||||
groupNameMemberMap["Objects"].push(title);
|
groupNameMemberMap["Objects"].push(title);
|
||||||
let destinationDirectory = path.join(map_dir_md["Class"], title);
|
let destinationDirectory = path.join(map_dir_md["Class"], title);
|
||||||
|
@ -201,18 +216,19 @@
|
||||||
|
|
||||||
let formatedHtml = content
|
let formatedHtml = content
|
||||||
.replace(html_reg_objectSpanNew,"")
|
.replace(html_reg_objectSpanNew,"")
|
||||||
.replace(html_reg_brRemove, "");
|
|
||||||
createTemplate(title, formatedHtml);
|
createTemplate(title, formatedHtml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle Global Group
|
||||||
function handleGlobal(title, content){
|
function handleGlobal(title, content){
|
||||||
groupNameMemberMap["Globals"].push("Globals");
|
groupNameMemberMap["Globals"].push("Globals");
|
||||||
createMD("Globals", map_dir_md["Global"], false, true);
|
createMD("Globals", map_dir_md["Global"], false, true);
|
||||||
createTemplate("Globals", content);
|
createTemplate("Globals", content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle Group TOCs
|
||||||
function makeGroupTOC(group){
|
function makeGroupTOC(group){
|
||||||
let mappedGroup;
|
let mappedGroup;
|
||||||
if (!Array.isArray(group)){
|
if (!Array.isArray(group)){
|
||||||
mappedGroup = groupNameMemberMap[group];
|
mappedGroup = groupNameMemberMap[group];
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,6 +250,112 @@
|
||||||
return htmlGroup.join("\n");
|
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 => {
|
||||||
|
linkArray.push(`<div><a href="#.${link.slice(1)}">${link.slice(1)}</a></div>`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
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){
|
||||||
|
|
||||||
|
}
|
||||||
|
extractedIDs.push(id)
|
||||||
|
})
|
||||||
|
return extractedIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper for splitting up html
|
||||||
|
// Takes: Content to split, SearchTerm to Split by, term to End Splitting By, and negate Term object array
|
||||||
|
// negateTermObject { term: "<code>", distance: "3"}
|
||||||
|
// Returns: [newContent after Split, Array of extracted ]
|
||||||
|
function splitBy(content, searchTerm, endSplitTerm){
|
||||||
|
let foundArray = [];
|
||||||
|
let curIndex = -1;
|
||||||
|
let afterCurSearchIndex = -1
|
||||||
|
let negateTermIndex = -1;
|
||||||
|
let nextIndex = 0;
|
||||||
|
let findbyNameLength = searchTerm.length;
|
||||||
|
let curfoundArrayIndex = 0;
|
||||||
|
let curEndSplitTermIndex = -1;
|
||||||
|
do {
|
||||||
|
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||||
|
curIndex = content.indexOf(searchTerm);
|
||||||
|
afterCurSearchIndex = curIndex+findbyNameLength;
|
||||||
|
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||||
|
if (nextIndex === -1){
|
||||||
|
nextIndex = curEndSplitTermIndex;
|
||||||
|
}
|
||||||
|
foundArray.push(content.slice(curIndex, nextIndex))
|
||||||
|
// remove that content
|
||||||
|
content = content.replace(foundArray[curfoundArrayIndex], "");
|
||||||
|
curfoundArrayIndex++;
|
||||||
|
} while (curIndex > -1)
|
||||||
|
return [content, foundArray];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split the signals, methods, and typeDefs [Might make this more generic]
|
||||||
|
function splitMethodsSignalsAndTypeDefs(allItemToSplit){
|
||||||
|
let methodArray = [];
|
||||||
|
let signalArray = [];
|
||||||
|
let typeDefArray = [];
|
||||||
|
console.log(allItemToSplit.length);
|
||||||
|
allItemToSplit.forEach( method => {
|
||||||
|
firstLine = method.split("\n")[0];
|
||||||
|
if (firstLine.indexOf("Signal") > -1){
|
||||||
|
console.log("Found signal")
|
||||||
|
signalArray.push(method);
|
||||||
|
} else if (firstLine.indexOf("span") > -1) {
|
||||||
|
// console.log("Found method")
|
||||||
|
methodArray.push(method);
|
||||||
|
} else {
|
||||||
|
// console.log("Found typeDef")
|
||||||
|
|
||||||
|
typeDefArray.push(method);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return [methodArray, signalArray, typeDefArray];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Remove grav directory if exists to make sure old files aren't kept
|
// Remove grav directory if exists to make sure old files aren't kept
|
||||||
if (fs.existsSync(dir_grav)){
|
if (fs.existsSync(dir_grav)){
|
||||||
console.log("dir_grav exists");
|
console.log("dir_grav exists");
|
||||||
|
@ -253,7 +375,8 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
// Read jsdoc output folder and process html files
|
// Read jsdoc output folder and process html files
|
||||||
let curSource = path.join(dir_out, "AvatarInputs.html");
|
let curSource = path.join(dir_out, "Controller.html");
|
||||||
|
if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") {
|
||||||
// Clean up the html source
|
// Clean up the html source
|
||||||
let loadedHtml = prepareHtml(curSource);
|
let loadedHtml = prepareHtml(curSource);
|
||||||
|
|
||||||
|
@ -261,26 +384,12 @@
|
||||||
let splitTitle = loadedHtml("title").text().split(": ");
|
let splitTitle = loadedHtml("title").text().split(": ");
|
||||||
let groupName = splitTitle[1];
|
let groupName = splitTitle[1];
|
||||||
let htmlTitle = splitTitle.pop();
|
let htmlTitle = splitTitle.pop();
|
||||||
// console.log("first loaded:", loadedHtml("#main").html())
|
|
||||||
let mainDiv = loadedHtml("#main")
|
let mainDiv = loadedHtml("#main")
|
||||||
|
|
||||||
// let signatures = mainDiv.find(".name")
|
let methodIDs = [];
|
||||||
// Exploring Extractions
|
let signalIDs = [];
|
||||||
// let array = mainDiv.find('h4').toArray();
|
let typeDefIDs = [];
|
||||||
|
// Basic Regex HTML edits
|
||||||
// console.log(array[2])
|
|
||||||
// var reducedArray = array.reduce((prev, cur) => {
|
|
||||||
// try {
|
|
||||||
// // console.log(cur.children[1]);
|
|
||||||
// prev.push(cur.children[1].data);
|
|
||||||
// } catch(e) {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// return prev;
|
|
||||||
// }, [])
|
|
||||||
// console.log("name", reducedArray.length);
|
|
||||||
|
|
||||||
// regex edits
|
|
||||||
let mainDivRegexed = mainDiv.html()
|
let mainDivRegexed = mainDiv.html()
|
||||||
.replace(html_reg_static,"")
|
.replace(html_reg_static,"")
|
||||||
.replace(html_reg_title,"")
|
.replace(html_reg_title,"")
|
||||||
|
@ -288,96 +397,74 @@
|
||||||
.replace(html_reg_htmlExt,"")
|
.replace(html_reg_htmlExt,"")
|
||||||
.replace(html_reg_brRemove, "")
|
.replace(html_reg_brRemove, "")
|
||||||
.replace(html_reg_subsectionEdit, html_reg_subsectionEdit_replace)
|
.replace(html_reg_subsectionEdit, html_reg_subsectionEdit_replace)
|
||||||
|
.replace(html_reg_propertiesHeaderEdit, html_reg_propertiesHeaderEdit_Replace)
|
||||||
.replace(html_reg_typeEdit, html_reg_typeEdit_replace)
|
.replace(html_reg_typeEdit, html_reg_typeEdit_replace)
|
||||||
.replace(html_reg_returnSize, html_reg_returnSize_replace)
|
.replace(html_reg_returnSize, html_reg_returnSize_replace)
|
||||||
.replace(html_reg_methodSize, html_reg_methodSize_replace);
|
.replace(html_reg_methodSize, html_reg_methodSize_replace)
|
||||||
|
.replace(html_reg_typeDefSize, html_reg_typeDefSize_replace)
|
||||||
function splitBy(content, searchTerm){
|
.replace(html_reg_typeDefinitonsTitle, "");
|
||||||
let foundArray = [];
|
|
||||||
let curIndex = -1;
|
|
||||||
let nextIndex = 0;
|
// Further HTML Manipulation
|
||||||
let findbyNameLength = searchTerm.length;
|
// Split HTML by Each named entry
|
||||||
let curfoundArrayIndex = 0;
|
let contentSplitArray = splitBy(mainDivRegexed, html_reg_findByName, html_reg_findByArticleClose);
|
||||||
let curArticleCloseIndex = -1;
|
// Create a reference to the current content after split and the split functions
|
||||||
do {
|
let currentContent = contentSplitArray[0];
|
||||||
curArticleCloseIndex = content.indexOf("</article>");
|
// Create references to the split methods and signals
|
||||||
curIndex = content.indexOf(searchTerm);
|
let splitMethodsSignalsAndTypeDefs = splitMethodsSignalsAndTypeDefs(contentSplitArray[1]);
|
||||||
nextIndex = content.indexOf(searchTerm,curIndex+findbyNameLength);
|
let splitMethods = splitMethodsSignalsAndTypeDefs[0];
|
||||||
if (nextIndex === -1){
|
let splitSignals = splitMethodsSignalsAndTypeDefs[1];
|
||||||
nextIndex = curArticleCloseIndex
|
let splitTypeDefintions = splitMethodsSignalsAndTypeDefs[2];
|
||||||
}
|
let splitMethodIDS = extractIDs(splitMethods);
|
||||||
foundArray.push(content.slice(curIndex, nextIndex))
|
let splitSignalIDS = extractIDs(splitSignals);
|
||||||
content = content.replace(foundArray[curfoundArrayIndex], "");
|
let splitTypeDefinitionIDS = extractIDs(splitTypeDefintions);
|
||||||
curfoundArrayIndex++;
|
let classTOC = makeClassTOC([
|
||||||
} while (curIndex > -1)
|
{type: "Methods", array: splitMethodIDS},
|
||||||
return [content, foundArray];
|
{type: "Signals", array: splitSignalIDS},
|
||||||
|
{type: "Type Definitions", array: splitTypeDefinitionIDS}
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Append Signals and Methods to the current Content
|
||||||
|
currentContent = append(currentContent, html_reg_findByTitle, classTOC);
|
||||||
|
currentContent = append(currentContent, html_reg_findByMethod, splitMethods.join('\n'));
|
||||||
|
if (splitSignals.length > 0) {
|
||||||
|
// Add the Signals header to the Signals HTML
|
||||||
|
splitSignals.unshift(html_reg_signalTitle)
|
||||||
|
currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n'),true);
|
||||||
|
}
|
||||||
|
if (splitTypeDefintions.length > 0) {
|
||||||
|
// Add the Signals header to the Signals HTML
|
||||||
|
splitTypeDefintions.unshift(html_reg_typeDefinitonsTitle)
|
||||||
|
currentContent = append(currentContent, html_reg_findByArticleClose, splitTypeDefintions.join('\n'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractSignals(methodArray){
|
// Final Pretty Content
|
||||||
let newMethodArray = [];
|
currentContent = htmlclean(currentContent);
|
||||||
let signalArray = [];
|
currentContent = pretty(currentContent);
|
||||||
methodArray.forEach( method => {
|
|
||||||
method.indexOf("Signal") > -1
|
|
||||||
? signalArray.push(method)
|
|
||||||
: newMethodArray.push(method);
|
|
||||||
})
|
|
||||||
return [newMethodArray, signalArray]
|
|
||||||
}
|
|
||||||
|
|
||||||
function append(content, areaToAppendTo, contentToAppend, appendBefore){
|
|
||||||
var contentArray = content.split("\n");
|
|
||||||
// console.log("contentArray:", contentArray)
|
|
||||||
// console.log("areaToAppendTo:", areaToAppendTo)
|
|
||||||
var foundIndex = findArrayTrim(contentArray, areaToAppendTo)
|
|
||||||
console.log(foundIndex)
|
|
||||||
foundIndex = appendBefore ? foundIndex : foundIndex +1
|
|
||||||
|
|
||||||
contentArray.splice(foundIndex,0,contentToAppend)
|
|
||||||
return contentArray.join("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
var nameArray = splitBy(mainDivRegexed, html_reg_findByName);
|
|
||||||
let currentContent = nameArray[0];
|
|
||||||
let separatedMethods = extractSignals(nameArray[1]);
|
|
||||||
let methodsToAppend = separatedMethods[0].join("\n");
|
|
||||||
separatedMethods[1].unshift(html_reg_signalTitle)
|
|
||||||
let signalsToAppend = separatedMethods[1].join("\n");
|
|
||||||
currentContent = append(currentContent, html_reg_findByMethod, methodsToAppend);
|
|
||||||
mainDivRegexed = append(currentContent, html_reg_findByArticleClose, signalsToAppend,true);
|
|
||||||
|
|
||||||
// console.log(mainDivRegexed);
|
|
||||||
// Handle Unique Categories
|
// Handle Unique Categories
|
||||||
switch(groupName){
|
switch(groupName){
|
||||||
case "Namespace":
|
case "Namespace":
|
||||||
handleNamespace(htmlTitle, mainDivRegexed);
|
handleNamespace(htmlTitle, currentContent);
|
||||||
break;
|
break;
|
||||||
case "Class":
|
case "Class":
|
||||||
handleClass(htmlTitle, mainDivRegexed);
|
handleClass(htmlTitle, currentContent);
|
||||||
break;
|
break;
|
||||||
case "Global":
|
case "Global":
|
||||||
handleGlobal(htmlTitle, mainDivRegexed);
|
handleGlobal(htmlTitle, currentContent);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log(`Case not handled for ${groupName}`);
|
console.log(`Case not handled for ${groupName}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create the base Templates after processing individual files
|
// Create the base Templates after processing individual files
|
||||||
createTemplate("API-Reference", makeGroupTOC(["Namespaces", "Objects", "Globals"]));
|
createTemplate("API-Reference", makeGroupTOC(["Namespaces", "Objects", "Globals"]));
|
||||||
createTemplate("Namespaces", makeGroupTOC("Namespaces"));
|
createTemplate("Namespaces", makeGroupTOC("Namespaces"));
|
||||||
createTemplate("Objects", makeGroupTOC("Objects"));
|
createTemplate("Objects", makeGroupTOC("Objects"));
|
||||||
|
|
||||||
// Copy files to the Twig Directory
|
// Copy the files to the target Directories if Local
|
||||||
|
if (copyLocal){
|
||||||
|
// Copy files to the Twig Directory
|
||||||
let templateFiles = fs.readdirSync(path.resolve(targetTemplateDirectory));
|
let templateFiles = fs.readdirSync(path.resolve(targetTemplateDirectory));
|
||||||
// Remove Existing API files
|
// Remove Existing API files
|
||||||
templateFiles.forEach(function(file){
|
templateFiles.forEach(function(file){
|
||||||
|
@ -389,10 +476,11 @@
|
||||||
})
|
})
|
||||||
copyFolderRecursiveSync(dir_template, targetTemplateDirectory);
|
copyFolderRecursiveSync(dir_template, targetTemplateDirectory);
|
||||||
|
|
||||||
// Copy files to the Md Directory
|
// Copy files to the Md Directory
|
||||||
let baseMdRefDir = path.join(targetMDDirectory,"06.api-reference");
|
let baseMdRefDir = path.join(targetMDDirectory,"06.api-reference");
|
||||||
// Remove existing MD directory
|
// Remove existing MD directory
|
||||||
if (fs.existsSync(baseMdRefDir)){
|
if (fs.existsSync(baseMdRefDir)){
|
||||||
rimraf.sync(baseMdRefDir);
|
rimraf.sync(baseMdRefDir);
|
||||||
}
|
}
|
||||||
copyFolderRecursiveSync(dir_md, targetMDDirectory);
|
copyFolderRecursiveSync(dir_md, targetMDDirectory);
|
||||||
|
}
|
||||||
|
|
|
@ -62,12 +62,17 @@
|
||||||
const html_reg_typeEdit_replace = '$1: $3</dt></dl>'
|
const html_reg_typeEdit_replace = '$1: $3</dt></dl>'
|
||||||
const html_reg_methodSize = /(<h4)( class="name"[\s\S].*?<\/span>)(<\/h4>)/g;
|
const html_reg_methodSize = /(<h4)( class="name"[\s\S].*?<\/span>)(<\/h4>)/g;
|
||||||
const html_reg_methodSize_replace = '<h5$2</h5>';
|
const html_reg_methodSize_replace = '<h5$2</h5>';
|
||||||
|
const html_reg_typeDefSize = /(<h4)( class="name"[\s\S].*?)(<\/h4>)/g;
|
||||||
|
const html_reg_typeDefSize_replace = '<h5$2</h5>';
|
||||||
const html_reg_returnSize = /<h5>Returns:<\/h5>/g;
|
const html_reg_returnSize = /<h5>Returns:<\/h5>/g;
|
||||||
const html_reg_returnSize_replace = '<h6>Returns:<\/h6>';
|
const html_reg_returnSize_replace = '<h6>Returns:<\/h6>';
|
||||||
const html_reg_findByName = '<h5 class="name"';
|
const html_reg_findByName = '<h5 class="name"';
|
||||||
const html_reg_findByMethod = `<h4 class="subsection-title">Methods</h4>`
|
const html_reg_findByTitle = '<h1>';
|
||||||
|
const html_reg_findByMethod = `<h4 class="subsection-title">Methods</h4>`;
|
||||||
const html_reg_findByArticleClose = `</article>`
|
const html_reg_findByArticleClose = `</article>`
|
||||||
const html_reg_signalTitle = `<h4 class="subsection-title">Signals</h4>`;
|
const html_reg_signalTitle = `<h4 class="subsection-title">Signals</h4>`;
|
||||||
|
const html_reg_typeDefinitonsTitle = `<h4 class="subsection-title">Type Definitions</h4>`;
|
||||||
|
const html_reg_firstTableClose = `</table>`;
|
||||||
|
|
||||||
|
|
||||||
// Mapping for GroupNames and Members
|
// Mapping for GroupNames and Members
|
||||||
|
@ -136,7 +141,7 @@
|
||||||
} else {
|
} else {
|
||||||
copyFileSync( curSource, targetFolder );
|
copyFileSync( curSource, targetFolder );
|
||||||
}
|
}
|
||||||
} );
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,23 +252,55 @@
|
||||||
return htmlGroup.join("\n");
|
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 => {
|
||||||
|
linkArray.push(`<div><a href="#.${link.slice(1)}">${link.slice(1)}</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){
|
||||||
|
|
||||||
|
}
|
||||||
|
extractedIDs.push(id)
|
||||||
|
})
|
||||||
|
return extractedIDs;
|
||||||
|
}
|
||||||
|
|
||||||
// Helper for splitting up html
|
// Helper for splitting up html
|
||||||
// Takes: Content to split, SearchTerm to Split by, and term to End Splitting By
|
// Takes: Content to split, SearchTerm to Split by, and term to End Splitting By
|
||||||
// Returns: [newContent after Split, Array of extracted ]
|
// Returns: [newContent after Split, Array of extracted ]
|
||||||
function splitBy(content, searchTerm, endSplitTerm){
|
function splitBy(content, searchTerm, endSplitTerm){
|
||||||
let foundArray = [];
|
let foundArray = [];
|
||||||
let curIndex = -1;
|
let curIndex = -1;
|
||||||
|
let afterCurSearchIndex = -1
|
||||||
|
let negateTermIndex = -1;
|
||||||
let nextIndex = 0;
|
let nextIndex = 0;
|
||||||
let findbyNameLength = searchTerm.length;
|
let findbyNameLength = searchTerm.length;
|
||||||
let curfoundArrayIndex = 0;
|
let curfoundArrayIndex = 0;
|
||||||
let curEndSplitTermIndex = -1;
|
let curEndSplitTermIndex = -1;
|
||||||
do {
|
do {
|
||||||
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
curEndSplitTermIndex = content.indexOf(endSplitTerm);
|
||||||
curIndex = content.indexOf(searchTerm);
|
curIndex = content.indexOf(searchTerm);
|
||||||
// Search after initial index + length of searchterm
|
afterCurSearchIndex = curIndex+findbyNameLength;
|
||||||
nextIndex = content.indexOf(searchTerm,curIndex+findbyNameLength);
|
nextIndex = content.indexOf(searchTerm,afterCurSearchIndex);
|
||||||
if (nextIndex === -1){
|
if (nextIndex === -1){
|
||||||
nextIndex = curEndSplitTermIndex
|
nextIndex = curEndSplitTermIndex;
|
||||||
}
|
}
|
||||||
foundArray.push(content.slice(curIndex, nextIndex))
|
foundArray.push(content.slice(curIndex, nextIndex))
|
||||||
// remove that content
|
// remove that content
|
||||||
|
@ -274,15 +311,27 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split the signals and methods [Might make this more generic]
|
// Split the signals and methods [Might make this more generic]
|
||||||
function splitMethodsAndSignals(methodArray){
|
function splitMethodsSignalsAndTypeDefs(allItemToSplit){
|
||||||
let newMethodArray = [];
|
let methodArray = [];
|
||||||
let signalArray = [];
|
let signalArray = [];
|
||||||
methodArray.forEach( method => {
|
let typeDefArray = [];
|
||||||
method.indexOf("Signal") > -1
|
// console.log(allItemToSplit.length);
|
||||||
? signalArray.push(method)
|
allItemToSplit.forEach( method => {
|
||||||
: newMethodArray.push(method);2
|
firstLine = method.split("\n")[0];
|
||||||
|
if (firstLine.indexOf("Signal") > -1){
|
||||||
|
// console.log("Found signal")
|
||||||
|
signalArray.push(method);
|
||||||
|
} else if (firstLine.indexOf("span") > -1) {
|
||||||
|
// console.log("Found method")
|
||||||
|
methodArray.push(method);
|
||||||
|
} else {
|
||||||
|
// console.log("Found typeDef")
|
||||||
|
if(firstLine.trim() !== ""){
|
||||||
|
typeDefArray.push(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return [newMethodArray, signalArray]
|
return [methodArray, signalArray, typeDefArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to append
|
// Helper to append
|
||||||
|
@ -337,51 +386,74 @@
|
||||||
let loadedHtml = prepareHtml(curSource);
|
let loadedHtml = prepareHtml(curSource);
|
||||||
|
|
||||||
// Extract the title, group name, and the main div
|
// Extract the title, group name, and the main div
|
||||||
let splitTitle = loadedHtml("title").text().split(": ");
|
let splitTitle = loadedHtml("title").text().split(": ");
|
||||||
let groupName = splitTitle[1];
|
let groupName = splitTitle[1];
|
||||||
let htmlTitle = splitTitle.pop();
|
let htmlTitle = splitTitle.pop();
|
||||||
let mainDiv = loadedHtml("#main")
|
let mainDiv = loadedHtml("#main")
|
||||||
|
|
||||||
// Basic Regex HTML edits
|
|
||||||
let mainDivRegexed = mainDiv.html()
|
|
||||||
.replace(html_reg_static,"")
|
|
||||||
.replace(html_reg_title,"")
|
|
||||||
.replace(html_reg_objectHeader,"")
|
|
||||||
.replace(html_reg_htmlExt,"")
|
|
||||||
.replace(html_reg_brRemove, "")
|
|
||||||
.replace(html_reg_subsectionEdit, html_reg_subsectionEdit_replace)
|
|
||||||
.replace(html_reg_propertiesHeaderEdit, html_reg_propertiesHeaderEdit_Replace)
|
|
||||||
.replace(html_reg_typeEdit, html_reg_typeEdit_replace)
|
|
||||||
.replace(html_reg_returnSize, html_reg_returnSize_replace)
|
|
||||||
.replace(html_reg_methodSize, html_reg_methodSize_replace);
|
|
||||||
|
|
||||||
// Further HTML Manipulation
|
|
||||||
// Split HTML by Each named entry
|
|
||||||
if (path.basename(curSource, '.html') === "Controller"){
|
|
||||||
var cleanup = htmlclean(mainDivRegexed);
|
|
||||||
cleanup = pretty(cleanup)
|
|
||||||
fs.writeFileSync(__dirname+'/Examine/ControllerExamine', cleanup);
|
|
||||||
}
|
|
||||||
|
|
||||||
let contentSplitArray = splitBy(mainDivRegexed, html_reg_findByName);
|
let methodIDs = [];
|
||||||
// Create a reference to the current content after split and the split functions
|
let signalIDs = [];
|
||||||
let currentContent = contentSplitArray[0];
|
let typeDefIDs = [];
|
||||||
// Create references to the split methods and signals
|
// Basic Regex HTML edits
|
||||||
let splitSignalsAndMethods = splitMethodsAndSignals(contentSplitArray[1]);
|
let mainDivRegexed = mainDiv.html()
|
||||||
let splitMethods = splitSignalsAndMethods[0];
|
.replace(html_reg_static,"")
|
||||||
let splitSignals = splitSignalsAndMethods[1];
|
.replace(html_reg_title,"")
|
||||||
// Append Signals and Methods to the current Content
|
.replace(html_reg_objectHeader,"")
|
||||||
currentContent = append(currentContent, html_reg_findByMethod, splitMethods.join('\n'));
|
.replace(html_reg_htmlExt,"")
|
||||||
console.log(path.basename(curSource, '.html'), splitSignals.length);
|
.replace(html_reg_brRemove, "")
|
||||||
if (splitSignals.length > 0) {
|
.replace(html_reg_subsectionEdit, html_reg_subsectionEdit_replace)
|
||||||
// Add the Signals header to the Signals HTML
|
.replace(html_reg_propertiesHeaderEdit, html_reg_propertiesHeaderEdit_Replace)
|
||||||
splitSignals.unshift(html_reg_signalTitle)
|
.replace(html_reg_typeEdit, html_reg_typeEdit_replace)
|
||||||
currentContent = append(currentContent, html_reg_findByArticleClose, splitSignals.join('\n',true));
|
.replace(html_reg_returnSize, html_reg_returnSize_replace)
|
||||||
}
|
.replace(html_reg_methodSize, html_reg_methodSize_replace)
|
||||||
|
.replace(html_reg_typeDefSize, html_reg_typeDefSize_replace)
|
||||||
|
.replace(html_reg_typeDefinitonsTitle, "")
|
||||||
|
.replace(html_reg_findByMethod, "");
|
||||||
|
|
||||||
|
// Further HTML Manipulation
|
||||||
|
// Split HTML by Each named entry
|
||||||
|
let contentSplitArray = splitBy(mainDivRegexed, html_reg_findByName, html_reg_findByArticleClose);
|
||||||
|
// Create a reference to the current content after split and the split functions
|
||||||
|
let currentContent = contentSplitArray[0];
|
||||||
|
// Create references to the split methods and signals
|
||||||
|
let processedMethodsSignalsAndTypeDefs = splitMethodsSignalsAndTypeDefs(contentSplitArray[1]);
|
||||||
|
let splitMethods = processedMethodsSignalsAndTypeDefs[0];
|
||||||
|
let splitSignals = processedMethodsSignalsAndTypeDefs[1];
|
||||||
|
let splitTypeDefintions = processedMethodsSignalsAndTypeDefs[2];
|
||||||
|
let splitMethodIDS = extractIDs(splitMethods);
|
||||||
|
let splitSignalIDS = extractIDs(splitSignals);
|
||||||
|
let splitTypeDefinitionIDS = extractIDs(splitTypeDefintions);
|
||||||
|
let arrayToPassToClassToc = [];
|
||||||
|
|
||||||
// Final Pretty Content
|
// Append Signals and Methods to the current Content
|
||||||
currentContent = htmlclean(currentContent);
|
if (splitMethods.length > 0) {
|
||||||
currentContent = pretty(currentContent);
|
arrayToPassToClassToc.push({type: "Methods", array: splitMethodIDS});
|
||||||
|
// Add the Signals header to the Signals HTML
|
||||||
|
splitMethods.unshift(html_reg_findByMethod)
|
||||||
|
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 (splitTypeDefintions.length > 0) {
|
||||||
|
|
||||||
|
// console.log(path.basename(curSource, '.html'));
|
||||||
|
// console.log(splitTypeDefintions.length);
|
||||||
|
arrayToPassToClassToc.push({type: "Type Definitions", array: splitTypeDefinitionIDS});
|
||||||
|
// Add the Signals header to the Signals HTML
|
||||||
|
splitTypeDefintions.unshift(html_reg_typeDefinitonsTitle)
|
||||||
|
currentContent = append(currentContent, html_reg_findByArticleClose, splitTypeDefintions.join('\n'), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
let classTOC = makeClassTOC(arrayToPassToClassToc);
|
||||||
|
currentContent = append(currentContent, html_reg_firstTableClose, classTOC);
|
||||||
|
|
||||||
|
// Final Pretty Content
|
||||||
|
currentContent = htmlclean(currentContent);
|
||||||
|
currentContent = pretty(currentContent);
|
||||||
|
|
||||||
// Handle Unique Categories
|
// Handle Unique Categories
|
||||||
switch(groupName){
|
switch(groupName){
|
||||||
|
|
Loading…
Reference in a new issue