Skip to content

Latest commit

 

History

History
127 lines (96 loc) · 3 KB

README_PLUGINS.md

File metadata and controls

127 lines (96 loc) · 3 KB

prisma-generator-builder plugins

Custom generator logic can be provided via additional plugins.

Contract

interface PrismaGeneratorBuilderPluginInterface {
  readonly location: string;

  run(config: PrismaGeneratorBuilderConfig): void;
}

Implementation Example

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");

See abstract.plugin.ts here.

Configuration options

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: [...],
};
  • provider

    Prisma provider name

  • prettyName

    Prisma pretty name for generator

  • defaultOutput

    Prisma generator output directory relative to <project root>prisma/ directory.

  • name, version, author, description, license

    Values for package.json

  • outputDirectoryRoot

    Root path for generated files

  • plugins

    Set of plugins implementing PrismaGeneratorBuilderPluginInterface.

Default plugins

  • PluginBin : generates bin.ts script
  • PluginEnv : generates .env file
  • PluginGenerator : generates generator.ts script
  • PluginGitIgnore : generates .gitignore file
  • PluginPackageJson : generates package.json file
  • PluginPrismaSchema : generates schema.prisma file
  • PluginReadme : generates README.md file
  • PluginCopyFiles : copies set of files without modification

Usage

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.