vue-docgen-cli
Version:
Generate documentation markdown files from VueJs components using the vue-docgen-api.
55 lines • 2.45 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.isParamTag = exports.getExamplesFilePaths = void 0;
const path_1 = require("path");
const fs_1 = require("fs");
const utils_1 = require("./utils");
function getExamplesFilePaths(tags, componentDirname) {
const exampleTags = [...(tags.example || []), ...(tags.examples || [])];
return (exampleTags.map((exampleTag) => isParamTag(exampleTag)
? (0, path_1.join)(componentDirname, exampleTag.description)
: (0, path_1.join)(componentDirname, exampleTag.content)) || []);
}
exports.getExamplesFilePaths = getExamplesFilePaths;
async function getDocsBlocks(absolutePath, doc, getDocFileName, rootPath, editLinkLabel, getRepoEditUrl) {
const docsBlocks = doc.docsBlocks || [];
const docFilesPaths = (0, utils_1.normalizePaths)(getDocFileName(absolutePath));
const docFilePaths = docFilesPaths
.map(p => (getRepoEditUrl ? (0, utils_1.findFileCaseInsensitive)(p) : p))
.filter(Boolean);
await Promise.allSettled(docFilePaths.map(async (docFilePath) => {
docsBlocks.push(`${getRepoEditUrl
? `
<a href="${getRepoEditUrl(relativeUrl(rootPath, docFilePath))}" class="docgen-edit-link">${editLinkLabel}</a>
`
: ''}
${await fs_1.promises.readFile(docFilePath, 'utf8')}`);
}));
// load @examples tags into the docsBlocks
if (doc.tags?.example || doc.tags?.examples) {
const componentDirname = (0, path_1.dirname)(absolutePath);
const examplesFilePaths = getExamplesFilePaths(doc.tags, componentDirname);
await Promise.all(examplesFilePaths.map(async (examplePath) => {
const ep = getRepoEditUrl ? (0, utils_1.findFileCaseInsensitive)(examplePath) : examplePath;
if (ep) {
docsBlocks.push(`${getRepoEditUrl
? `
<a href="${getRepoEditUrl(relativeUrl(rootPath, ep))}" class="docgen-edit-link">${editLinkLabel}</a>
`
: ''}
${await fs_1.promises.readFile(ep, 'utf8')}`);
}
}));
}
return docsBlocks;
}
exports.default = getDocsBlocks;
const separatorRE = new RegExp(`\\${path_1.sep}`, 'g');
function relativeUrl(rootPath, docFilePath) {
return (0, path_1.relative)(rootPath, docFilePath).replace(separatorRE, '/');
}
function isParamTag(tag) {
return !!tag.description;
}
exports.isParamTag = isParamTag;
//# sourceMappingURL=getDocsBlocks.js.map
;