From ca515c3615dcfddc18fe52563fee50240d408395 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Mon, 8 Apr 2024 12:11:10 +0200 Subject: [PATCH] v2.0.03 Routes generation fixes with ESLint (typo, multiple params). --- composer.json | 2 +- lib/routes.ts | 5 +++-- lib/type-routes.d.ts | 2 +- src/Typed/Route/TypeRouteListTs.php | 11 +++++++++-- src/Typescriptable.php | 1 + tests/Data/routes.json | 8 ++++---- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 2a135b4..a491064 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "kiwilan/typescriptable-laravel", "description": "PHP package for Laravel to type Eloquent models, routes, Spatie Settings with autogenerated TypeScript. If you want to use some helpers with Inertia, you can install associated NPM package.", - "version": "2.0.02", + "version": "2.0.03", "keywords": [ "kiwilan", "laravel", diff --git a/lib/routes.ts b/lib/routes.ts index 78413a4..11ffee9 100644 --- a/lib/routes.ts +++ b/lib/routes.ts @@ -26,8 +26,9 @@ const Routes: Record = { }, 'download.show': { name: 'download.show', - path: '/download/{podcast_slug}', + path: '/download/{feed_slug}/{podcast_slug}', params: { + feed_slug: 'string', podcast_slug: 'string', }, methods: ['GET'], @@ -281,7 +282,7 @@ declare global { if (typeof window !== 'undefined') { // eslint-disable-next-line valid-typeof if (typeof window !== undefined && typeof window?.Routes !== undefined) - window?.Routes = Routes + window.Routes = Routes } export { Routes } diff --git a/lib/type-routes.d.ts b/lib/type-routes.d.ts index 567ad32..aabf870 100644 --- a/lib/type-routes.d.ts +++ b/lib/type-routes.d.ts @@ -1,7 +1,7 @@ // This file is auto generated by TypescriptableLaravel. declare namespace App.Route { export type Name = 'api/user' | 'current-user-photo.destroy' | 'current-user.destroy' | 'dashboard' | 'download.show' | 'feeds.index' | 'feeds.show' | 'home' | 'login' | 'logout' | 'other-browser-sessions.destroy' | 'page.about' | 'page.p1pdd' | 'page.pqd2p' | 'page.subscribe' | 'password.confirm' | 'password.confirmation' | 'password.email' | 'password.request' | 'password.reset' | 'password.update' | 'podcasts.index' | 'podcasts.show' | 'posts.index' | 'posts.show' | 'profile.show' | 'rss.index' | 'rss.show' | 'sanctum.csrf-cookie' | 'submission.index' | 'submission.store' | 'two-factor-challenge' | 'two-factor.confirm' | 'two-factor.disable' | 'two-factor.enable' | 'two-factor.login' | 'two-factor.qr-code' | 'two-factor.recovery-codes' | 'two-factor.secret-key' | 'user-password.update' | 'user-profile-information.update' | 'user/confirm-password' | 'user/two-factor-recovery-codes' - export type Path = '/' | '/a-propos' | '/api/user' | '/blog' | '/blog/{post_slug}' | '/contact' | '/dashboard' | '/download/{podcast_slug}' | '/feeds' | '/feeds/{feed_slug}' | '/forgot-password' | '/login' | '/logout' | '/p1pdd' | '/podcasts' | '/podcasts/{podcast_slug}' | '/pqd2p' | '/reset-password' | '/reset-password/{token}' | '/rss' | '/rss/{feed_slug}' | '/s-abonner' | '/sanctum/csrf-cookie' | '/two-factor-challenge' | '/user' | '/user/confirm-password' | '/user/confirmed-password-status' | '/user/confirmed-two-factor-authentication' | '/user/other-browser-sessions' | '/user/password' | '/user/profile' | '/user/profile-information' | '/user/profile-photo' | '/user/two-factor-authentication' | '/user/two-factor-qr-code' | '/user/two-factor-recovery-codes' | '/user/two-factor-secret-key' + export type Path = '/' | '/a-propos' | '/api/user' | '/blog' | '/blog/{post_slug}' | '/contact' | '/dashboard' | '/download/{feed_slug}/{podcast_slug}' | '/feeds' | '/feeds/{feed_slug}' | '/forgot-password' | '/login' | '/logout' | '/p1pdd' | '/podcasts' | '/podcasts/{podcast_slug}' | '/pqd2p' | '/reset-password' | '/reset-password/{token}' | '/rss' | '/rss/{feed_slug}' | '/s-abonner' | '/sanctum/csrf-cookie' | '/two-factor-challenge' | '/user' | '/user/confirm-password' | '/user/confirmed-password-status' | '/user/confirmed-two-factor-authentication' | '/user/other-browser-sessions' | '/user/password' | '/user/profile' | '/user/profile-information' | '/user/profile-photo' | '/user/two-factor-authentication' | '/user/two-factor-qr-code' | '/user/two-factor-recovery-codes' | '/user/two-factor-secret-key' export interface Params { 'login': never 'logout': never diff --git a/src/Typed/Route/TypeRouteListTs.php b/src/Typed/Route/TypeRouteListTs.php index a84fc7c..9802548 100644 --- a/src/Typed/Route/TypeRouteListTs.php +++ b/src/Typed/Route/TypeRouteListTs.php @@ -55,10 +55,10 @@ interface Window { } } - const appUrl = '{$appUrl}'; + const appUrl = '{$appUrl}' if (typeof window !== 'undefined') { - if (typeof window !== undefined && typeof window?.Routes !== undefined) + if (typeof window !== 'undefined' && typeof window?.Routes !== 'undefined') window.Routes = Routes } @@ -77,6 +77,13 @@ private function setTypescript(): string $params = 'params: undefined'; } else { $params = $params->join(' '); + if (str_contains($params, ',')) { + $paramsExplode = explode(',', $params); + $paramsExplode = array_map(fn ($param) => trim($param), $paramsExplode); + $paramsExplode = array_filter($paramsExplode, fn ($param) => ! empty($param)); + $paramsExplode = array_map(fn ($param) => "{$param},", $paramsExplode); + $params = implode("\n ", $paramsExplode); + } $params = <<