Skip to content

Commit

Permalink
v2.0.01
Browse files Browse the repository at this point in the history
Add `appUrl` to `routes.ts`.
  • Loading branch information
ewilan-riviere committed Mar 30, 2024
1 parent c3b2ca0 commit f6a1c64
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 96 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.0",
"version": "2.0.01",
"keywords": [
"kiwilan",
"laravel",
Expand Down
5 changes: 4 additions & 1 deletion src/Typed/Route/TypeRouteListTs.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public static function make(Collection $routes): self
public function get(): string
{
$head = Typescriptable::head();
$appUrl = config('app.url');

return <<<typescript
{$head}
Expand All @@ -54,12 +55,14 @@ interface Window {
}
}
const appUrl = '{$appUrl}';
if (typeof window !== 'undefined') {
if (typeof window !== undefined && typeof window?.Routes !== undefined)
window?.Routes = Routes
}
export { Routes }
export { Routes, appUrl }
typescript;
}
Expand Down
94 changes: 0 additions & 94 deletions src/Typed/Route/TypeRouteTs.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,6 @@ public function get(): string
$this->tsGlobalTypesPatch = empty($this->tsGlobalTypesPatch) ? 'never' : $this->tsGlobalTypesPatch;
$this->tsGlobalTypesDelete = empty($this->tsGlobalTypesDelete) ? 'never' : $this->tsGlobalTypesDelete;

// return <<<typescript
// // This file is auto generated by TypescriptableLaravel.
// declare namespace App.Route {
// export interface Name {$this->tsNames}
// export interface Path {$this->tsPaths};
// export interface Params {
// {$this->tsParams}
// };

// export interface Method = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
// export interface Entity { name: App.Route.Name; path: App.Route.Path; params?: App.Route.Params[Route.Name], method: App.Route.Method; }

// export interface Param = string | number | boolean | undefined
// export interface Type {$this->tsGlobalTypes}
// export interface TypeGet {$this->tsGlobalTypesGet}
// export interface TypePost {$this->tsGlobalTypesPost}
// export interface TypePut {$this->tsGlobalTypesPut}
// export interface TypePatch {$this->tsGlobalTypesPatch}
// export interface TypeDelete {$this->tsGlobalTypesDelete}
// }

// declare namespace App.Typed {
// {$this->tsTypes}
// }
// typescript;

$head = Typescriptable::head();

return <<<typescript
Expand Down Expand Up @@ -115,15 +89,6 @@ private function parse()
$this->tsNames = $this->setTsNames();
$this->tsPaths = $this->setTsPaths();
$this->tsParams = $this->setTsParams();

// $this->tsTypes = $this->setTsTypes();
// $this->tsGlobalTypes = $this->setTsGlobalTypes();

// $this->tsGlobalTypesGet = $this->setTsGlobalTypesMethod('GET');
// $this->tsGlobalTypesPost = $this->setTsGlobalTypesMethod('POST');
// $this->tsGlobalTypesPut = $this->setTsGlobalTypesMethod('PUT');
// $this->tsGlobalTypesPatch = $this->setTsGlobalTypesMethod('PATCH');
// $this->tsGlobalTypesDelete = $this->setTsGlobalTypesMethod('DELETE');
}

private function setTsNames(): string
Expand Down Expand Up @@ -175,65 +140,6 @@ private function setTsParams(): string
}, "\n");
}

// private function setTsTypes(): string
// {
// return $this->collectRoutes(function (TypeRoute $route) {
// $params = '';

// if (empty($route->parameters())) {
// $params = 'params?: undefined';
// } else {
// $params = collect($route->parameters())
// ->map(function (TypeRouteParam $param) {
// $required = $param->required() ? '' : '?';

// return "{$param->name()}{$required}: App.Route.Param,";
// })
// ->join(' ');
// $params = <<<typescript
// params: {
// {$params}
// }
// typescript;
// }

// return <<<typescript
// type {$route->routeName()} = {
// name: '{$route->pathType()}',
// {$params},
// query?: Record<string, App.Route.Param>,
// hash?: string,
// }
// typescript;
// }, ";\n");
// }

// private function setTsGlobalTypes(): string
// {
// return $this->collectRoutes(function (TypeRoute $route) {
// return <<<typescript
// App.Route.Typed.{$route->routeName()}
// typescript;
// }, ' | ');
// }

// private function setTsGlobalTypesMethod(string $method): string
// {
// $routes = $this->collectRoutesMethod($method);

// return collect($routes)
// ->map(function (TypeRoute $route) {
// return <<<typescript
// App.Route.Typed.{$route->routeName()}
// typescript;
// })->join(' | ');
// }

// private function collectRoutesMethod(string $method): Collection
// {
// return $this->routes->filter(fn (TypeRoute $route) => $route->method() === $method);
// }

private function collectRoutes(Closure $closure, ?string $join = null): string|Collection
{
$routes = $this->routes->map(fn (TypeRoute $route, string $key) => $closure($route, $key));
Expand Down

0 comments on commit f6a1c64

Please sign in to comment.