Skip to content

Commit

Permalink
v2.0.03
Browse files Browse the repository at this point in the history
Routes generation fixes with ESLint (typo, multiple params).
  • Loading branch information
ewilan-riviere committed Apr 8, 2024
1 parent b91196b commit ca515c3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 3 additions & 2 deletions lib/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const Routes: Record<App.Route.Name, App.Route.Link> = {
},
'download.show': {
name: 'download.show',
path: '/download/{podcast_slug}',
path: '/download/{feed_slug}/{podcast_slug}',
params: {
feed_slug: 'string',
podcast_slug: 'string',
},
methods: ['GET'],
Expand Down Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion lib/type-routes.d.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/Typed/Route/TypeRouteListTs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 = <<<typescript
params: {
{$params}
Expand Down
1 change: 1 addition & 0 deletions src/Typescriptable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Typescriptable
* @var string[]
*/
const TS_HEAD = [
'/* eslint-disable eslint-comments/no-unlimited-disable */',
'/* eslint-disable */',
'/* prettier-ignore */',
'// @ts-nocheck',
Expand Down
8 changes: 4 additions & 4 deletions tests/Data/routes.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
"download.show": {
"name": "download.show",
"methods": ["GET", "HEAD"],
"uri": "download/{podcast_slug}",
"uri": "download/{feed_slug}/{podcast_slug}",
"action": "App\\Http\\Controllers\\DownloadController@show",
"middleware": [
"web",
"Illuminate\\Routing\\Middleware\\SubstituteBindings"
],
"example": "http://app.p1pdd.test/download/{podcast_slug}",
"parameters": ["podcast_slug"]
"parameters": ["feed_slug", "podcast_slug"]
},
"feeds.index": {
"name": "feeds.index",
Expand Down Expand Up @@ -1075,14 +1075,14 @@
"podcasts.show": {
"name": "podcasts.show",
"methods": ["GET", "HEAD"],
"uri": "podcasts/{podcast_slug}",
"uri": "podcasts/{feed_slug}/{podcast_slug}",
"action": "App\\Http\\Controllers\\PodcastController@show",
"middleware": [
"web",
"Illuminate\\Routing\\Middleware\\SubstituteBindings"
],
"example": "http://app.p1pdd.test/podcasts/{podcast_slug}",
"parameters": ["podcast_slug"]
"parameters": ["feed_slug", "podcast_slug"]
},
"posts.index": {
"name": "posts.index",
Expand Down

0 comments on commit ca515c3

Please sign in to comment.