Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// This script generates a full documentation for the API.
const documentation = require('documentation')
// streamArray and vfs can be used because these are dependencies of documentation.
const streamArray = require('stream-array')
const vfs = require('vinyl-fs')
console.log(`Building API documentation. This can take a few moments ...`)
documentation.build([
'source/main.js',
'source/renderer/zettlr-renderer.js'
], {
// config: 'documentation.yml',
projectName: 'Zettlr',
projectHomepage: 'https://www.zettlr.com'
})
.then(comments => documentation.formats.html(comments, {}))
.then(output => {
streamArray(output).pipe(vfs.dest('resources/docs'))
console.log('Done generating API documentation!')
})
function buildChildDoc(inputPath, outputPath, actionMap, config) {
return documentation.build(inputPath, {...INPUT_CONFIG, ...config})
.then(res => {
// res is an array of parsed comments with inferred properties
// and more: everything you need to build documentation or
// any other kind of code data.
let processed = res;
if (outputPath.includes('actions.md')) {
// add action type and updater links to action
processed = res.map(node => _appendActionTypesAndUpdatersToActions(node, actionMap));
} else if (inputPath.some(p => p.includes('reducers'))) {
// add action type and updater links to action
processed = res.map(node => _appendActionToUpdaters(node, actionMap));
}
return documentation.formats.remark(processed, OUT_CONFIG)
})
async function generate(app, sources, output) {
let task = app.log(`generating API references... (${output})`, true);
// start the `documentation` task.
try {
let builder = await documentation.build(sources, {});
// format the result using markdown.
let contents = await documentation.formats.md(builder);
// write the final result.
fs.ensureDirSync(path.dirname(output));
fs.writeFileSync(output, contents);
task();
app.log(`${colors.bold(colors.green('documentation created.'))} ${colors.grey(`(${output.localPath})`)}`);
} catch(err) {
// ops.
task();
throw err;
}
}
*/
const path = require('path'),
documentation = require('documentation'),
Promise = require('bluebird'),
fs = Promise.promisifyAll(require('fs'));
/**
* Cotains type definitions and where should their link point to
*
* @type {Object}
*/
const paths = require('param-links');
// Build Documentation
documentation
.build(['index.js'], {
shallow: true,
hljs: {
highlightAuto: true,
languages: ['js', 'json', 'sql', 'sh', 'bash']
}
})
.then(res => {
return documentation.formats.md(res, {
paths,
hljs: {
highlightAuto: true,
languages: ['js', 'json', 'sql', 'sh', 'bash']
}
});
})
async function updateDoc() {
const comments = await build('./lib/taiko.js', { shallow: true });
const jsonDocString = removeLocation(comments);
writeFileSync('./lib/api.json', jsonDocString);
console.log('Successfully save json docs to lib/api.json.');
}
const transform = function (code, filePath) {
const ret = null;
if (!filePath || !filePath.includes(path.join(projectRoot, 'src'))) {
return ret;
}
documentation
.build([filePath], { extension: 'js', shallow: true })
.then((docs) => {
if (!docs || !docs.length) {
return;
}
docs.forEach((doc) => {
if (!doc.members || !doc.members.instance || !doc.members.instance.length) {
return;
}
const methods = doc.members.instance;
methods.forEach((method) => {
if (method.deprecated) {
logDeprecation(doc.name, method.name, method.deprecated);
}
const all = async () => {
const ast = await build(
files,
Object.assign(options, {
config: tocPath
})
);
let source = await formats.md(ast, {});
const toc = await _toc();
source = source.replace(/^## apr/, '# apr');
source = source.replace(//, toc);
await writeFile(path.join(__dirname, '../readme.md'), source, {
encoding: 'utf-8'
});
};
function getMarkdown(documentationSource, args) {
return documentation
.build([{ source: documentationSource }], { shallow: true })
.then(comments => buildMarkdown(comments, args));
}
function buildDocumentation({ title, entry, source, pattern, tag, visitor }) {
const documentationSource = buildDocumentationSource({
entry,
source,
pattern,
tag,
visitor,
});
return documentation
.build([{ source: documentationSource || ' ' }], { shallow: true })
.then(
comments =>
buildMarkdown(comments, {
title: title,
}),
error => {
if (error.loc) {
error.codeFrame = codeFrameColumns(documentationSource, {
start: error.loc,
});
error.message += `\n${error.codeFrame}`;
}
error.message = `"${title}" documentation source${
source ? '' : ` (${entry || pattern})`