Skip to content

Commit 91279bb

Browse files
committed
fix(file): check if file exists
1 parent 9d581e7 commit 91279bb

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

example/documentation/code/config.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/vue-sidebar.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { join } from 'path';
1+
import fs from 'fs';
22
interface Node {
33
name: string;
44
children: any[];
@@ -23,13 +23,15 @@ export const generateVueSidebar = ({
2323
const buildChildren = (children: any[], name: string, depth: number) => {
2424
let newChildren: any[] = [];
2525

26-
children.forEach(child => {
27-
if (child.children && child.children.length > 0) {
28-
newChildren = newChildren.concat(buildChildren(child.children, child.name, depth + 1));
29-
} else if (child.fullPath) {
30-
newChildren.push(child.fullPath.replace(`${srcFolder}/`, ''));
26+
for (const child of children) {
27+
if (fs.existsSync(child.fullPath)) {
28+
if (child.children && child.children.length > 0) {
29+
newChildren = newChildren.concat(buildChildren(child.children, child.name, depth + 1));
30+
} else if (child.fullPath) {
31+
newChildren.push(child.fullPath.replace(`${srcFolder}/`, ''));
32+
}
3133
}
32-
});
34+
}
3335

3436
return newChildren;
3537
};

0 commit comments

Comments
 (0)