Custom generator logic can be provided via additional plugins.
interface PrismaGeneratorBuilderPluginInterface {
readonly location: string;
run(config: PrismaGeneratorBuilderConfig): void;
}
Plugin example that generates example.ts
script.
plugin.example.ts
class PluginExample
extends AbstractPlugin
implements PrismaGeneratorBuilderPluginInterface {
public readonly location = "example.ts";
protected loadTemplate(template: PrismaGeneratorBuilderConfig): string {
return `// generated script example for ${template.name}
console.log("${template.prettyName}");
`;
}
}
example.ts
// generated script example for prisma-generator-example
console.log("Prisma Generator Example");
Default configuration options.
To use additional plugins add them to plugins
collection.
This collection can be set up as required.
const config: PrismaGeneratorBuilderConfig = {
provider: "provider",
prettyName: "prettyName",
defaultOutput: "defaultOutput",
name: "prisma-generator-example",
version: "1.0.0",
author: "John Doe",
description: "Prisma ORM Generator",
license: "MIT",
outputDirectoryRoot: "./build",
plugins: [...],
};
-
Prisma provider name
-
Prisma pretty name for generator
-
Prisma generator output directory relative to
<project root>prisma/
directory. -
Values for
package.json
-
Root path for generated files
-
Set of plugins implementing
PrismaGeneratorBuilderPluginInterface
.
PluginBin
: generatesbin.ts
scriptPluginEnv
: generates.env
filePluginGenerator
: generatesgenerator.ts
scriptPluginGitIgnore
: generates.gitignore
filePluginPackageJson
: generatespackage.json
filePluginPrismaSchema
: generatesschema.prisma
filePluginReadme
: generatesREADME.md
filePluginCopyFiles
: copies set of files without modification
import { PrismaGeneratorBuilder, PrismaGeneratorBuilderConfig } from "@prisma-generator-builder";
const config: PrismaGeneratorBuilderConfig = {
provider: "provider",
prettyName: "prettyName",
defaultOutput: "defaultOutput",
name: "prisma-generator-example",
version: "1.0.0",
author: "John Doe",
description: "Prisma ORM Generator",
license: "MIT",
outputDirectoryRoot: "./build",
plugins: [
new PluginBin(),
new PluginCopyFiles(),
new PluginEnv(),
new PluginGenerator(),
new PluginGitIgnore(),
new PluginPackageJson(),
new PluginPrismaSchema(),
new PluginReadme(),
],
};
PrismaGeneratorBuilder.run(config);
See builder.test.ts for an example.