polen 0.10.0-next.4 → 0.10.0-next.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/build/api/config/load.js +5 -5
- package/build/api/config/load.js.map +1 -1
- package/build/api/config-resolver/resolve.js +2 -2
- package/build/api/config-resolver/resolve.js.map +1 -1
- package/build/api/content/$$.d.ts +5 -0
- package/build/api/content/$$.d.ts.map +1 -0
- package/build/api/content/$$.js +5 -0
- package/build/api/content/$$.js.map +1 -0
- package/build/api/content/$.d.ts +2 -0
- package/build/api/content/$.d.ts.map +1 -0
- package/build/api/content/$.js +2 -0
- package/build/api/content/$.js.map +1 -0
- package/build/api/content/metadata.d.ts +10 -0
- package/build/api/content/metadata.d.ts.map +1 -0
- package/build/api/content/metadata.js +9 -0
- package/build/api/content/metadata.js.map +1 -0
- package/build/api/content/page.d.ts +11 -0
- package/build/api/content/page.d.ts.map +1 -0
- package/build/api/content/page.js +2 -0
- package/build/api/content/page.js.map +1 -0
- package/build/api/content/scan.d.ts +19 -0
- package/build/api/content/scan.d.ts.map +1 -0
- package/build/api/content/scan.js +57 -0
- package/build/api/content/scan.js.map +1 -0
- package/build/{lib/file-router/sidebar/types.d.ts → api/content/sidebar.d.ts} +8 -1
- package/build/api/content/sidebar.d.ts.map +1 -0
- package/build/api/content/sidebar.js +90 -0
- package/build/api/content/sidebar.js.map +1 -0
- package/build/api/schema/data-sources/schema-directory/schema-directory.js +1 -1
- package/build/api/schema/data-sources/schema-directory/schema-directory.js.map +1 -1
- package/build/api/vite/plugins/branding/index.js +4 -4
- package/build/api/vite/plugins/branding/index.js.map +1 -1
- package/build/api/vite/plugins/core.js +4 -4
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/pages.d.ts +6 -8
- package/build/api/vite/plugins/pages.d.ts.map +1 -1
- package/build/api/vite/plugins/pages.js +99 -155
- package/build/api/vite/plugins/pages.js.map +1 -1
- package/build/api/vite/plugins/serve.js +5 -5
- package/build/api/vite/plugins/serve.js.map +1 -1
- package/build/cli/_/self-contained-mode.js +5 -5
- package/build/cli/_/self-contained-mode.js.map +1 -1
- package/build/exports/components.d.ts +2 -0
- package/build/exports/components.d.ts.map +1 -0
- package/build/exports/components.js +2 -0
- package/build/exports/components.js.map +1 -0
- package/build/lib/demos/config-schema.d.ts +14 -14
- package/build/lib/file-router/file-router.d.ts +0 -2
- package/build/lib/file-router/file-router.d.ts.map +1 -1
- package/build/lib/file-router/file-router.js +0 -2
- package/build/lib/file-router/file-router.js.map +1 -1
- package/build/lib/file-router/route.d.ts +2 -0
- package/build/lib/file-router/route.d.ts.map +1 -1
- package/build/lib/file-router/route.js.map +1 -1
- package/build/lib/file-router/scan.d.ts.map +1 -1
- package/build/lib/file-router/scan.js +16 -12
- package/build/lib/file-router/scan.js.map +1 -1
- package/build/singletons/debug.d.ts +1 -1
- package/build/singletons/debug.d.ts.map +1 -1
- package/build/singletons/debug.js +1 -1
- package/build/singletons/debug.js.map +1 -1
- package/build/template/components/ThemeToggle.d.ts +3 -0
- package/build/template/components/ThemeToggle.d.ts.map +1 -0
- package/build/template/components/ThemeToggle.jsx +10 -0
- package/build/template/components/ThemeToggle.jsx.map +1 -0
- package/build/template/components/content/$$.d.ts +2 -0
- package/build/template/components/content/$$.d.ts.map +1 -0
- package/build/template/components/content/$$.js +2 -0
- package/build/template/components/content/$$.js.map +1 -0
- package/build/template/components/sidebar/Sidebar.d.ts +2 -2
- package/build/template/components/sidebar/Sidebar.d.ts.map +1 -1
- package/build/template/components/sidebar/SidebarItem.d.ts +3 -3
- package/build/template/components/sidebar/SidebarItem.d.ts.map +1 -1
- package/build/template/components/sidebar/SidebarItem.jsx +1 -1
- package/build/template/components/sidebar/SidebarItem.jsx.map +1 -1
- package/build/template/contexts/ThemeContext.d.ts +12 -0
- package/build/template/contexts/ThemeContext.d.ts.map +1 -0
- package/build/template/contexts/ThemeContext.jsx +41 -0
- package/build/template/contexts/ThemeContext.jsx.map +1 -0
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.jsx +15 -9
- package/build/template/routes/root.jsx.map +1 -1
- package/package.json +10 -3
- package/src/api/config/load.ts +5 -5
- package/src/api/config-resolver/resolve.ts +2 -2
- package/src/api/content/$$.ts +4 -0
- package/src/api/content/$.test.ts +72 -0
- package/src/api/content/$.ts +1 -0
- package/src/api/content/metadata.ts +11 -0
- package/src/api/content/page.ts +12 -0
- package/src/api/content/scan.ts +82 -0
- package/src/api/content/sidebar.ts +136 -0
- package/src/api/schema/data-sources/schema-directory/schema-directory.ts +1 -1
- package/src/api/vite/plugins/branding/index.ts +4 -4
- package/src/api/vite/plugins/core.ts +4 -4
- package/src/api/vite/plugins/pages.ts +117 -171
- package/src/api/vite/plugins/serve.ts +5 -5
- package/src/cli/_/self-contained-mode.ts +5 -5
- package/src/exports/components.ts +1 -0
- package/src/lib/deployment/$$.ts +1 -1
- package/src/lib/deployment/$.test.ts +3 -3
- package/src/lib/deployment/$.ts +1 -1
- package/src/lib/file-router/file-router.ts +0 -2
- package/src/lib/file-router/linter.test.ts +2 -0
- package/src/lib/file-router/route.ts +2 -0
- package/src/lib/file-router/scan.ts +19 -13
- package/src/lib/task/$.test.ts +3 -3
- package/src/singletons/debug.ts +1 -1
- package/src/template/components/ThemeToggle.tsx +21 -0
- package/src/template/components/content/$$.ts +1 -0
- package/src/template/components/sidebar/Sidebar.tsx +2 -2
- package/src/template/components/sidebar/SidebarItem.tsx +8 -8
- package/src/template/contexts/ThemeContext.tsx +60 -0
- package/src/template/routes/root.tsx +15 -9
- package/build/lib/file-router/scan-tree.d.ts +0 -20
- package/build/lib/file-router/scan-tree.d.ts.map +0 -1
- package/build/lib/file-router/scan-tree.js +0 -158
- package/build/lib/file-router/scan-tree.js.map +0 -1
- package/build/lib/file-router/sidebar/index.d.ts +0 -3
- package/build/lib/file-router/sidebar/index.d.ts.map +0 -1
- package/build/lib/file-router/sidebar/index.js +0 -4
- package/build/lib/file-router/sidebar/index.js.map +0 -1
- package/build/lib/file-router/sidebar/sidebar-tree.d.ts +0 -9
- package/build/lib/file-router/sidebar/sidebar-tree.d.ts.map +0 -1
- package/build/lib/file-router/sidebar/sidebar-tree.js +0 -85
- package/build/lib/file-router/sidebar/sidebar-tree.js.map +0 -1
- package/build/lib/file-router/sidebar/types.d.ts.map +0 -1
- package/build/lib/file-router/sidebar/types.js +0 -2
- package/build/lib/file-router/sidebar/types.js.map +0 -1
- package/build/lib/tree/index.d.ts +0 -3
- package/build/lib/tree/index.d.ts.map +0 -1
- package/build/lib/tree/index.js +0 -2
- package/build/lib/tree/index.js.map +0 -1
- package/build/lib/tree/tree.d.ts +0 -62
- package/build/lib/tree/tree.d.ts.map +0 -1
- package/build/lib/tree/tree.js +0 -134
- package/build/lib/tree/tree.js.map +0 -1
- package/src/lib/file-router/scan-tree.test.ts +0 -189
- package/src/lib/file-router/scan-tree.ts +0 -205
- package/src/lib/file-router/sidebar/index.ts +0 -3
- package/src/lib/file-router/sidebar/sidebar-tree.test.ts +0 -123
- package/src/lib/file-router/sidebar/sidebar-tree.ts +0 -110
- package/src/lib/file-router/sidebar/types.ts +0 -19
- package/src/lib/tree/index.ts +0 -2
- package/src/lib/tree/tree.test.ts +0 -117
- package/src/lib/tree/tree.ts +0 -183
package/build/lib/tree/tree.js
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Generic tree data structure and utilities
|
3
|
-
*/
|
4
|
-
/**
|
5
|
-
* Create a new tree node
|
6
|
-
*/
|
7
|
-
export const node = (value, children = []) => ({
|
8
|
-
value,
|
9
|
-
children,
|
10
|
-
});
|
11
|
-
/**
|
12
|
-
* Map over a tree, transforming each node's value
|
13
|
-
*/
|
14
|
-
export const map = (tree, mapper, depth = 0, path = []) => {
|
15
|
-
const newPath = [...path, tree.value];
|
16
|
-
return {
|
17
|
-
value: mapper(tree.value, depth, path),
|
18
|
-
children: tree.children.map(child => map(child, mapper, depth + 1, newPath)),
|
19
|
-
};
|
20
|
-
};
|
21
|
-
/**
|
22
|
-
* Visit each node in the tree (depth-first)
|
23
|
-
*/
|
24
|
-
export const visit = (tree, visitor, depth = 0, path = []) => {
|
25
|
-
visitor(tree, depth, path);
|
26
|
-
const newPath = [...path, tree.value];
|
27
|
-
tree.children.forEach(child => visit(child, visitor, depth + 1, newPath));
|
28
|
-
};
|
29
|
-
/**
|
30
|
-
* Find a node in the tree
|
31
|
-
*/
|
32
|
-
export const find = (tree, predicate, depth = 0, path = []) => {
|
33
|
-
if (predicate(tree.value, depth, path)) {
|
34
|
-
return tree;
|
35
|
-
}
|
36
|
-
const newPath = [...path, tree.value];
|
37
|
-
for (const child of tree.children) {
|
38
|
-
const found = find(child, predicate, depth + 1, newPath);
|
39
|
-
if (found)
|
40
|
-
return found;
|
41
|
-
}
|
42
|
-
return undefined;
|
43
|
-
};
|
44
|
-
/**
|
45
|
-
* Filter tree nodes (keeps structure, removes non-matching nodes)
|
46
|
-
*/
|
47
|
-
export const filter = (tree, predicate, depth = 0, path = []) => {
|
48
|
-
const newPath = [...path, tree.value];
|
49
|
-
const filteredChildren = tree.children
|
50
|
-
.map(child => filter(child, predicate, depth + 1, newPath))
|
51
|
-
.filter((child) => child !== undefined);
|
52
|
-
// Keep node if it matches or has matching children
|
53
|
-
if (predicate(tree.value, depth, path) || filteredChildren.length > 0) {
|
54
|
-
return {
|
55
|
-
value: tree.value,
|
56
|
-
children: filteredChildren,
|
57
|
-
};
|
58
|
-
}
|
59
|
-
return undefined;
|
60
|
-
};
|
61
|
-
/**
|
62
|
-
* Sort a tree's children at each level
|
63
|
-
*/
|
64
|
-
export const sort = (tree, compareFn) => ({
|
65
|
-
value: tree.value,
|
66
|
-
children: tree.children
|
67
|
-
.map(child => sort(child, compareFn))
|
68
|
-
.sort((a, b) => compareFn(a.value, b.value)),
|
69
|
-
});
|
70
|
-
/**
|
71
|
-
* Flatten a tree into an array (depth-first)
|
72
|
-
*/
|
73
|
-
export const flatten = (tree) => {
|
74
|
-
const result = [tree.value];
|
75
|
-
tree.children.forEach(child => {
|
76
|
-
result.push(...flatten(child));
|
77
|
-
});
|
78
|
-
return result;
|
79
|
-
};
|
80
|
-
/**
|
81
|
-
* Get the depth of the tree
|
82
|
-
*/
|
83
|
-
export const depth = (tree) => {
|
84
|
-
if (tree.children.length === 0)
|
85
|
-
return 0;
|
86
|
-
return 1 + Math.max(...tree.children.map(depth));
|
87
|
-
};
|
88
|
-
/**
|
89
|
-
* Count total nodes in the tree
|
90
|
-
*/
|
91
|
-
export const count = (tree) => {
|
92
|
-
return 1 + tree.children.reduce((sum, child) => sum + count(child), 0);
|
93
|
-
};
|
94
|
-
/**
|
95
|
-
* Check if a node is a leaf (has no children)
|
96
|
-
*/
|
97
|
-
export const isLeaf = (node) => {
|
98
|
-
return node.children.length === 0;
|
99
|
-
};
|
100
|
-
/**
|
101
|
-
* Get all leaf nodes
|
102
|
-
*/
|
103
|
-
export const leaves = (tree) => {
|
104
|
-
if (isLeaf(tree))
|
105
|
-
return [tree];
|
106
|
-
return tree.children.flatMap(leaves);
|
107
|
-
};
|
108
|
-
/**
|
109
|
-
* Build a tree from a flat list with parent references
|
110
|
-
*/
|
111
|
-
export const fromList = (items, rootId) => {
|
112
|
-
const itemMap = new Map(items.map(item => [item.id, item]));
|
113
|
-
const roots = [];
|
114
|
-
const nodeMap = new Map();
|
115
|
-
// Create all nodes
|
116
|
-
items.forEach(item => {
|
117
|
-
nodeMap.set(item.id, node(item));
|
118
|
-
});
|
119
|
-
// Build hierarchy
|
120
|
-
items.forEach(item => {
|
121
|
-
const itemNode = nodeMap.get(item.id);
|
122
|
-
if (item.parentId === rootId) {
|
123
|
-
roots.push(itemNode);
|
124
|
-
}
|
125
|
-
else if (item.parentId) {
|
126
|
-
const parent = nodeMap.get(item.parentId);
|
127
|
-
if (parent) {
|
128
|
-
parent.children.push(itemNode);
|
129
|
-
}
|
130
|
-
}
|
131
|
-
});
|
132
|
-
return roots;
|
133
|
-
};
|
134
|
-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;aAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACzC,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAChC,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
@@ -1,189 +0,0 @@
|
|
1
|
-
import { Tree } from '#lib/tree/index'
|
2
|
-
import { describe, expect, test } from 'vitest'
|
3
|
-
import type { RouteTreeNode } from './scan-tree.ts'
|
4
|
-
|
5
|
-
// Helper to create a mock route tree structure for testing
|
6
|
-
const mockRouteTree = (structure: Record<string, any>): RouteTreeNode => {
|
7
|
-
const sortNodes = (nodes: RouteTreeNode[]): RouteTreeNode[] => {
|
8
|
-
return nodes.sort((a, b) => {
|
9
|
-
// If both have orders, sort by order
|
10
|
-
if (a.value.order !== undefined && b.value.order !== undefined) {
|
11
|
-
return a.value.order - b.value.order
|
12
|
-
}
|
13
|
-
// If only one has order, it comes first
|
14
|
-
if (a.value.order !== undefined) return -1
|
15
|
-
if (b.value.order !== undefined) return 1
|
16
|
-
// Otherwise sort alphabetically
|
17
|
-
return a.value.name.localeCompare(b.value.name)
|
18
|
-
})
|
19
|
-
}
|
20
|
-
|
21
|
-
const buildNode = (name: string, value: any): RouteTreeNode => {
|
22
|
-
const parsed = name.match(/^(?<order>\d+)[_-](?<name>.+)$/)
|
23
|
-
const nodeName = parsed?.groups?.[`name`] ?? name
|
24
|
-
const order = parsed?.groups?.[`order`] ? parseInt(parsed.groups[`order`], 10) : undefined
|
25
|
-
|
26
|
-
if (typeof value === 'object' && !value.isFile) {
|
27
|
-
// Directory node
|
28
|
-
const children = Object.entries(value).map(([childName, childValue]) => buildNode(childName, childValue))
|
29
|
-
return Tree.node(
|
30
|
-
{ name: nodeName, order, type: 'directory' },
|
31
|
-
sortNodes(children),
|
32
|
-
)
|
33
|
-
} else {
|
34
|
-
// File node - strip extension (but keep 'index' as is)
|
35
|
-
const nameWithoutExtension = nodeName.replace(/\.(md|mdx)$/, '')
|
36
|
-
return Tree.node({ name: nameWithoutExtension, order, type: 'file', route: value })
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
const children = Object.entries(structure).map(([name, value]) => buildNode(name, value))
|
41
|
-
return Tree.node(
|
42
|
-
{ name: 'root', type: 'directory' },
|
43
|
-
sortNodes(children),
|
44
|
-
)
|
45
|
-
}
|
46
|
-
|
47
|
-
describe('scan-tree structure', () => {
|
48
|
-
test('builds tree from flat file structure', () => {
|
49
|
-
const tree = mockRouteTree({
|
50
|
-
'getting-started.md': { isFile: true },
|
51
|
-
'guide': {
|
52
|
-
'introduction.md': { isFile: true },
|
53
|
-
'basics.md': { isFile: true },
|
54
|
-
},
|
55
|
-
'api': {
|
56
|
-
'reference.md': { isFile: true },
|
57
|
-
},
|
58
|
-
})
|
59
|
-
|
60
|
-
expect(tree.value.name).toBe('root')
|
61
|
-
expect(tree.children).toHaveLength(3)
|
62
|
-
|
63
|
-
const guide = tree.children.find(c => c.value.name === 'guide')
|
64
|
-
expect(guide).toBeDefined()
|
65
|
-
expect(guide!.children).toHaveLength(2)
|
66
|
-
})
|
67
|
-
|
68
|
-
test('handles numbered prefixes on files', () => {
|
69
|
-
const tree = mockRouteTree({
|
70
|
-
'10_getting-started.md': { isFile: true },
|
71
|
-
'20_configuration.md': { isFile: true },
|
72
|
-
'30_advanced.md': { isFile: true },
|
73
|
-
})
|
74
|
-
|
75
|
-
const children = tree.children
|
76
|
-
expect(children[0]!.value).toMatchObject({ name: 'getting-started', order: 10 })
|
77
|
-
expect(children[1]!.value).toMatchObject({ name: 'configuration', order: 20 })
|
78
|
-
expect(children[2]!.value).toMatchObject({ name: 'advanced', order: 30 })
|
79
|
-
})
|
80
|
-
|
81
|
-
test('handles numbered prefixes on directories', () => {
|
82
|
-
const tree = mockRouteTree({
|
83
|
-
'10_guide': {
|
84
|
-
'intro.md': { isFile: true },
|
85
|
-
},
|
86
|
-
'20_api': {
|
87
|
-
'reference.md': { isFile: true },
|
88
|
-
},
|
89
|
-
'05_quickstart': {
|
90
|
-
'index.md': { isFile: true },
|
91
|
-
},
|
92
|
-
})
|
93
|
-
|
94
|
-
const children = tree.children
|
95
|
-
expect(children[0]!.value).toMatchObject({ name: 'quickstart', order: 5 })
|
96
|
-
expect(children[1]!.value).toMatchObject({ name: 'guide', order: 10 })
|
97
|
-
expect(children[2]!.value).toMatchObject({ name: 'api', order: 20 })
|
98
|
-
})
|
99
|
-
|
100
|
-
test('handles mixed numbered and non-numbered items', () => {
|
101
|
-
const tree = mockRouteTree({
|
102
|
-
'10_guide': {
|
103
|
-
'intro.md': { isFile: true },
|
104
|
-
},
|
105
|
-
'troubleshooting': {
|
106
|
-
'common.md': { isFile: true },
|
107
|
-
},
|
108
|
-
'05_quickstart': {
|
109
|
-
'index.md': { isFile: true },
|
110
|
-
},
|
111
|
-
'api': {
|
112
|
-
'reference.md': { isFile: true },
|
113
|
-
},
|
114
|
-
})
|
115
|
-
|
116
|
-
// After sorting: numbered items first (5, 10), then alphabetical (api, troubleshooting)
|
117
|
-
const childNames = tree.children.map(c => c.value.name)
|
118
|
-
expect(childNames).toEqual(['quickstart', 'guide', 'api', 'troubleshooting'])
|
119
|
-
})
|
120
|
-
|
121
|
-
test('handles nested numbered prefixes', () => {
|
122
|
-
const tree = mockRouteTree({
|
123
|
-
'10_guide': {
|
124
|
-
'10_getting-started.md': { isFile: true },
|
125
|
-
'20_basics.md': { isFile: true },
|
126
|
-
'troubleshooting.md': { isFile: true },
|
127
|
-
'05_prerequisites.md': { isFile: true },
|
128
|
-
},
|
129
|
-
})
|
130
|
-
|
131
|
-
const guide = tree.children[0]!
|
132
|
-
expect(guide.value.name).toBe('guide')
|
133
|
-
|
134
|
-
const guideChildNames = guide.children.map(c => c.value.name)
|
135
|
-
expect(guideChildNames).toEqual(['prerequisites', 'getting-started', 'basics', 'troubleshooting'])
|
136
|
-
})
|
137
|
-
|
138
|
-
test('handles index files', () => {
|
139
|
-
const tree = mockRouteTree({
|
140
|
-
'guide': {
|
141
|
-
'index.md': { isFile: true },
|
142
|
-
'intro.md': { isFile: true },
|
143
|
-
},
|
144
|
-
})
|
145
|
-
|
146
|
-
const guide = tree.children[0]!
|
147
|
-
expect(guide.children).toHaveLength(2)
|
148
|
-
expect(guide.children.map(c => c.value.name)).toContain('index')
|
149
|
-
expect(guide.children.map(c => c.value.name)).toContain('intro')
|
150
|
-
})
|
151
|
-
|
152
|
-
test('creates directory nodes with correct type', () => {
|
153
|
-
const tree = mockRouteTree({
|
154
|
-
'10_guide': {
|
155
|
-
'intro.md': { isFile: true },
|
156
|
-
},
|
157
|
-
'api-reference.md': { isFile: true },
|
158
|
-
})
|
159
|
-
|
160
|
-
expect(tree.value.type).toBe('directory')
|
161
|
-
|
162
|
-
const guide = tree.children.find(c => c.value.name === 'guide')
|
163
|
-
expect(guide?.value.type).toBe('directory')
|
164
|
-
expect(guide?.value.order).toBe(10)
|
165
|
-
|
166
|
-
const apiRef = tree.children.find(c => c.value.name === 'api-reference')
|
167
|
-
expect(apiRef?.value.type).toBe('file')
|
168
|
-
})
|
169
|
-
|
170
|
-
test('handles file collisions with same order number - last wins', () => {
|
171
|
-
// This test simulates what would happen if the scanner processes files in order
|
172
|
-
// The mock doesn't actually test the scanner logic but documents expected behavior
|
173
|
-
const tree = mockRouteTree({
|
174
|
-
'10_about.md': { isFile: true, processedFirst: true },
|
175
|
-
'10-about.md': { isFile: true, processedLast: true }, // Same order, same logical name
|
176
|
-
})
|
177
|
-
|
178
|
-
// In the real scanner, only one 'about' node would exist
|
179
|
-
// The test structure above would result in duplicate nodes in our mock
|
180
|
-
// Document the expected behavior: last processed file should win
|
181
|
-
const aboutNodes = tree.children.filter(c => c.value.name === 'about')
|
182
|
-
|
183
|
-
// Note: This mock creates duplicates; real scanner would replace
|
184
|
-
expect(aboutNodes.length).toBeGreaterThan(0)
|
185
|
-
|
186
|
-
// Document that when orders are equal, last file processed wins
|
187
|
-
// This aligns with the linter message about "file processed later is being kept"
|
188
|
-
})
|
189
|
-
})
|
@@ -1,205 +0,0 @@
|
|
1
|
-
import { TinyGlobby } from '#dep/tiny-globby/index'
|
2
|
-
import { Tree, type TreeNode } from '#lib/tree/index'
|
3
|
-
import { Path, Str } from '@wollybeard/kit'
|
4
|
-
import type { Diagnostic } from './linter.ts'
|
5
|
-
import type { Route, RouteFile } from './route.ts'
|
6
|
-
|
7
|
-
//
|
8
|
-
// Types
|
9
|
-
//
|
10
|
-
|
11
|
-
export type RouteTreeNodeType = 'directory' | 'file'
|
12
|
-
|
13
|
-
export interface RouteTreeNodeValue {
|
14
|
-
name: string
|
15
|
-
order?: number
|
16
|
-
type: RouteTreeNodeType
|
17
|
-
route?: Route // Only present for file nodes
|
18
|
-
}
|
19
|
-
|
20
|
-
export type RouteTreeNode = TreeNode<RouteTreeNodeValue>
|
21
|
-
|
22
|
-
export interface ScanTreeResult {
|
23
|
-
routeTree: RouteTreeNode
|
24
|
-
diagnostics: Diagnostic[]
|
25
|
-
}
|
26
|
-
|
27
|
-
//
|
28
|
-
// Constants
|
29
|
-
//
|
30
|
-
|
31
|
-
const conventions = {
|
32
|
-
index: {
|
33
|
-
name: `index`,
|
34
|
-
},
|
35
|
-
numberedPrefix: {
|
36
|
-
pattern: Str.pattern<{ groups: ['order', 'name'] }>(/^(?<order>\d+)[_-](?<name>.+)$/),
|
37
|
-
},
|
38
|
-
}
|
39
|
-
|
40
|
-
//
|
41
|
-
// Helpers
|
42
|
-
//
|
43
|
-
|
44
|
-
const parseSegment = (segment: string): { name: string; order?: number } => {
|
45
|
-
const match = Str.match(segment, conventions.numberedPrefix.pattern)
|
46
|
-
if (match) {
|
47
|
-
return {
|
48
|
-
name: match.groups.name,
|
49
|
-
order: parseInt(match.groups.order, 10),
|
50
|
-
}
|
51
|
-
}
|
52
|
-
return { name: segment }
|
53
|
-
}
|
54
|
-
|
55
|
-
const buildRouteTreeFromPaths = async (paths: string[], rootDir: string): Promise<RouteTreeNode> => {
|
56
|
-
// Root node (represents the pages directory itself)
|
57
|
-
const root = Tree.node<RouteTreeNodeValue>({
|
58
|
-
name: 'root',
|
59
|
-
type: 'directory',
|
60
|
-
})
|
61
|
-
|
62
|
-
// Process each file path
|
63
|
-
for (const filePath of paths) {
|
64
|
-
const relativePath = Path.relative(rootDir, filePath)
|
65
|
-
|
66
|
-
// Split the path into segments
|
67
|
-
const segments = relativePath.split(Path.sep).filter(s => s.length > 0)
|
68
|
-
if (segments.length === 0) continue // Skip root directory
|
69
|
-
|
70
|
-
// Navigate/create path in tree
|
71
|
-
let currentNode = root
|
72
|
-
|
73
|
-
for (let i = 0; i < segments.length; i++) {
|
74
|
-
const segment = segments[i]!
|
75
|
-
const isLast = i === segments.length - 1
|
76
|
-
|
77
|
-
// Parse segment for ordering
|
78
|
-
let segmentName = segment
|
79
|
-
// Strip extension for files
|
80
|
-
if (isLast && (segment.endsWith('.md') || segment.endsWith('.mdx'))) {
|
81
|
-
segmentName = segment.replace(/\.(md|mdx)$/, '')
|
82
|
-
}
|
83
|
-
const parsed = parseSegment(segmentName)
|
84
|
-
|
85
|
-
// Find existing child
|
86
|
-
const existingChildIndex = currentNode.children.findIndex(child => child.value.name === parsed.name)
|
87
|
-
let childNode = existingChildIndex >= 0 ? currentNode.children[existingChildIndex] : undefined
|
88
|
-
|
89
|
-
if (!childNode) {
|
90
|
-
// Create new node
|
91
|
-
if (isLast) {
|
92
|
-
// This is a file
|
93
|
-
const route = filePathToRoute(filePath, rootDir)
|
94
|
-
childNode = Tree.node<RouteTreeNodeValue>({
|
95
|
-
name: parsed.name,
|
96
|
-
order: parsed.order,
|
97
|
-
type: 'file',
|
98
|
-
route,
|
99
|
-
})
|
100
|
-
} else {
|
101
|
-
// This is a directory (implicit from file path)
|
102
|
-
childNode = Tree.node<RouteTreeNodeValue>({
|
103
|
-
name: parsed.name,
|
104
|
-
order: parsed.order,
|
105
|
-
type: 'directory',
|
106
|
-
})
|
107
|
-
}
|
108
|
-
currentNode.children.push(childNode)
|
109
|
-
} else if (isLast && childNode.value.type === 'file') {
|
110
|
-
// Handle collision for files with same name
|
111
|
-
// If new file has higher or equal order, replace the existing one (last wins for ties)
|
112
|
-
if (
|
113
|
-
parsed.order !== undefined
|
114
|
-
&& (childNode.value.order === undefined || parsed.order >= childNode.value.order)
|
115
|
-
) {
|
116
|
-
const route = filePathToRoute(filePath, rootDir)
|
117
|
-
const newNode = Tree.node<RouteTreeNodeValue>({
|
118
|
-
name: parsed.name,
|
119
|
-
order: parsed.order,
|
120
|
-
type: 'file',
|
121
|
-
route,
|
122
|
-
})
|
123
|
-
currentNode.children[existingChildIndex] = newNode
|
124
|
-
childNode = newNode
|
125
|
-
}
|
126
|
-
// Otherwise keep the existing node (when existing has higher order)
|
127
|
-
}
|
128
|
-
|
129
|
-
currentNode = childNode
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
// Sort the tree
|
134
|
-
return sortRouteTree(root)
|
135
|
-
}
|
136
|
-
|
137
|
-
const sortRouteTree = (tree: RouteTreeNode): RouteTreeNode => {
|
138
|
-
return Tree.sort(tree, (a, b) => {
|
139
|
-
// If both have orders, sort by order
|
140
|
-
if (a.order !== undefined && b.order !== undefined) {
|
141
|
-
return a.order - b.order
|
142
|
-
}
|
143
|
-
// If only one has order, it comes first
|
144
|
-
if (a.order !== undefined) return -1
|
145
|
-
if (b.order !== undefined) return 1
|
146
|
-
// Otherwise sort alphabetically
|
147
|
-
return a.name.localeCompare(b.name)
|
148
|
-
})
|
149
|
-
}
|
150
|
-
|
151
|
-
//
|
152
|
-
// Main scan function
|
153
|
-
//
|
154
|
-
|
155
|
-
export const scanTree = async (parameters: {
|
156
|
-
dir: string
|
157
|
-
glob?: string
|
158
|
-
}): Promise<ScanTreeResult> => {
|
159
|
-
const { dir, glob = `**/*` } = parameters
|
160
|
-
|
161
|
-
// Get all files
|
162
|
-
const filePaths = await TinyGlobby.glob(glob, {
|
163
|
-
absolute: true,
|
164
|
-
cwd: dir,
|
165
|
-
onlyFiles: true,
|
166
|
-
})
|
167
|
-
|
168
|
-
// Build tree structure (directories will be created implicitly)
|
169
|
-
const routeTree = await buildRouteTreeFromPaths(filePaths, dir)
|
170
|
-
|
171
|
-
// TODO: Implement tree-based linting
|
172
|
-
const diagnostics: Diagnostic[] = []
|
173
|
-
|
174
|
-
return {
|
175
|
-
routeTree,
|
176
|
-
diagnostics,
|
177
|
-
}
|
178
|
-
}
|
179
|
-
|
180
|
-
// Reuse existing route creation logic
|
181
|
-
const filePathToRoute = (filePathExpression: string, rootDir: string): Route => {
|
182
|
-
const file: RouteFile = {
|
183
|
-
path: {
|
184
|
-
absolute: Path.parse(filePathExpression),
|
185
|
-
relative: Path.parse(Path.relative(rootDir, filePathExpression)),
|
186
|
-
},
|
187
|
-
}
|
188
|
-
|
189
|
-
const dirPath = Str.split(Str.removeSurrounding(file.path.relative.dir, Path.sep), Path.sep)
|
190
|
-
|
191
|
-
// Parse numbered prefix from filename
|
192
|
-
const prefixMatch = file.path.relative.name.match(conventions.numberedPrefix.pattern)
|
193
|
-
const order = prefixMatch?.groups?.[`order`] ? parseInt(prefixMatch.groups[`order`], 10) : undefined
|
194
|
-
const nameWithoutPrefix = prefixMatch?.groups?.[`name`] ?? file.path.relative.name
|
195
|
-
|
196
|
-
const logical = {
|
197
|
-
path: nameWithoutPrefix === conventions.index.name ? dirPath : dirPath.concat(nameWithoutPrefix),
|
198
|
-
order,
|
199
|
-
}
|
200
|
-
|
201
|
-
return {
|
202
|
-
logical,
|
203
|
-
file,
|
204
|
-
}
|
205
|
-
}
|
@@ -1,123 +0,0 @@
|
|
1
|
-
import { Tree } from '#lib/tree/index'
|
2
|
-
import { describe, expect, test } from 'vitest'
|
3
|
-
import type { RouteTreeNode, RouteTreeNodeValue } from '../scan-tree.ts'
|
4
|
-
import { buildFromTree } from './sidebar-tree.ts'
|
5
|
-
|
6
|
-
// Helper to create mock routes
|
7
|
-
const mockRoute = (path: string[]) => ({
|
8
|
-
logical: { path },
|
9
|
-
file: {
|
10
|
-
path: {
|
11
|
-
absolute: { root: '/', dir: '/', base: 'file.md', ext: '.md', name: 'file' },
|
12
|
-
relative: { root: '', dir: '', base: 'file.md', ext: '.md', name: 'file' },
|
13
|
-
},
|
14
|
-
},
|
15
|
-
})
|
16
|
-
|
17
|
-
// Helper to create file node
|
18
|
-
const fileNode = (name: string, route: any): RouteTreeNode =>
|
19
|
-
Tree.node<RouteTreeNodeValue>({ name, type: 'file', route })
|
20
|
-
|
21
|
-
// Helper to create directory node
|
22
|
-
const dirNode = (name: string, children: RouteTreeNode[] = []): RouteTreeNode =>
|
23
|
-
Tree.node<RouteTreeNodeValue>({ name, type: 'directory' }, children)
|
24
|
-
|
25
|
-
describe('sidebar-tree', () => {
|
26
|
-
test('builds sidebar from simple tree', () => {
|
27
|
-
const tree = dirNode('root', [
|
28
|
-
fileNode('getting-started', mockRoute(['getting-started'])),
|
29
|
-
dirNode('guide', [
|
30
|
-
fileNode('introduction', mockRoute(['guide', 'introduction'])),
|
31
|
-
fileNode('basics', mockRoute(['guide', 'basics'])),
|
32
|
-
]),
|
33
|
-
])
|
34
|
-
|
35
|
-
const sidebar = buildFromTree(tree, [])
|
36
|
-
|
37
|
-
expect(sidebar.items).toHaveLength(2)
|
38
|
-
expect(sidebar.items[0]).toMatchObject({
|
39
|
-
type: 'ItemLink',
|
40
|
-
pathExp: 'getting-started',
|
41
|
-
title: 'Getting Started',
|
42
|
-
})
|
43
|
-
const section = sidebar.items[1]
|
44
|
-
expect(section).toBeDefined()
|
45
|
-
expect(section!.type).toBe('ItemSection')
|
46
|
-
if (section!.type === 'ItemSection') {
|
47
|
-
expect(section).toMatchObject({
|
48
|
-
type: 'ItemSection',
|
49
|
-
title: 'Guide',
|
50
|
-
pathExp: 'guide',
|
51
|
-
isLinkToo: false,
|
52
|
-
})
|
53
|
-
expect(section!.links).toHaveLength(2)
|
54
|
-
}
|
55
|
-
})
|
56
|
-
|
57
|
-
test('handles index files correctly', () => {
|
58
|
-
const tree = dirNode('root', [
|
59
|
-
dirNode('guide', [
|
60
|
-
fileNode('index', mockRoute(['guide'])),
|
61
|
-
fileNode('introduction', mockRoute(['guide', 'introduction'])),
|
62
|
-
]),
|
63
|
-
])
|
64
|
-
|
65
|
-
const sidebar = buildFromTree(tree, [])
|
66
|
-
|
67
|
-
expect(sidebar.items).toHaveLength(1)
|
68
|
-
const section = sidebar.items[0]
|
69
|
-
expect(section).toBeDefined()
|
70
|
-
expect(section!.type).toBe('ItemSection')
|
71
|
-
if (section!.type === 'ItemSection') {
|
72
|
-
expect(section).toMatchObject({
|
73
|
-
type: 'ItemSection',
|
74
|
-
title: 'Guide',
|
75
|
-
pathExp: 'guide',
|
76
|
-
isLinkToo: true, // Should be true because of index file
|
77
|
-
})
|
78
|
-
expect(section!.links).toHaveLength(1) // Only introduction, not index
|
79
|
-
}
|
80
|
-
})
|
81
|
-
|
82
|
-
test('respects node ordering from tree', () => {
|
83
|
-
const tree = dirNode('root', [
|
84
|
-
Tree.node<RouteTreeNodeValue>({ name: 'quickstart', order: 5, type: 'file', route: mockRoute(['quickstart']) }),
|
85
|
-
Tree.node<RouteTreeNodeValue>({ name: 'guide', order: 10, type: 'file', route: mockRoute(['guide']) }),
|
86
|
-
fileNode('api', mockRoute(['api'])),
|
87
|
-
fileNode('troubleshooting', mockRoute(['troubleshooting'])),
|
88
|
-
])
|
89
|
-
|
90
|
-
const sidebar = buildFromTree(tree, [])
|
91
|
-
|
92
|
-
// Tree should already be sorted, so sidebar should maintain that order
|
93
|
-
const titles = sidebar.items.map(item => item.title)
|
94
|
-
expect(titles).toEqual(['Quickstart', 'Guide', 'Api', 'Troubleshooting'])
|
95
|
-
})
|
96
|
-
|
97
|
-
test('handles nested directories', () => {
|
98
|
-
const tree = dirNode('root', [
|
99
|
-
dirNode('guide', [
|
100
|
-
fileNode('intro', mockRoute(['guide', 'intro'])),
|
101
|
-
dirNode('advanced', [
|
102
|
-
fileNode('performance', mockRoute(['guide', 'advanced', 'performance'])),
|
103
|
-
fileNode('optimization', mockRoute(['guide', 'advanced', 'optimization'])),
|
104
|
-
]),
|
105
|
-
]),
|
106
|
-
])
|
107
|
-
|
108
|
-
const sidebar = buildFromTree(tree, [])
|
109
|
-
|
110
|
-
expect(sidebar.items).toHaveLength(1)
|
111
|
-
const guideSection = sidebar.items[0]
|
112
|
-
expect(guideSection).toBeDefined()
|
113
|
-
expect(guideSection!.type).toBe('ItemSection')
|
114
|
-
if (guideSection!.type === 'ItemSection') {
|
115
|
-
expect(guideSection!.links).toHaveLength(3) // intro + 2 from advanced subdirectory
|
116
|
-
|
117
|
-
const navTitles = guideSection!.links.map(nav => nav.title)
|
118
|
-
expect(navTitles).toContain('Intro')
|
119
|
-
expect(navTitles).toContain('Performance')
|
120
|
-
expect(navTitles).toContain('Optimization')
|
121
|
-
}
|
122
|
-
})
|
123
|
-
})
|