Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for custom templates option #630

Merged
merged 4 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/pages/docs/blitz-config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,50 @@ module.exports = {
}
```

## Codegen {#codegen}

If you want to use custom templates with `blitz generate` instead of the
default ones (e.g. with different styles), you can provide a path to the
local template directory:

```js
module.exports = {
codegen: {
templateDir: "./templates",
},
}
```

The template directory should have the following structure:

```
.
├── form
│ └── __ModelName__Form.tsx
├── mutation
│ └── __input__.ts
├── mutations
│ ├── create__ModelName__.ts
│ ├── delete__ModelName__.ts
│ └── update__ModelName__.ts
├── page
│ ├── __modelIdParam__
│ │ └── edit.tsx
│ ├── __modelIdParam__.tsx
│ ├── index.tsx
│ └── new.tsx
├── queries
│ ├── get__ModelName__.ts
│ └── get__ModelNames__.ts
└── query
└── __name__.ts
```

If some folders are omitted in your custom template directory,
`blitz generate` will fallback to the default templates. You can check
them out
[here](https://github.com/blitz-js/blitz/tree/canary/packages/generator/templates).

## CLI {#cli}

### Clear Console On Blitz Dev {#clear-console-on-blitz-dev}
Expand Down
7 changes: 7 additions & 0 deletions app/pages/docs/cli-generate.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,10 @@ field to the `Task` model.
```bash
blitz generate model task subheading:string
```

### Custom templates {#custom-templates}

If you want to use custom templates with `blitz generate` instead of the
default ones (e.g. with different styles), you can provide a path to the
local directory with template files. You can specify it in your
`blitz.config.ts` file. [Read more here](/docs/blitz-config#codegen).