@triflux/core 10.0.0-alpha.2 → 10.0.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/hooks/keyword-rules.json
CHANGED
package/hub/adaptive-inject.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, readFileSync } from "node:fs";
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
2
2
|
import { basename, extname, join, relative } from "node:path";
|
|
3
3
|
|
|
4
4
|
const IF_TAG_RE = /{{\s*(#if\s+([A-Za-z0-9_.-]+)|\/if)\s*}}/g;
|
|
@@ -39,6 +39,44 @@ function parseScalar(raw) {
|
|
|
39
39
|
return bool ?? value;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function parseMultilineValue(lines, startIndex, marker) {
|
|
43
|
+
const fold = marker.startsWith(">");
|
|
44
|
+
const chunks = [];
|
|
45
|
+
let index = startIndex;
|
|
46
|
+
|
|
47
|
+
while (index + 1 < lines.length && /^\s+/.test(lines[index + 1])) {
|
|
48
|
+
index += 1;
|
|
49
|
+
chunks.push(lines[index].replace(/^\s+/, ""));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
index,
|
|
54
|
+
value: fold ? chunks.join(" ").trim() : chunks.join("\n").trim(),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function parseListValue(lines, startIndex) {
|
|
59
|
+
const items = [];
|
|
60
|
+
let index = startIndex;
|
|
61
|
+
|
|
62
|
+
while (index + 1 < lines.length) {
|
|
63
|
+
const nextLine = lines[index + 1];
|
|
64
|
+
const match = nextLine.match(/^\s*-\s+(.*)$/);
|
|
65
|
+
if (match) {
|
|
66
|
+
index += 1;
|
|
67
|
+
items.push(parseScalar(match[1]));
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (/^\s*$/.test(nextLine)) {
|
|
71
|
+
index += 1;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return { index, value: items };
|
|
78
|
+
}
|
|
79
|
+
|
|
42
80
|
function parseFrontmatterBlock(block) {
|
|
43
81
|
const lines = block.split(/\r?\n/);
|
|
44
82
|
const data = {};
|
|
@@ -53,16 +91,21 @@ function parseFrontmatterBlock(block) {
|
|
|
53
91
|
const value = rawValue.trim();
|
|
54
92
|
|
|
55
93
|
if (value === ">" || value === "|" || value === ">-" || value === "|-") {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
i += 1;
|
|
60
|
-
chunks.push(lines[i].replace(/^\s+/, ""));
|
|
61
|
-
}
|
|
62
|
-
data[key] = fold ? chunks.join(" ").trim() : chunks.join("\n").trim();
|
|
94
|
+
const parsed = parseMultilineValue(lines, i, value);
|
|
95
|
+
data[key] = parsed.value;
|
|
96
|
+
i = parsed.index;
|
|
63
97
|
continue;
|
|
64
98
|
}
|
|
65
99
|
|
|
100
|
+
if (!value) {
|
|
101
|
+
const parsed = parseListValue(lines, i);
|
|
102
|
+
if (parsed.index !== i) {
|
|
103
|
+
data[key] = parsed.value;
|
|
104
|
+
i = parsed.index;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
66
109
|
data[key] = parseScalar(value);
|
|
67
110
|
}
|
|
68
111
|
|
|
@@ -140,7 +183,11 @@ function renderWithContext(source, context, partials, includeStack = []) {
|
|
|
140
183
|
}
|
|
141
184
|
|
|
142
185
|
function readAllTemplateFiles(rootDir, currentDir = rootDir) {
|
|
143
|
-
|
|
186
|
+
if (!rootDir || !existsSync(rootDir)) return [];
|
|
187
|
+
|
|
188
|
+
const entries = readdirSync(currentDir, { withFileTypes: true }).sort((left, right) =>
|
|
189
|
+
left.name.localeCompare(right.name),
|
|
190
|
+
);
|
|
144
191
|
const files = [];
|
|
145
192
|
|
|
146
193
|
for (const entry of entries) {
|