blitz generate

Alias: blitz g

Use this command to scaffold all the boring code into your project.

Can generate pages, queries, and mutations. Generating

Prisma models is coming soon. Also coming soon is support for custom templates based on the built-in templates so you can customize the generator to your app's needs.

blitz generate [type] [model]
ArgumentRequiredDescription
typeYesType of files to generate. Options: all, crud, queries, mutations, and pages.
modelYesThe model name to generate files for
Example Output

blitz generate all project will generate the following files:

app/projects/pages/projects/[projectId]/edit.tsx
app/projects/pages/projects/[projectId].tsx
app/projects/pages/projects/index.tsx
app/projects/pages/projects/new.tsx
app/projects/components/ProjectForm.tsx
app/projects/queries/getProject.ts
app/projects/queries/getProjects.ts
app/projects/mutations/createProject.ts
app/projects/mutations/deleteProject.ts
app/projects/mutations/updateProject.ts

For the above example, you can view the generated project index page at

localhost:3000/projects

Options

context/model

For organization of files within your project, you can specify a nested folder path in which to generate the files.

blitz generate all admin/products
// Will generate files in `app/admin/products` instead of `app/products`

Alternatively, you can provide the folder path via the

--context or -c options

--parent

Shorthand:

-p

Used to specify that you want to generate files for a model which is a child of a parent model.

For example, say you have

Project and Task models. A Task belongs to a Project and Project has many Tasks. You would run this command:

blitz generate all task --parent project

which would generate the following files:

app/tasks/pages/projects/[projectId]/tasks/[taskId]/edit.tsx
app/tasks/pages/projects/[projectId]/tasks/[taskId].tsx
app/tasks/pages/projects/[projectId]/tasks/index.tsx
app/tasks/pages/projects/[projectId]/tasks/new.tsx
app/tasks/components/TaskForm.tsx
app/tasks/queries/getTask.ts
app/tasks/queries/getTasks.ts
app/tasks/mutations/createTask.ts
app/tasks/mutations/deleteTask.ts
app/tasks/mutations/updateTask.ts
--dry-run

Shorthand:

-d

Displays what files would be generated but does not write the files to disk.

Examples

blitz generate all project
blitz generate mutations project
blitz generate crud admin/topsecret/files
blitz generate pages tasks --parent=projects
Idea for improving this page?Edit it on Github