Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function createMarkdownFromClasses(packageName, outputDir, api, readme) {
console.log('createMarkdownFromClasses()')
const { outputDocsDir, templateData } = setup(outputDir, true)
// reduce templateData to an array of class names
const classNames = templateData.reduce((classNames, identifier) => {
if (identifier.kind === 'class') classNames.push(identifier.name)
return classNames
}, [])
// create a documentation file for each class
for (const className of classNames) {
const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`
const output = jsdoc2md.renderSync({ data: templateData, template: template })
fs.writeFileSync(path.resolve(outputDocsDir, `${className}.md`), output)
}
let apiOutput = await prepApi(api, templateData)
apiOutput = mergeAndRepathHeaderLink(apiOutput, './')
// use to convert links from page scroll to nav to other md files
apiOutput = apiOutput.replace(/(\[)([^\]]+)(\]\(#([^\)]+)\))/g, (full, a, b, c, d) => {
// split to see if it is a method or property
const split = d.split('.')
return split.length > 1 ? `<a href="./docs/${split[0]}.md#${d}">${b}</a>` : b
})
combineAndWrite(packageName, outputDir, apiOutput, readme)
}
fs.readFile(obj.api, (err, apiData) => {
if (err) reject(err)
console.log(obj.name)
// console.log(obj.files)
const templateData = jsdoc2md.getTemplateDataSync({ files: obj.files, configure: docUtils.CONFIG_PATH })
// console.log(templateData)
let output = jsdoc2md.renderSync({
data: templateData,
template: apiData.toString(),
helper: __dirname + '/helper.js'
})
// remap the links
output = output.replace(/(\[)([^\]]+)(\]\(#([^\)]+)\))/g, (full, a, b, c, d) => {
// split to see if it is a method or property
const split = d.split('.')
let subPath = ''
if (split.length > 1) {
subPath = `#${d}`
} else {
// check 'd' for 'new_[name]_new' leading word
split[0] = split[0].replace(/(new_)(.+)(_new)/, '$2')
}
namespaces.forEach((name) => {
const template = `{{#namespace name="${name}"}}{{>docs}}{{/namespace}}`;
console.log(`Rendering ${name}, template: ${template}`); // eslint-disable-line no-console
const output = jsdoc2md.renderSync(getRenderOptions(template, templateData));
const markdown = generateFinalMarkdown(name, output);
fs.writeFileSync(path.resolve(sourceFilesOutputDir, `${name}.md`), markdown);
});
async function prepApi(api, templateData) {
const apiData = await fs.readFileAsync(api)
// create the main README
return jsdoc2md.renderSync({
data: templateData,
template: apiData.toString(),
helper: __dirname + '/helper.js'
})
}
it("Should not allow the readme docs to get out of sync", function () {
var currentReadme = fs.readFileSync(path.join(__dirname, '../', 'readme.md')).toString()
var cliDocsRaw = fs.readFileSync(path.join(__dirname, '../bin', 'help.md')).toString()
cliDocsRaw = cliDocsRaw
.replace(/ /g, ' ')
.replace(/\*\*/g, '');
var approvalsSource = fs.readFileSync(path.join(__dirname, '../lib', 'Approvals.js')).toString();
var jsdocsOutput = jsdoc2md.renderSync({ source: approvalsSource, 'no-cache': true})
jsdocsOutput = jsdocsOutput.split('\n').map(function (line) {
return line.replace(/\s+$/, '');
}).join('\n');
var newDocs = "";
newDocs += "\n";
newDocs += "\n";
newDocs += "\n\n" + jsdocsOutput;
newDocs += "\n\n";
var cliDocs = "";
cliDocs += "\n";
cliDocs += "\n";
cliDocs += "\n```";
cliDocs += "\n\n" + cliDocsRaw;
cliDocs += "\n```";
let generateMarkdown = (folder) => {
let file = path.resolve(folder);
try {
var options = { files: file + '\\*.js'};
console.log(options);
let markdown = jsdoc2md.renderSync(options);
console.log(markdown);
return markdown;
}
catch(e) {
//console.log(e);
console.log("Error Caught");
}
return "";
}
files.forEach(file => {
const fileinfo = path.parse(file.path);
const vinylFile = new Vinyl({
path: fileinfo.name + '.md',
contents: new Buffer.from(jsdoc2md.renderSync({files: file.path}))
});
stream.push(vinylFile);
});
cb();
function produceAPI(sourceArr, rsPath) {
var apidocsPath = path.join(envPath, 'docs');
const output = jsdoc2md.renderSync({ files: sourceArr })
var isexist = fs.existsSync(apidocsPath);
if (!isexist) {
fs.mkdirSync(apidocsPath);
}
fs.writeFileSync(path.join(apidocsPath, rsPath), output)
}