Skip to content

Commit

Permalink
fix: Support namespaced models for windows (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe authored Jul 11, 2024
1 parent ee03e07 commit 8b7281b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
6 changes: 1 addition & 5 deletions examples/laravel10-app/.laravel-typegen-tmp/User.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@
}
],
"relations": [
{
"name": "posts",
"type": "HasMany",
"related": "App\\Models\\Post"
},
{ "name": "posts", "type": "HasMany", "related": "App\\Models\\Post" },
{
"name": "userContacts",
"type": "HasMany",
Expand Down
6 changes: 1 addition & 5 deletions examples/laravel10-app/.laravel-typegen-tmp/UserContact.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@
}
],
"relations": [
{
"name": "user",
"type": "BelongsTo",
"related": "App\\Models\\User"
}
{ "name": "user", "type": "BelongsTo", "related": "App\\Models\\User" }
],
"observers": []
}
48 changes: 24 additions & 24 deletions examples/laravel10-app/resources/js/types/route.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { Config, Router } from "ziggy-js";
import { RouteParams } from "./param";
import type { Config, Router } from "ziggy-js";
import type { RouteParams } from "./param";
type CustomRouter<T> = {
get params(): RouteParams[T];
current(): Extract<keyof RouteParams, T> | undefined;
current(
name: Extract<keyof RouteParams, T>,
params?: RouteParams[T]
): boolean;
get params(): RouteParams[T];
current(): Extract<keyof RouteParams, T> | undefined;
current(
name: Extract<keyof RouteParams, T>,
params?: RouteParams[T],
): boolean;
} & Router;
declare global {
declare function route<T extends keyof RouteParams>(): CustomRouter<T>;
declare function route<T extends keyof RouteParams>(
name: T,
params?: RouteParams[T],
absolute?: boolean,
config?: Config
): string;
declare function route<T extends keyof RouteParams>(): CustomRouter<T>;
declare function route<T extends keyof RouteParams>(
name: T,
params?: RouteParams[T],
absolute?: boolean,
config?: Config,
): string;
}
declare module "vue" {
interface ComponentCustomProperties {
route: (<T extends keyof RouteParams>() => CustomRouter<T>) &
(<T extends keyof RouteParams>(
name: T,
params?: RouteParams[T],
absolute?: boolean,
config?: Config
) => string);
}
interface ComponentCustomProperties {
route: (<T extends keyof RouteParams>() => CustomRouter<T>) &
(<T extends keyof RouteParams>(
name: T,
params?: RouteParams[T],
absolute?: boolean,
config?: Config,
) => string);
}
}
4 changes: 1 addition & 3 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ export async function generate(options: CLIOptions) {

createModelDirectory(modelName);

const namespacedModel = `${getNamespaceForCommand(
modelPath,
)}\\\\${modelName}`;
const namespacedModel = `${getNamespaceForCommand(modelPath)}/${modelName}`;
const outputPath = path.join(tmpDir, `${modelName}.json`);

const modelShowCommand = `php artisan model:show ${namespacedModel} --json`;
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const convertCamelToSnake = (camelCaseString: string): string => {
};

export const formatNamespaceForCommand = (namespace: string): string => {
return namespace.replaceAll(/\\/g, "\\\\");
return namespace.replaceAll(/\\/g, "/");
};

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

0 comments on commit 8b7281b

Please sign in to comment.