Skip to content

Commit

Permalink
Support formRequestPath option (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
NaoyaMiyagawa authored May 19, 2024
1 parent 6a5a4f3 commit f0645e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,17 @@ Usage: laravel-typegen [options]
Generate TypeScript types from your Laravel code

Options:
-V, --version output the version number
-o, --output <value> Output directory (default: "resources/js/types")
--laravel-enum Use Laravel Enum (default: false)
--enum-path <value> Path to enum files (default: "app/Enums")
--model-path <value> Path to model files (default: "app/Models")
-z, --ziggy Generate types for ziggy (default: false)
--vendor-routes Include routes defined by vendor packages (default: false)
--ignore-route-dts Ignore generating route.d.ts (default: false)
--form-request Generate types for FormRequests (default: false)
-h, --help display help for command
-V, --version output the version number
-o, --output <value> Output directory (default: "resources/js/types")
--laravel-enum Use Laravel Enum (default: false)
--enum-path <value> Path to enum files (default: "app/Enums")
--model-path <value> Path to model files (default: "app/Models")
-z, --ziggy Generate types for ziggy (default: false)
--vendor-routes Include routes defined by vendor packages (default: false)
--ignore-route-dts Ignore generating route.d.ts (default: false)
--form-request Generate types for FormRequests (default: false)
--form-request-path <value> Path to FormRequest files (default: "app/Http/Requests")
-h, --help display help for command
```


Expand Down
7 changes: 7 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
tmpDir,
} from "./constants";
import fs from "fs";
import { defaultFormRequestPath } from "@7nohe/laravel-zodgen";

export type CLIOptions = {
output: string;
Expand All @@ -19,6 +20,7 @@ export type CLIOptions = {
vendorRoutes: boolean;
ignoreRouteDts: boolean;
formRequest: boolean;
formRequestPath: string;
};

const program = new Command();
Expand All @@ -35,6 +37,11 @@ program
.option("--vendor-routes", "Include routes defined by vendor packages", false)
.option("--ignore-route-dts", "Ignore generating route.d.ts", false)
.option("--form-request", "Generate types for FormRequests", false)
.option(
"--form-request-path <value>",
"Path to FormRequest files",
defaultFormRequestPath
)
.parse();

const options = program.opts<CLIOptions>();
Expand Down
7 changes: 2 additions & 5 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import {
tmpDir,
} from "./constants";
import path from "path";
import {
parseFormRequests,
defaultFormRequestPath,
} from "@7nohe/laravel-zodgen";
import { parseFormRequests } from "@7nohe/laravel-zodgen";
import { createFormRequestTypes } from "./formRequests/createFormRequestTypes";
import { formatNamespaceForCommand, getPhpAst, getPhpNamespace } from "./utils";

Expand Down Expand Up @@ -99,7 +96,7 @@ export async function generate(options: CLIOptions) {

if (options.formRequest) {
// Generate types for form requests
const rules = parseFormRequests(defaultFormRequestPath, true);
const rules = parseFormRequests(options.formRequestPath, true);
const formRequestSource = createFormRequestTypes(rules);
print(formRequestsFileName, formRequestSource, options.output ?? defaultOutputPath);
}
Expand Down

0 comments on commit f0645e5

Please sign in to comment.