prisma-generator-handlebars
v1.2.1
Published
Generate any text files from Prisma schema with Handlebars templates.
Downloads
71
Maintainers
Readme
prisma-generator-handlebars
Generate any text files from Prisma schema with Handlebars templates.
You can generate files such as:
- Database documents
- Entity-relation diagrams
- GraphQL schema
Getting started
Install this generator.
npm install -D prisma-generator-handlebars
Add the generator to
schema.prisma
. Changeoutput
andinputBasePath
options according to your use case.generator docs { provider = "prisma-generator-handlebars" output = "docs" inputBasePath = "docs" }
Create
{{ inputBasePath }}/templates
directory next toschema.prisma
.Put some handlebars template files in
templates
directory.docs/templates/models.md.handlebars
Models: {{#each datamodel.models}} - {{name}} {{#each fields}} - {{name}} {{/each}} {{/each}} Enums: {{#each datamodel.enums}} - {{name}} {{#each values}} - {{name}} {{/each}} {{/each}}
Run the generate command.
npx prisma generate
Templates will be rendered with Prisma
DMMF.Document
object as context.Models: - User - id - email - type - name - posts - Post - id - createdAt - updatedAt - title - content - published - viewCount - author - authorId Enums: - UserType - ADMIN - USER
Options
generator handlebars {
provider = "prisma-generator-handlebars"
output = "./generated"
inputBasePath = "."
templates = "./templates"
partials = "./partials"
helpers = "./helpers.js"
options = "./options.js"
}
| Option | Default | Description |
| --------------- | -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| output
| ./generated
| Generator output directory path. Relative paths are resolved from schema.prisma
. |
| inputBasePath
| .
| Base path for input paths. Relative paths are resolved from schema.prisma
. |
| templates
| ./templates
| Input template directory path. All files under this directory will be compiled as handlebars templates. |
| partials
| ./partials
| Input partial directory path. All files under this directory will be registered as handlebars partials. Partial names will be based on files' pathname relative to the directory, removing .handlebars
extension if exists. |
| helpers
| ./helpers.js
| Input helper script file path. All functions exported from the file will be registered as helpers. Helper names will be based on functions' exported name. |
| options
| ./options.js
| Input option script file path. Export object with names compileOptions
and runtimeOptions
. |
Helpers
pluralize and methods in change-case are registered as helpers by default.
Notes
Prisma DMMF is an internal AST and no backward compatibilities are guaranteed. Beware of breaking changes when updating your prisma cli versions.