-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.mjs
58 lines (46 loc) · 1.19 KB
/
menu.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import * as path from 'path';
import * as fs from 'fs';
let counter = 2;
const traverseFolder = (folderPath, parentName = '') => {
const files = fs.readdirSync(folderPath);
const tree = [];
for (const file of files) {
const filePath = path.join(folderPath, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) {
const children = traverseFolder(
filePath,
parentName ? `${parentName}/${file}` : file,
counter,
);
const node = {
label: file,
key: `${counter++}`,
path: parentName ? `/${parentName}/${file}` : `/${file}`,
// path: filePath,
};
if (children.length) {
node.children = children;
}
tree.push(node);
}
}
return tree;
};
(() => {
const folderPath = path.resolve('./src/app');
const result = traverseFolder(folderPath);
result.unshift({
key: '1',
label: 'home',
path: '/',
});
const folder = path.resolve('./src/utils/menu/folder.ts');
// console.log(result);
fs.writeFileSync(
folder,
`export const MENU_PATH_DATA = ${JSON.stringify(result, null, 2)}
`,
);
console.log(`menu info 👉🏻 ${folder}`);
})();