Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
function getDocs() {
// Get all lodash functions
const functionNames = _.functions(_)
console.log(`Found ${functionNames.length} functions`)
// Find all files associated to lodash functions
const files = functionNames
.map(functionName =>
path.join(__dirname, `../node_modules/lodash/${functionName}.js`)
)
.filter(fs.existsSync)
console.log(`Found ${files.length} files`)
// Parse JSDoc for each file
const docs = jsdoc2md
.getTemplateDataSync({ files })
.filter(doc => functionNames.includes(doc.name))
console.log(`Found ${docs.length} docs`)
return docs
}
function setup(outputDir, createDocsDir) {
// input and output paths
const inputFiles = [outputDir + 'index.js'].concat(docUtils.readDirRecursive(outputDir + 'lib'))
// get template data
const templateData = jsdoc2md.getTemplateDataSync({ files: inputFiles, configure: docUtils.CONFIG_PATH })
if (createDocsDir) {
const outputDocsDir = outputDir + 'docs'
if (!fs.existsSync(outputDocsDir)) {
fs.mkdirSync(outputDocsDir)
}
return { outputDocsDir, templateData }
}
return templateData
}
const createTemplate = ({ kind, title, sidebarLabel }) => `---
id: ${kind}
title: ${title}
sidebar_label: ${sidebarLabel}
---
{{>global-index-kinds kind="${kind}" ~}}
{{#identifiers kind="${kind}" scope="global"}}
{{>docs~}}
{{/identifiers}}
`
// Get template data.
const templateData = jsdoc2md.getTemplateDataSync({
files: inputFile,
})
// Group template data by kind.
const templateDataByKind = groupBy(templateData, 'kind')
const tasks = new Listr(
// Create a documentation file for each kind.
Object.keys(templateDataByKind).map(kind => {
const title = titleMap[kind]
const template = createTemplate({
kind,
title,
sidebarLabel: titleMap[kind],
})
map((file, callback) => {
let urlPrefix = '';
let menuHandled = false;
let templateData = jsdoc2md.getTemplateDataSync({ files: file.path });
let textHandled = false;
const filename = file.relative
.replace(/(\/|.jsx|.js)/g, '')
.replace(/([a-zA-Z])(?=[A-Z])/g, '$1-')
.toLowerCase();
templateData = templateData.map(item => {
if (item.meta) {
const { filename = '', lineno = 0, path = '' } = item.meta;
item.imaGitUrl = `${gitUrl}${path
.split(DOC_SRC)
.pop()}/${filename}#L${lineno}`;
if (!menuHandled) {
const category = path.split(`${DOC_SRC}/`);
fn =>
jsDocParser.getTemplateDataSync({
files: fn.fullPath,
'no-cache': true
})[0]
)
const generateMarkdownForFile = ({ file, outputDir, partial, separator }) => {
const templateData = jsdoc2md.getTemplateDataSync({ files: file });
const classNames = getClassesInFile(templateData);
classNames.forEach((className) => createDocFileForClass({ className, templateData, outputDir, partial, separator }));
};
genParams(item) {
let text = '';
for (let i = 0; i < item.params.length; i++) {
let element = item.params[i];
text += element.name;
if (i != item.params.length - 1)
text += ', ';
}
return text;
}
}
const templateData = jsdoc2md.getTemplateDataSync({
files: inputFile
});
let g = new Generator();
g.setTemplateData(templateData)
function ensureDirectoryExistence(filePath) {
let dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
}
const classNames = [];
encoding : "utf-8"
});
//Inject example usage into README
var example1 = fs.readFileSync('./examples/styles-and-formatting.js',{
encoding : 'utf-8'
});
example1 = example1.replace('../','tty-table');
example1 = '\n```js\n' + example1 + '\n```';
readme = readme.replace(
/((?:.|[\r\n])*)/m,
'\n'+example1+'\n'
);
const jsdoc2md = require('jsdoc-to-markdown');
let jsdocData = jsdoc2md.getTemplateDataSync({
//configure: __dirname + '/conf.json', //jsdoc config file path
files: 'src/*.js'
});
let stdout = jsdoc2md.renderSync({
data: jsdocData,
"no-usage-stats": true
});
//Reformat documentation to reflect correct method naming.
var str = stdout.replace(/new /g,'').replace(/_public\./g,'');
readme = readme.replace(
/((?:.|[\r\n])*)/m,
'\n\n'+str+'\n'
);