Skip to content

Commit

Permalink
fix: schema as arugment (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyichv authored Sep 17, 2024
1 parent 7134234 commit e373e52
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-clocks-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-zod-form": patch
---

fix: use argument instead of option
8 changes: 4 additions & 4 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const generateOptionsSchema = z.object({
export const generate = new Command()
.name("generate")
.description("Generate shadcn/ui form from zod schema")
.option("-s, --schema <path>", "the path to zod schemas folder")
.argument("<schema>", "the path to zod schemas folder")
.option("-n, --name <name>", "the name of the form")
.action(async (opts) => {
.action(async (schema, opts) => {
try {
const options = generateOptionsSchema.parse(opts);
const options = generateOptionsSchema.parse({ schema, ...opts });
const cwd = process.cwd();
const config = await getConfig(cwd);
if (!config) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export const generate = new Command()
).name;

const spinner = ora(
`Generating form for schema: ${selectedSchema} at ${config.resolvedPaths.forms}/${name}.tsx`,
`Generating form for schema: ${selectedSchema} at ${config.resolvedPaths.forms}/${name}.tsx\n`,
).start();

const targetDir = config.resolvedPaths.forms;
Expand Down
7 changes: 4 additions & 3 deletions src/utils/templates/array-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const arrayFieldTemplate = {
component: `
<div>
{fields.map((field, index) => (
<div key={field.id} className="flex items-center space-x-2">
<div key={field.id} className="flex w-full items-end space-x-2">
<%= children %>
<Button
type="button"
Expand All @@ -24,12 +24,13 @@ export const arrayFieldTemplate = {
))
}
<Button
size="icon"
variant="ghost"
size="sm"
className="mt-2"
type="button"
onClick={() => append(<%= defaultValues %>)}
>
<PlusIcon className="size-4" />
<span className="ml-2">Add Item</span>
</Button>
</div>`,
};
3 changes: 2 additions & 1 deletion src/utils/templates/form.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const formTemplate = `
export const formTemplate = `"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import type { z } from "zod";
Expand Down

0 comments on commit e373e52

Please sign in to comment.