Skip to content

Commit 8b7281b

Browse files
authored
fix: Support namespaced models for windows (#38)
1 parent ee03e07 commit 8b7281b

File tree

5 files changed

+28
-38
lines changed

5 files changed

+28
-38
lines changed

examples/laravel10-app/.laravel-typegen-tmp/User.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@
126126
}
127127
],
128128
"relations": [
129-
{
130-
"name": "posts",
131-
"type": "HasMany",
132-
"related": "App\\Models\\Post"
133-
},
129+
{ "name": "posts", "type": "HasMany", "related": "App\\Models\\Post" },
134130
{
135131
"name": "userContacts",
136132
"type": "HasMany",

examples/laravel10-app/.laravel-typegen-tmp/UserContact.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@
6666
}
6767
],
6868
"relations": [
69-
{
70-
"name": "user",
71-
"type": "BelongsTo",
72-
"related": "App\\Models\\User"
73-
}
69+
{ "name": "user", "type": "BelongsTo", "related": "App\\Models\\User" }
7470
],
7571
"observers": []
7672
}
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { Config, Router } from "ziggy-js";
2-
import { RouteParams } from "./param";
1+
import type { Config, Router } from "ziggy-js";
2+
import type { RouteParams } from "./param";
33
type CustomRouter<T> = {
4-
get params(): RouteParams[T];
5-
current(): Extract<keyof RouteParams, T> | undefined;
6-
current(
7-
name: Extract<keyof RouteParams, T>,
8-
params?: RouteParams[T]
9-
): boolean;
4+
get params(): RouteParams[T];
5+
current(): Extract<keyof RouteParams, T> | undefined;
6+
current(
7+
name: Extract<keyof RouteParams, T>,
8+
params?: RouteParams[T],
9+
): boolean;
1010
} & Router;
1111
declare global {
12-
declare function route<T extends keyof RouteParams>(): CustomRouter<T>;
13-
declare function route<T extends keyof RouteParams>(
14-
name: T,
15-
params?: RouteParams[T],
16-
absolute?: boolean,
17-
config?: Config
18-
): string;
12+
declare function route<T extends keyof RouteParams>(): CustomRouter<T>;
13+
declare function route<T extends keyof RouteParams>(
14+
name: T,
15+
params?: RouteParams[T],
16+
absolute?: boolean,
17+
config?: Config,
18+
): string;
1919
}
2020
declare module "vue" {
21-
interface ComponentCustomProperties {
22-
route: (<T extends keyof RouteParams>() => CustomRouter<T>) &
23-
(<T extends keyof RouteParams>(
24-
name: T,
25-
params?: RouteParams[T],
26-
absolute?: boolean,
27-
config?: Config
28-
) => string);
29-
}
21+
interface ComponentCustomProperties {
22+
route: (<T extends keyof RouteParams>() => CustomRouter<T>) &
23+
(<T extends keyof RouteParams>(
24+
name: T,
25+
params?: RouteParams[T],
26+
absolute?: boolean,
27+
config?: Config,
28+
) => string);
29+
}
3030
}

src/generate.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ export async function generate(options: CLIOptions) {
5656

5757
createModelDirectory(modelName);
5858

59-
const namespacedModel = `${getNamespaceForCommand(
60-
modelPath,
61-
)}\\\\${modelName}`;
59+
const namespacedModel = `${getNamespaceForCommand(modelPath)}/${modelName}`;
6260
const outputPath = path.join(tmpDir, `${modelName}.json`);
6361

6462
const modelShowCommand = `php artisan model:show ${namespacedModel} --json`;

src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const convertCamelToSnake = (camelCaseString: string): string => {
2020
};
2121

2222
export const formatNamespaceForCommand = (namespace: string): string => {
23-
return namespace.replaceAll(/\\/g, "\\\\");
23+
return namespace.replaceAll(/\\/g, "/");
2424
};
2525

2626
export const getPhpAst = (phpFilePath: string): Program => {

0 commit comments

Comments
 (0)