Skip to content

Commit

Permalink
feat: add array field support (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyichv authored Sep 17, 2024
1 parent 5c9b7d7 commit de930e1
Show file tree
Hide file tree
Showing 11 changed files with 342 additions and 246 deletions.
5 changes: 5 additions & 0 deletions .changeset/thin-peaches-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-zod-form": patch
---

feat: add array fields support
10 changes: 5 additions & 5 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import template from "lodash.template";
import ora from "ora";
import prompts from "prompts";
import { z } from "zod";
import { discoverZodSchemas } from "../utils/discover-zod";
import { getFormFields } from "../utils/form-fields";
import { getConfig } from "../utils/get-config";
import { handleError } from "../utils/handle-error";
import { logger } from "../utils/logger";
import { parseZodSchemasFromFile } from "../utils/parse-zod";
import { formTemplate } from "../utils/templates/form";
import { transform } from "../utils/transformers";

Expand All @@ -39,7 +39,7 @@ export const generate = new Command()
process.exit(1);
}

const zodSchemas = discoverZodSchemas(config, options.schema);
const zodSchemas = parseZodSchemasFromFile(config, options.schema);

if (Object.keys(zodSchemas).length === 0) {
logger.error("No Zod schemas found in the specified file.");
Expand Down Expand Up @@ -103,7 +103,7 @@ export const generate = new Command()
process.exit(1);
}

const { components, imports } = getFormFields(
const { components, imports, functions } = getFormFields(
zodSchemas[selectedSchema].schema,
);

Expand All @@ -112,9 +112,9 @@ export const generate = new Command()
schema: selectedSchema,
formName:
camelCase(name).charAt(0).toUpperCase() + camelCase(name).slice(1),
defaultValues: "{}",
functions,
components,
schemaImport: zodSchemas[selectedSchema].importStr,
schemaImport: zodSchemas[selectedSchema].import,
imports,
}),
filename: `${name}.tsx`,
Expand Down
134 changes: 0 additions & 134 deletions src/utils/discover-zod.ts

This file was deleted.

Loading

0 comments on commit de930e1

Please sign in to comment.