@jay-framework/stack-route-scanner 0.15.6 → 0.16.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 +11 -1
- package/dist/index.mjs +25 -2
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -30,8 +30,18 @@ interface ScanFilesOptions {
|
|
|
30
30
|
* Static routes come before dynamic routes at the same position.
|
|
31
31
|
*/
|
|
32
32
|
declare function sortRoutesByPriority(routes: JayRoutes): JayRoutes;
|
|
33
|
+
/**
|
|
34
|
+
* Parse a route path string into segments (DL#130).
|
|
35
|
+
* Supports [param], [[optional]], [...catchAll] patterns.
|
|
36
|
+
*/
|
|
37
|
+
declare function parseRouteSegments(routePath: string): JayRouteSegment[];
|
|
38
|
+
/**
|
|
39
|
+
* Create a JayRoute from explicit path and file locations (DL#130).
|
|
40
|
+
* Used for plugin-provided routes where the path is declared, not inferred from the filesystem.
|
|
41
|
+
*/
|
|
42
|
+
declare function createRoute(routePath: string, jayHtmlPath: string, compPath: string): JayRoute;
|
|
33
43
|
declare function scanRoutes(baseDir: string, options: ScanFilesOptions): Promise<JayRoutes>;
|
|
34
44
|
|
|
35
45
|
declare function routeToExpressRoute(route: JayRoute): string;
|
|
36
46
|
|
|
37
|
-
export { type JayRoute, type JayRouteParam, JayRouteParamType, type JayRouteSegment, type JayRoutes, type ScanFilesOptions, routeToExpressRoute, scanRoutes, sortRoutesByPriority };
|
|
47
|
+
export { type JayRoute, type JayRouteParam, JayRouteParamType, type JayRouteSegment, type JayRoutes, type ScanFilesOptions, createRoute, parseRouteSegments, routeToExpressRoute, scanRoutes, sortRoutesByPriority };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { promises } from "fs";
|
|
1
|
+
import { promises, existsSync } from "fs";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { parse } from "node-html-parser";
|
|
4
4
|
import YAML from "yaml";
|
|
@@ -25,7 +25,8 @@ function convertToRoutePath(BASE_DIR, jayHtmlPath, { jayHtmlFilename, compFilena
|
|
|
25
25
|
/* single */
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
|
-
const
|
|
28
|
+
const candidateCompPath = jayHtmlPath.replace(jayHtmlFilename, compFilename);
|
|
29
|
+
const compPath = existsSync(candidateCompPath) ? candidateCompPath : "";
|
|
29
30
|
return { segments, jayHtmlPath, compPath, rawRoute };
|
|
30
31
|
}
|
|
31
32
|
async function scanDirectory(BASE_DIR, directory, options) {
|
|
@@ -129,6 +130,26 @@ async function parseJayParams(jayHtmlPath) {
|
|
|
129
130
|
};
|
|
130
131
|
}
|
|
131
132
|
}
|
|
133
|
+
function parseRouteSegments(routePath) {
|
|
134
|
+
return routePath.split("/").filter((s) => s.length > 0).map((segment) => {
|
|
135
|
+
const match = segment.match(PARSE_PARAM);
|
|
136
|
+
if (!match)
|
|
137
|
+
return segment;
|
|
138
|
+
return {
|
|
139
|
+
name: match[3],
|
|
140
|
+
type: match[1] ? 2 : match[2] ? 1 : 0
|
|
141
|
+
/* single */
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function createRoute(routePath, jayHtmlPath, compPath) {
|
|
146
|
+
return {
|
|
147
|
+
segments: parseRouteSegments(routePath),
|
|
148
|
+
rawRoute: routePath,
|
|
149
|
+
jayHtmlPath,
|
|
150
|
+
compPath
|
|
151
|
+
};
|
|
152
|
+
}
|
|
132
153
|
async function scanRoutes(baseDir, options) {
|
|
133
154
|
const BASE_DIR = path.resolve(baseDir);
|
|
134
155
|
const routes = await scanDirectory(BASE_DIR, BASE_DIR, options);
|
|
@@ -159,6 +180,8 @@ function routeToExpressRoute(route) {
|
|
|
159
180
|
}
|
|
160
181
|
export {
|
|
161
182
|
JayRouteParamType,
|
|
183
|
+
createRoute,
|
|
184
|
+
parseRouteSegments,
|
|
162
185
|
routeToExpressRoute,
|
|
163
186
|
scanRoutes,
|
|
164
187
|
sortRoutesByPriority
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/stack-route-scanner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.16.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.16.1",
|
|
29
29
|
"@types/node": "^20.11.5",
|
|
30
30
|
"nodemon": "^3.0.3",
|
|
31
31
|
"replace-in-file": "^7.1.0",
|