UNPKG

kompendium

Version:

Documentation generator for Stencil components

30 lines (29 loc) 847 B
import { basename, dirname, resolve } from 'path'; import { readFile } from './filesystem'; export async function findGuides(config) { const nodes = config.guides.map(createMenuNode('/')).flat(); const promises = nodes.map(createGuide); return Promise.all(promises); } export const createMenuNode = (path) => (guide) => { if (typeof guide !== 'string') { const newPath = path + guide.name + '/'; return guide.children.map(createMenuNode(newPath)).flat(); } return { menupath: path, filepath: guide, }; }; export const createGuide = async ({ menupath: path, filepath, }) => { const content = await readFile(filepath); return { dirPath: dirname(filepath), fileName: basename(filepath), filePath: resolve(filepath), data: { path: path + basename(filepath), }, content: content, }; };