From 8b7281ba067c60dfc01c32f8617242c8254a5f87 Mon Sep 17 00:00:00 2001 From: Urata Daiki <7nohe@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:08:54 +0900 Subject: [PATCH] fix: Support namespaced models for windows (#38) --- .../.laravel-typegen-tmp/User.json | 6 +-- .../.laravel-typegen-tmp/UserContact.json | 6 +-- .../resources/js/types/route.d.ts | 48 +++++++++---------- src/generate.ts | 4 +- src/utils.ts | 2 +- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/examples/laravel10-app/.laravel-typegen-tmp/User.json b/examples/laravel10-app/.laravel-typegen-tmp/User.json index 7521f7b..8fee873 100644 --- a/examples/laravel10-app/.laravel-typegen-tmp/User.json +++ b/examples/laravel10-app/.laravel-typegen-tmp/User.json @@ -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", diff --git a/examples/laravel10-app/.laravel-typegen-tmp/UserContact.json b/examples/laravel10-app/.laravel-typegen-tmp/UserContact.json index 2db8fd8..34d60d3 100644 --- a/examples/laravel10-app/.laravel-typegen-tmp/UserContact.json +++ b/examples/laravel10-app/.laravel-typegen-tmp/UserContact.json @@ -66,11 +66,7 @@ } ], "relations": [ - { - "name": "user", - "type": "BelongsTo", - "related": "App\\Models\\User" - } + { "name": "user", "type": "BelongsTo", "related": "App\\Models\\User" } ], "observers": [] } diff --git a/examples/laravel10-app/resources/js/types/route.d.ts b/examples/laravel10-app/resources/js/types/route.d.ts index 782c000..b38817e 100644 --- a/examples/laravel10-app/resources/js/types/route.d.ts +++ b/examples/laravel10-app/resources/js/types/route.d.ts @@ -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 = { - get params(): RouteParams[T]; - current(): Extract | undefined; - current( - name: Extract, - params?: RouteParams[T] - ): boolean; + get params(): RouteParams[T]; + current(): Extract | undefined; + current( + name: Extract, + params?: RouteParams[T], + ): boolean; } & Router; declare global { - declare function route(): CustomRouter; - declare function route( - name: T, - params?: RouteParams[T], - absolute?: boolean, - config?: Config - ): string; + declare function route(): CustomRouter; + declare function route( + name: T, + params?: RouteParams[T], + absolute?: boolean, + config?: Config, + ): string; } declare module "vue" { - interface ComponentCustomProperties { - route: (() => CustomRouter) & - (( - name: T, - params?: RouteParams[T], - absolute?: boolean, - config?: Config - ) => string); - } + interface ComponentCustomProperties { + route: (() => CustomRouter) & + (( + name: T, + params?: RouteParams[T], + absolute?: boolean, + config?: Config, + ) => string); + } } diff --git a/src/generate.ts b/src/generate.ts index 72bbcef..2288519 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -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`; diff --git a/src/utils.ts b/src/utils.ts index f7306ec..8a13e7f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 => {