Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function gendoc (filepath) {
// Load file
let file = fs.readFileSync(filepath, 'utf8')
// Fix some TypeScript-isms that jsdoc doesn't like
file = file.replace(/\{import\('events'\)\.EventEmitter\}/g, '{EventEmitter}')
let ast
try {
ast = jsdoc.explainSync({ source: file })
} catch (e) {
console.log(`Unable to parse ${filepath}`, e.message)
return ''
}
let text = ''
for (const obj of ast) {
if (!obj.undocumented) {
if (obj.kind === 'typedef') {
gentypedef(obj)
continue
}
if (obj.kind === 'package') continue
if (!obj.params || !obj.returns) continue
text += `---\n`
text += `title: ${obj.name}\n`
function parseAPIJsDocFormat(filepath, fileContent) {
const fileName = path.basename(filepath);
const babelRC = {
'filename': fileName,
'sourceFileName': fileName,
'plugins': [
'transform-flow-strip-types',
]
};
// Babel transform
const code = babel.transform(fileContent, babelRC).code;
// Parse via jsdoc-api
let jsonParsed = jsdocApi.explainSync({
source: code,
configure: './jsdocs/jsdoc-conf.json'
});
// Clean up jsdoc-api return
jsonParsed = jsonParsed.filter(i => {
return !i.undocumented && !/package|file/.test(i.kind);
});
jsonParsed = jsonParsed.map((identifier) => {
delete identifier.comment;
return identifier;
});
jsonParsed.forEach((identifier, index) => {
identifier.order = index;
});
// Group by "kind"
const json = {};
function parseAPIJsDocFormat(filepath, fileContent) {
const fileName = path.basename(filepath);
const babelRC = {
'filename': fileName,
'sourceFileName': fileName,
'plugins': [
'transform-flow-strip-types',
'babel-plugin-syntax-trailing-function-commas',
]
};
// Babel transform
const code = babel.transform(fileContent, babelRC).code;
// Parse via jsdoc-api
let jsonParsed = jsdocApi.explainSync({
source: code,
configure: './jsdocs/jsdoc-conf.json'
});
// Clean up jsdoc-api return
jsonParsed = jsonParsed.filter(i => {
return !i.undocumented && !/package|file/.test(i.kind);
});
jsonParsed = jsonParsed.map((identifier) => {
delete identifier.comment;
return identifier;
});
jsonParsed.forEach((identifier, index) => {
identifier.order = index;
});
// Group by "kind"
const json = {};
var path = require('path');
var compiler = require('jsdoc-api');
var explanation = compiler.explainSync({
files: [
path.resolve(__dirname, '../src/two.js'),
path.resolve(__dirname, '../src/registry.js'),
path.resolve(__dirname, '../src/vector.js'),
path.resolve(__dirname, '../src/anchor.js'),
path.resolve(__dirname, '../src/matrix.js'),
// path.resolve(__dirname, '../src/renderer/svg.js'),
// path.resolve(__dirname, '../src/renderer/canvas.js'),
// path.resolve(__dirname, '../src/renderer/webgl.js'),
path.resolve(__dirname, '../src/shape.js'),
path.resolve(__dirname, '../src/path.js'),
path.resolve(__dirname, '../src/shapes/line.js'),
path.resolve(__dirname, '../src/shapes/rectangle.js'),
path.resolve(__dirname, '../src/shapes/ellipse.js'),
path.resolve(__dirname, '../src/shapes/circle.js'),
path.resolve(__dirname, '../src/shapes/polygon.js'),
file =>
jsdoc
.explainSync({ files: file })
.filter(({ kind }) => kind === 'function')
.filter(({ tags }) => tags) // To rule out the other undocumented functions of these files
.map(jsDocData => ({
mdPath: `${jsDocData.meta.path}/README.md`,
jsDocData: {
...jsDocData,
parentPackage: (jsDocData.tags.find(t => t.title === 'parentpackage') || {}).value,
lowercaseName: jsDocData.name.toLowerCase(),
formattedReturns: `**${jsDocData.returns[0].type.names[0]}**${
jsDocData.returns[0].description ? `: ${jsDocData.returns[0].description}` : ''
}`,
formattedParams: jsDocData.params
.map(
p =>
`**${p.optional ? '\\[' : ''}${p.name}${
let nodeDoc = new Doc(interfaces.shift());
nodeDoc.writeToFile();
interfaces.forEach(el => {
new Doc(el, nodeDoc).writeToFile();
});
// Let's start again! Draxt is not ES6 class and `Doc` will chalk on it!
nodeDoc.lines = ['# draxt.js'];
let doc = nodeDoc;
doc.clsName = 'draxt';
doc.srcPath = path.join(__dirname, '../src/draxt.js');
doc.instanceName = 'draxtCollection';
doc.relativeSrcPath = 'draxt.js';
const source = fs.readFileSync(doc.srcPath, 'utf8');
const descs = jsdoc.explainSync({ source }).filter(el => el.description);
const constructorDesc = descs.shift();
doc.add(Doc.linkify(constructorDesc.description));
doc.addSyntax(false);
doc.addParamsList(constructorDesc);
doc.addExamples(constructorDesc);
const rets = Doc.getReturnValues(constructorDesc);
if (rets) {
doc.add('');
doc.add(`→ ${rets}`);
}
doc.add('<br><br>');
doc.add('## Methods');
descs.forEach(el => {
doc.addMethod(el);
});
export default function getDocFile(source, file, lang) {
try {
const parsedSource = parseModule(source, file, lang, '2017')
let docReturn = jsdoc
.explainSync({
source: parsedSource,
configure: path.join(path.dirname(__dirname), '..', 'config.json'),
})
.filter(obj => obj.undocumented !== true)
.map(obj => {
if (obj.meta) {
obj.meta.filename = file
obj.meta.path = file
} else {
obj.files[0] = file
}
return obj
})
return docReturn
} catch (err) {
getJsdocDataSync (options) {
const jsdocOptions = new JsdocOptions(options)
return jsdocApi.explainSync(jsdocOptions)
}