litestar-vite-plugin 0.5.1 → 0.6.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/index.js +1 -0
- package/inertia-helpers/index.d.ts +6 -0
- package/inertia-helpers/index.js +40 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -108,6 +108,7 @@ function resolveLitestarPlugin(pluginConfig) {
|
|
|
108
108
|
server.config,
|
|
109
109
|
userConfig
|
|
110
110
|
);
|
|
111
|
+
fs.mkdirSync(path.dirname(pluginConfig.hotFile), { recursive: true });
|
|
111
112
|
fs.writeFileSync(pluginConfig.hotFile, viteDevServerUrl);
|
|
112
113
|
setTimeout(() => {
|
|
113
114
|
server.config.logger.info(
|
|
@@ -1 +1,7 @@
|
|
|
1
1
|
export declare function resolvePageComponent<T>(path: string | string[], pages: Record<string, Promise<T> | (() => Promise<T>)>): Promise<T>;
|
|
2
|
+
declare global {
|
|
3
|
+
var routes: {
|
|
4
|
+
[key: string]: string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export declare function route(routeName: string, ...args: any[]): string;
|
package/inertia-helpers/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
1
2
|
export async function resolvePageComponent(path, pages) {
|
|
2
3
|
for (const p of (Array.isArray(path) ? path : [path])) {
|
|
3
4
|
const page = pages[p];
|
|
@@ -8,3 +9,42 @@ export async function resolvePageComponent(path, pages) {
|
|
|
8
9
|
}
|
|
9
10
|
throw new Error(`Page not found: ${path}`);
|
|
10
11
|
}
|
|
12
|
+
globalThis.routes = globalThis.routes || {};
|
|
13
|
+
export function route(routeName, ...args) {
|
|
14
|
+
let url = globalThis.routes[routeName];
|
|
15
|
+
if (!url) {
|
|
16
|
+
throw new Error("URL " + routeName + " was not found.");
|
|
17
|
+
}
|
|
18
|
+
const argTokens = url.match(/<(\w+:?)?\w+>/g);
|
|
19
|
+
if (!argTokens && args.length > 0) {
|
|
20
|
+
throw new Error("Invalid URL lookup: URL " + routeName + " does not expect any arguments.");
|
|
21
|
+
}
|
|
22
|
+
if (typeof args[0] === "object" && !Array.isArray(args[0])) {
|
|
23
|
+
argTokens?.forEach((token) => {
|
|
24
|
+
let argName = token.slice(1, -1);
|
|
25
|
+
if (argName.includes(":")) {
|
|
26
|
+
argName = argName.split(":")[1];
|
|
27
|
+
}
|
|
28
|
+
const argValue = args[0][argName];
|
|
29
|
+
if (argValue === undefined) {
|
|
30
|
+
throw new Error("Invalid URL lookup: Argument " + argName + " was not provided.");
|
|
31
|
+
}
|
|
32
|
+
url = url.replace(token, argValue.toString());
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
const argsArray = Array.isArray(args[0])
|
|
37
|
+
? args[0]
|
|
38
|
+
: Array.prototype.slice.call(args);
|
|
39
|
+
if (argTokens && argTokens.length !== argsArray.length) {
|
|
40
|
+
throw new Error("Invalid URL lookup: Wrong number of arguments; expected " +
|
|
41
|
+
argTokens.length.toString() +
|
|
42
|
+
" arguments.");
|
|
43
|
+
}
|
|
44
|
+
argTokens?.forEach((token, i) => {
|
|
45
|
+
const argValue = argsArray[i];
|
|
46
|
+
url = url.replace(token, argValue.toString());
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return url;
|
|
50
|
+
}
|