Cleaned up gravprep.js

This commit is contained in:
milad 2018-05-29 11:24:13 -07:00
parent 3455dd296b
commit 9c664a2512
2 changed files with 377 additions and 387 deletions

View file

@ -2,12 +2,26 @@
##Prerequisites ##Prerequisites
* Install node.js * Install node.js.
* Install jsdoc via npm. `npm install jsdoc -g` * 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: To generate html documentation for the High Fidelity JavaScript API:
* `cd tools/jsdoc` * `cd tools/jsdoc`
* `jsdoc . -c config.json` * `jsdoc . -c config.json`
The out folder should contain index.html. 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"

View file

@ -120,7 +120,7 @@ function allLinksToLowerCase(match, p1, p2, p3) {
return [p1, p2, p3].join(""); 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) { function fixLinkGrouping(match, p1, p2, p3) {
// Handle if referencing ID // Handle if referencing ID
let count = (p2.match(/\./g) || []).length; 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) { function returnRightGroup(methodToCheck) {
for (var key in groupNameMemberMap) { for (var key in groupNameMemberMap) {
for (i = 0; i < groupNameMemberMap[key].length; i++) { for (i = 0; i < groupNameMemberMap[key].length; i++) {
@ -467,30 +468,30 @@ function makeGroupTOC(group) {
} }
// 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");
rimraf.sync(dir_grav); rimraf.sync(dir_grav);
} }
// Create Grav directories in JSDOC output // Create Grav directories in JSDOC output
dirArray.forEach(function(dir){ dirArray.forEach(function(dir){
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
fs.mkdirSync(dir); fs.mkdirSync(dir);
} }
}) })
// Create baseMD files // Create baseMD files
baseMDDirectories.forEach( md => { baseMDDirectories.forEach( md => {
createMD(md, map_dir_md[md]); createMD(md, map_dir_md[md]);
}) })
// Read jsdoc output folder and process html files // Read jsdoc output folder and process html files
let links = []; let links = [];
let unTouchedLinks = []; let unTouchedLinks = [];
let files = fs.readdirSync(dir_out); let files = fs.readdirSync(dir_out);
// Create initial Group name member map to handle individual link :: TODO find better way to do this // Create initial Group name member map to handle individual link
files.forEach(function (file){ files.forEach(function (file){
let curSource = path.join(dir_out, file); let curSource = path.join(dir_out, file);
if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") { if (path.extname(curSource) == ".html" && path.basename(curSource, '.html') !== "index") {
let loadedHtml = prepareHtml(curSource); let loadedHtml = prepareHtml(curSource);
@ -508,8 +509,8 @@ function makeGroupTOC(group) {
console.log(`Case not handled for ${groupName}`); console.log(`Case not handled for ${groupName}`);
} }
} }
}) })
files.forEach(function (file, index){ files.forEach(function (file, index){
// For testing individual files // For testing individual files
// if (index !== 59) return; // if (index !== 59) return;
let curSource = path.join(dir_out, file); let curSource = path.join(dir_out, file);
@ -540,10 +541,10 @@ function makeGroupTOC(group) {
.replace(html_reg_allNonHTTPLinks, fixLinkGrouping) // Make sure links refer to correct grouping .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_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_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_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_methodSize, html_reg_methodSize_replace) // Make method size into h5
.replace(html_reg_pretty, html_reg_pretty_replace) .replace(html_reg_pretty, html_reg_pretty_replace) // remove the references to pretty
.replace(html_reg_classDefinitonsTitle, html_reg_classDefinitonsTitle_replace) .replace(html_reg_classDefinitonsTitle, html_reg_classDefinitonsTitle_replace) // Change the class def titles
.replace(html_reg_depreciated, html_reg_depreciated_replace); // format depreciated better .replace(html_reg_depreciated, html_reg_depreciated_replace); // format depreciated better
// Further HTML Manipulation // Further HTML Manipulation
@ -645,15 +646,15 @@ function makeGroupTOC(group) {
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 the files to the target Directories if Local // Copy the files to the target Directories if Local
if (copyLocal){ if (copyLocal){
// Copy files to the Twig Directory // 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
@ -674,29 +675,4 @@ function makeGroupTOC(group) {
rimraf.sync(baseMdRefDir); rimraf.sync(baseMdRefDir);
} }
copyFolderRecursiveSync(dir_md, targetMDDirectory); copyFolderRecursiveSync(dir_md, targetMDDirectory);
} }
/*
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)
*/