kompendium
Version:
Documentation generator for Stencil components
31 lines (30 loc) • 955 B
JavaScript
import { basename, dirname, resolve } from "path";
import { readFile } from "fs/promises";
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, 'utf8');
return {
dirPath: dirname(filepath),
fileName: basename(filepath),
filePath: resolve(filepath),
data: {
path: path + basename(filepath),
},
content: content,
};
};
//# sourceMappingURL=guides.js.map