Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const path = require('path')
const semverDiff = require('semver-diff')
const semver = require('semver')
const fs = require('fs-extra')
const json2md = require('json2md')
const vueDocgen = require('vue-docgen-api')
// Add convert for markdown anchor
json2md.converters.anchor = (anchor, json) => {
if (!anchor.text) {
return "";
}
return `[${anchor.text}](${anchor.source})`;
};
/**
* convert .vue file into JSON object then convert to markdown file
* @param {String} file -- file path of raw Vue component file
* @param {Object} info -- packag.json
*/
function docsBuild(file, info) {
console.log(`Processing file: ${file}\n`)
const vueObj = vueDocgen.parse(file)
const path = require('path')
const semverDiff = require('semver-diff')
const semver = require('semver')
const fs = require('fs-extra')
const json2md = require('json2md')
const vueDocgen = require('vue-docgen-api')
const glob = require('glob')
// Add convert for markdown anchor
json2md.converters.anchor = (anchor, json) => {
if (!anchor.text)
return "";
return `[${anchor.text}](${anchor.source})`;
};
// pull in *.vue files from directory
glob('src/+(components|compositions)/**/*.vue', {ignore: ['**/node_modules/**', '**/examples/**', '**/demos/**']}, (compErr, files) => {
if(compErr)
throw new Error(`Error while trying to find single file Vue components:\n${compErr}`)
// convert *.vue files into JSON objects then convert to *.md files
files.forEach((file) => {
console.log(`Processing file: ${file}\n`)
const vueObj = vueDocgen.parse(file)
it("Custom types", () => {
const customConverter: json2md.ConverterCallback = (input, json2md) => {
return `Hello ${input} world!`;
};
json2md.converters.customConverter = customConverter;
json2md([
{
customConverter: EXAMPLE_STRING
}
]);
});
it("Use converter", () => {
const blockquote: string = json2md.converters.blockquote(EXAMPLE_STRING, json2md);
const img: string = json2md.converters.img({
title: EXAMPLE_STRING,
source: EXAMPLE_STRING
}, json2md);
});
const readFile = util.promisify(FS.readFile);
const readdir = util.promisify(FS.readdir);
const writeFile = util.promisify(FS.writeFile);
const categories = {};
const toc = [];
json2md.converters.ul = async (array) => {
return `- ${array.join('\n- ')}`;
};
json2md.converters.md = async (filepath) => {
return await readFile(filepath, {encoding: 'utf8'});
};
json2md.converters.toc = (contents) => {
const indent = 4;
const ul = '-';
const space = ' '.repeat(indent);
const usedHeaders = {};
const headers = [];
contents.forEach((c) => {
const {name, level} = c;
let anchor = name.trim().toLowerCase().replace(/\s+/g, '-').replace(/\-+$/, '');
const usedHeader = usedHeaders[anchor];
if (usedHeader) {
usedHeaders[anchor] = usedHeader + 1;
anchor = `${anchor}-${usedHeader}`;
} else {
usedHeaders[anchor] = 1;
}
.replace(/\s/g, '')
.replace(/^(.)/, ($1) => $1.toUpperCase());
const getStat = util.promisify(FS.stat);
const readFile = util.promisify(FS.readFile);
const readdir = util.promisify(FS.readdir);
const writeFile = util.promisify(FS.writeFile);
const categories = {};
const toc = [];
json2md.converters.ul = async (array) => {
return `- ${array.join('\n- ')}`;
};
json2md.converters.md = async (filepath) => {
return await readFile(filepath, {encoding: 'utf8'});
};
json2md.converters.toc = (contents) => {
const indent = 4;
const ul = '-';
const space = ' '.repeat(indent);
const usedHeaders = {};
const headers = [];
contents.forEach((c) => {
const {name, level} = c;
let anchor = name.trim().toLowerCase().replace(/\s+/g, '-').replace(/\-+$/, '');
const usedHeader = usedHeaders[anchor];
if (usedHeader) {
usedHeaders[anchor] = usedHeader + 1;
const absPath = (...paths) => Path.resolve(__dirname, ...paths);
const relativePath = (path) => Path.relative(__dirname, path);
const toCamelCase = (str) => str
.replace(/\s(.)/g, ($1) => $1.toUpperCase())
.replace(/\s/g, '')
.replace(/^(.)/, ($1) => $1.toUpperCase());
const getStat = util.promisify(FS.stat);
const readFile = util.promisify(FS.readFile);
const readdir = util.promisify(FS.readdir);
const writeFile = util.promisify(FS.writeFile);
const categories = {};
const toc = [];
json2md.converters.ul = async (array) => {
return `- ${array.join('\n- ')}`;
};
json2md.converters.md = async (filepath) => {
return await readFile(filepath, {encoding: 'utf8'});
};
json2md.converters.toc = (contents) => {
const indent = 4;
const ul = '-';
const space = ' '.repeat(indent);
const usedHeaders = {};
const headers = [];
contents.forEach((c) => {
const {name, level} = c;