alfresco-ng2-components/tools/doc/buildYamlSourceInfo.js
Andy Stark 8a86981da7 [ADF-4249] Fixed issues with ToC and auto-linking tools (#4492)
* [ADF-4249] Fixed issues with anchors in contents sections

* [ADF-4249] Removed redundant copy of edit proc filter cloud docs

* [ADF-4249] Fixed YAML template generation for accessor props

* [ADF-4249] Fixed ToC link generation

* [ADF-4249] Fixed type alias links in component docs
2019-03-25 17:56:25 +00:00

54 lines
1.3 KiB
JavaScript

var fs = require("fs");
var path = require("path");
var ejs = require("ejs");
var templateFolder = path.resolve("tools", "doc", "yamlTemplates");
var outputFolder = path.resolve("docs", "sourceinfo");
if (process.argv.length < 3) {
console.log("Error: Source filename required");
process.exit();
}
console.log(`Processing ${process.argv[2]}`);
if (!fs.existsSync(outputFolder)) {
fs.mkdirSync(outputFolder);
}
var docData = JSON.parse(fs.readFileSync(path.resolve(process.argv[2]), "utf8"));
var tempFilename = path.resolve(templateFolder, "template.ejs");
var tempSource = fs.readFileSync(tempFilename, "utf8");
var template = ejs.compile(
tempSource,
{
filename: tempFilename,
cache: true
}
);
searchItemsRecursively(docData);
function searchItemsRecursively(item) {
if (interestedIn(item.kind)) {
processItem(item);
} else if (item.children) {
item.children.forEach(child => {
searchItemsRecursively(child);
});
}
}
function interestedIn(itemKind) {
return (itemKind === 128) || (itemKind === 256) || (itemKind === 4194304);
}
function processItem(item) {
//console.log(`Generating ${item.name}`);
var docText = template(item);
fs.writeFileSync(path.resolve(outputFolder, item.name + ".yml"), docText);
}