From 66e7a644b72ac381ded8ee086c954c71ae15fa3d Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Wed, 15 Dec 2021 14:45:13 +0100 Subject: [PATCH 1/3] Add docs for custom templates option --- app/pages/docs/cli-generate.mdx | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/app/pages/docs/cli-generate.mdx b/app/pages/docs/cli-generate.mdx index 6f1d2573..40a5488c 100644 --- a/app/pages/docs/cli-generate.mdx +++ b/app/pages/docs/cli-generate.mdx @@ -105,6 +105,49 @@ app/tasks/mutations/updateTask.ts Note that this will not generate the relationships between the models, only the queries, mutations and pages. +##### `--templateDir` + +Shorthand: `-t` + +Allows you to specify a custom template directory. If you want to use +custom templates insetad of the default ones (e.g. with different styles), +you can pass a path to the local template directory. The template +directory should have the following structure: + +```bash +. +├── 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). + +**Usage:** + +```bash +blitz generate all projects -t ./my-custom-templates +``` + ##### `--dry-run` Shorthand: `-d` From 8de1a1e6c40defde67bdaa66d8dcc2c090f1f6be Mon Sep 17 00:00:00 2001 From: JuanM04 Date: Wed, 15 Dec 2021 12:24:17 -0300 Subject: [PATCH 2/3] Update cli-generate.mdx --- app/pages/docs/cli-generate.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pages/docs/cli-generate.mdx b/app/pages/docs/cli-generate.mdx index 40a5488c..512f6735 100644 --- a/app/pages/docs/cli-generate.mdx +++ b/app/pages/docs/cli-generate.mdx @@ -114,7 +114,7 @@ custom templates insetad of the default ones (e.g. with different styles), you can pass a path to the local template directory. The template directory should have the following structure: -```bash +``` . ├── form │ └── __ModelName__Form.tsx From 311e2bf6fa8e080c2515192606ca8f85faf8a4e6 Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Thu, 16 Dec 2021 16:29:22 +0100 Subject: [PATCH 3/3] Move config to blitz.config --- app/pages/docs/blitz-config.mdx | 44 +++++++++++++++++++++++++++++ app/pages/docs/cli-generate.mdx | 50 +++++---------------------------- 2 files changed, 51 insertions(+), 43 deletions(-) diff --git a/app/pages/docs/blitz-config.mdx b/app/pages/docs/blitz-config.mdx index 1220cff9..13087f23 100644 --- a/app/pages/docs/blitz-config.mdx +++ b/app/pages/docs/blitz-config.mdx @@ -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: + +```bash +. +├── 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} diff --git a/app/pages/docs/cli-generate.mdx b/app/pages/docs/cli-generate.mdx index 40a5488c..1632d1bd 100644 --- a/app/pages/docs/cli-generate.mdx +++ b/app/pages/docs/cli-generate.mdx @@ -105,49 +105,6 @@ app/tasks/mutations/updateTask.ts Note that this will not generate the relationships between the models, only the queries, mutations and pages. -##### `--templateDir` - -Shorthand: `-t` - -Allows you to specify a custom template directory. If you want to use -custom templates insetad of the default ones (e.g. with different styles), -you can pass a path to the local template directory. The template -directory should have the following structure: - -```bash -. -├── 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). - -**Usage:** - -```bash -blitz generate all projects -t ./my-custom-templates -``` - ##### `--dry-run` Shorthand: `-d` @@ -311,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).