Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const _writeMarkdown = ({ filename, outputDir, result }) => {
const destination = Path.format({
dir: outputDir,
name: filename,
ext: ".md"
});
const render = new Render(result);
const markdown = render.renderMarkdown() || {};
// @ts-ignore
fs.writeFileSync(destination, markdown.content || "");
};
const writeApi = ({ result }) => {
function getMdFromSfc (filePath) {
if (!fs.existsSync(filePath)) return `Not found: ${filePath}`
try {
const content = fs.readFileSync(filePath, 'utf-8')
const parserRes = vueseParser(content, parserOptions)
if (isFn(useParser)) return useParser(parserRes)
const vueseRender = new VueseRender(parserRes, renderOptions)
if (isFn(useRender)) return useRender(vueseRender)
const renderRes = vueseRender.render()
const markdownRes = vueseRender.renderMarkdown()
return isFn(useAll)
? useAll({ content, parserRes, renderRes, markdownRes })
: markdownRes.content
} catch (e) {
return e.message
}
}
}
return files.map(async (p: string) => {
const abs = path.resolve(p)
const source = await fs.readFile(abs, 'utf-8')
try {
const parserRes = parser(source, {
babelParserPlugins,
basedir: path.dirname(abs)
})
const r = new Render(parserRes)
let markdownRes = r.renderMarkdown()
if (!markdownRes) return
let str = markdownRes.content
let compName = markdownRes.componentName
? markdownRes.componentName
: path.basename(abs, '.vue')
const groupName = markdownRes.groupName
str = str.replace(/\[name\]/g, compName)
let targetDir = ''
let targetFile = ''
if (genType === 'markdown' && markdownDir === '*') {
targetDir = path.dirname(abs)
targetFile = markdownFile || compName