rspress-plugin-file-tree 0.3.0 → 0.4.0
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/dist/parser.d.ts +1 -0
- package/dist/parser.js +7 -4
- package/package.json +1 -1
package/dist/parser.d.ts
CHANGED
package/dist/parser.js
CHANGED
|
@@ -5,7 +5,7 @@ function countLeadingSpaces(line) {
|
|
|
5
5
|
return matches[0].length;
|
|
6
6
|
}
|
|
7
7
|
export function parseInput(input) {
|
|
8
|
-
var _a;
|
|
8
|
+
var _a, _b;
|
|
9
9
|
const lines = input.split('\n').filter((line) => line.trim());
|
|
10
10
|
const tree = [];
|
|
11
11
|
const stack = [];
|
|
@@ -14,11 +14,14 @@ export function parseInput(input) {
|
|
|
14
14
|
if (line === '.')
|
|
15
15
|
continue;
|
|
16
16
|
const level = countLeadingSpaces(line);
|
|
17
|
-
const
|
|
17
|
+
const normalizedLine = line.split('─').slice(-1)[0].trimStart();
|
|
18
|
+
const [_, name, extra = ''] = (_a = normalizedLine.match(/^(.*?)(?:\s*\/\/\s*(.*))?$/)) !== null && _a !== void 0 ? _a : [];
|
|
18
19
|
const nextLine = lines[i + 1] || '';
|
|
19
20
|
const nextLineLevel = countLeadingSpaces(nextLine);
|
|
20
21
|
const type = nextLineLevel > level ? 'directory' : 'file';
|
|
21
|
-
const item = type === 'directory'
|
|
22
|
+
const item = type === 'directory'
|
|
23
|
+
? { type, name, files: [], extra }
|
|
24
|
+
: { type, name, extra };
|
|
22
25
|
while (stack.length > 0 && stack[stack.length - 1].level >= level) {
|
|
23
26
|
stack.pop();
|
|
24
27
|
}
|
|
@@ -27,7 +30,7 @@ export function parseInput(input) {
|
|
|
27
30
|
}
|
|
28
31
|
else {
|
|
29
32
|
const parentItem = stack[stack.length - 1].item;
|
|
30
|
-
(
|
|
33
|
+
(_b = parentItem.files) === null || _b === void 0 ? void 0 : _b.push(item);
|
|
31
34
|
}
|
|
32
35
|
if (item.type === 'directory') {
|
|
33
36
|
stack.push({ level, item });
|