@jay-framework/stack-route-scanner 0.22.2 → 0.23.1
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/index.d.mts +5 -1
- package/dist/index.mjs +14 -24
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -23,6 +23,8 @@ type JayRoute = {
|
|
|
23
23
|
* e.g., /products/ceramic-flower-vase declares { slug: 'ceramic-flower-vase' }.
|
|
24
24
|
*/
|
|
25
25
|
inferredParams?: Record<string, string>;
|
|
26
|
+
/** When true, dev-server tooling route — consumers may filter from page navigation. */
|
|
27
|
+
devOnly?: boolean;
|
|
26
28
|
};
|
|
27
29
|
type JayRoutes = JayRoute[];
|
|
28
30
|
interface ScanFilesOptions {
|
|
@@ -43,7 +45,9 @@ declare function parseRouteSegments(routePath: string): JayRouteSegment[];
|
|
|
43
45
|
* Create a JayRoute from explicit path and file locations (DL#130).
|
|
44
46
|
* Used for plugin-provided routes where the path is declared, not inferred from the filesystem.
|
|
45
47
|
*/
|
|
46
|
-
declare function createRoute(routePath: string, jayHtmlPath: string, compPath: string, componentExport?: string
|
|
48
|
+
declare function createRoute(routePath: string, jayHtmlPath: string, compPath: string, componentExport?: string, options?: {
|
|
49
|
+
devOnly?: boolean;
|
|
50
|
+
}): JayRoute;
|
|
47
51
|
declare function scanRoutes(baseDir: string, options: ScanFilesOptions): Promise<JayRoutes>;
|
|
48
52
|
|
|
49
53
|
declare function routeToExpressRoute(route: JayRoute): string;
|
package/dist/index.mjs
CHANGED
|
@@ -14,8 +14,7 @@ function convertToRoutePath(BASE_DIR, jayHtmlPath, { jayHtmlFilename, compFilena
|
|
|
14
14
|
let rawRoute = jayHtmlPath.replace(BASE_DIR, "").replace(`/${jayHtmlFilename}`, "").replace("\\", "/");
|
|
15
15
|
const segments = rawRoute.split("/").filter((segment) => segment.length > 0).map((segment) => {
|
|
16
16
|
const match = segment.match(PARSE_PARAM);
|
|
17
|
-
if (!match)
|
|
18
|
-
return segment;
|
|
17
|
+
if (!match) return segment;
|
|
19
18
|
const isOptional = !!match[1];
|
|
20
19
|
const isCatchAll = !!match[2];
|
|
21
20
|
const name = match[3];
|
|
@@ -36,8 +35,7 @@ async function scanDirectory(BASE_DIR, directory, options) {
|
|
|
36
35
|
for (const item of items) {
|
|
37
36
|
const fullPath = path.join(directory, item.name);
|
|
38
37
|
if (item.isDirectory()) {
|
|
39
|
-
if (IGNORED_DIRS.has(item.name))
|
|
40
|
-
continue;
|
|
38
|
+
if (IGNORED_DIRS.has(item.name)) continue;
|
|
41
39
|
routes = [...routes, ...await scanDirectory(BASE_DIR, fullPath, options)];
|
|
42
40
|
} else if (item.name === options.jayHtmlFilename) {
|
|
43
41
|
const route = convertToRoutePath(BASE_DIR, fullPath, options);
|
|
@@ -74,8 +72,7 @@ async function scanDirectory(BASE_DIR, directory, options) {
|
|
|
74
72
|
return routes;
|
|
75
73
|
}
|
|
76
74
|
function getSegmentPriority(segment) {
|
|
77
|
-
if (typeof segment === "string")
|
|
78
|
-
return 0;
|
|
75
|
+
if (typeof segment === "string") return 0;
|
|
79
76
|
switch (segment.type) {
|
|
80
77
|
case 0:
|
|
81
78
|
return 1;
|
|
@@ -90,18 +87,14 @@ function compareRoutes(a, b) {
|
|
|
90
87
|
for (let i = 0; i < maxLen; i++) {
|
|
91
88
|
const segA = a.segments[i];
|
|
92
89
|
const segB = b.segments[i];
|
|
93
|
-
if (segA === void 0)
|
|
94
|
-
|
|
95
|
-
if (segB === void 0)
|
|
96
|
-
return -1;
|
|
90
|
+
if (segA === void 0) return 1;
|
|
91
|
+
if (segB === void 0) return -1;
|
|
97
92
|
const priorityA = getSegmentPriority(segA);
|
|
98
93
|
const priorityB = getSegmentPriority(segB);
|
|
99
|
-
if (priorityA !== priorityB)
|
|
100
|
-
return priorityA - priorityB;
|
|
94
|
+
if (priorityA !== priorityB) return priorityA - priorityB;
|
|
101
95
|
if (typeof segA === "string" && typeof segB === "string") {
|
|
102
96
|
const cmp = segA.localeCompare(segB);
|
|
103
|
-
if (cmp !== 0)
|
|
104
|
-
return cmp;
|
|
97
|
+
if (cmp !== 0) return cmp;
|
|
105
98
|
}
|
|
106
99
|
}
|
|
107
100
|
return 0;
|
|
@@ -111,8 +104,7 @@ function sortRoutesByPriority(routes) {
|
|
|
111
104
|
}
|
|
112
105
|
function dedentYaml(text) {
|
|
113
106
|
const lines = text.split("\n").filter((l) => l.trim().length > 0);
|
|
114
|
-
if (lines.length === 0)
|
|
115
|
-
return "";
|
|
107
|
+
if (lines.length === 0) return "";
|
|
116
108
|
const minIndent = Math.min(...lines.map((l) => l.match(/^\s*/)?.[0].length ?? 0));
|
|
117
109
|
return lines.map((l) => l.slice(minIndent)).join("\n");
|
|
118
110
|
}
|
|
@@ -141,13 +133,11 @@ async function parseHeadlessProps(jayHtmlPath) {
|
|
|
141
133
|
let merged;
|
|
142
134
|
for (const script of headlessScripts) {
|
|
143
135
|
const body = dedentYaml(script.textContent ?? "");
|
|
144
|
-
if (!body)
|
|
145
|
-
continue;
|
|
136
|
+
if (!body) continue;
|
|
146
137
|
try {
|
|
147
138
|
const parsed = YAML.parse(body);
|
|
148
139
|
if (parsed && typeof parsed === "object") {
|
|
149
|
-
if (!merged)
|
|
150
|
-
merged = {};
|
|
140
|
+
if (!merged) merged = {};
|
|
151
141
|
for (const [k, v] of Object.entries(parsed)) {
|
|
152
142
|
merged[k] = String(v);
|
|
153
143
|
}
|
|
@@ -163,8 +153,7 @@ async function parseHeadlessProps(jayHtmlPath) {
|
|
|
163
153
|
function parseRouteSegments(routePath) {
|
|
164
154
|
return routePath.split("/").filter((s) => s.length > 0).map((segment) => {
|
|
165
155
|
const match = segment.match(PARSE_PARAM);
|
|
166
|
-
if (!match)
|
|
167
|
-
return segment;
|
|
156
|
+
if (!match) return segment;
|
|
168
157
|
return {
|
|
169
158
|
name: match[3],
|
|
170
159
|
type: match[1] ? 2 : match[2] ? 1 : 0
|
|
@@ -172,13 +161,14 @@ function parseRouteSegments(routePath) {
|
|
|
172
161
|
};
|
|
173
162
|
});
|
|
174
163
|
}
|
|
175
|
-
function createRoute(routePath, jayHtmlPath, compPath, componentExport) {
|
|
164
|
+
function createRoute(routePath, jayHtmlPath, compPath, componentExport, options) {
|
|
176
165
|
return {
|
|
177
166
|
segments: parseRouteSegments(routePath),
|
|
178
167
|
rawRoute: routePath,
|
|
179
168
|
jayHtmlPath,
|
|
180
169
|
compPath,
|
|
181
|
-
...componentExport && { componentExport }
|
|
170
|
+
...componentExport && { componentExport },
|
|
171
|
+
...options?.devOnly && { devOnly: true }
|
|
182
172
|
};
|
|
183
173
|
}
|
|
184
174
|
async function scanRoutes(baseDir, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/stack-route-scanner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.mts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"readme.md"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@jay-framework/logger": "^0.
|
|
12
|
+
"@jay-framework/logger": "^0.23.1",
|
|
13
13
|
"node-html-parser": "^6.1.12",
|
|
14
14
|
"yaml": "^2.3.4"
|
|
15
15
|
},
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test:watch": "vitest"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@jay-framework/dev-environment": "^0.
|
|
28
|
+
"@jay-framework/dev-environment": "^0.23.1",
|
|
29
29
|
"@types/node": "^20.11.5",
|
|
30
30
|
"nodemon": "^3.0.3",
|
|
31
31
|
"replace-in-file": "^7.1.0",
|