Skip to content

Commit

Permalink
fix(file): check if file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Sep 2, 2021
1 parent 9d581e7 commit 91279bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/documentation/code/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/lib/vue-sidebar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'path';
import fs from 'fs';
interface Node {
name: string;
children: any[];
Expand All @@ -23,13 +23,15 @@ export const generateVueSidebar = ({
const buildChildren = (children: any[], name: string, depth: number) => {
let newChildren: any[] = [];

children.forEach(child => {
if (child.children && child.children.length > 0) {
newChildren = newChildren.concat(buildChildren(child.children, child.name, depth + 1));
} else if (child.fullPath) {
newChildren.push(child.fullPath.replace(`${srcFolder}/`, ''));
for (const child of children) {
if (fs.existsSync(child.fullPath)) {
if (child.children && child.children.length > 0) {
newChildren = newChildren.concat(buildChildren(child.children, child.name, depth + 1));
} else if (child.fullPath) {
newChildren.push(child.fullPath.replace(`${srcFolder}/`, ''));
}
}
});
}

return newChildren;
};
Expand Down

0 comments on commit 91279bb

Please sign in to comment.