import type { BinaryPaths , GeneratorConfig , GeneratorManifest , GeneratorOptions } from '@prisma/generator-helper' ; import { GeneratorProcess } from '@prisma/generator-helper' ; import { parseEnvValue } from './utils/parseEnvValue' ; export class Generator { private generatorProcess : GeneratorProcess ; public manifest : GeneratorManifest | null = null ; public config : GeneratorConfig ; public options ? : GeneratorOptions ; constructor ( executablePath , config , isNode ? ) { this . config = config ; this . generatorProcess = new GeneratorProcess ( executablePath , isNode ) ; } async init ( ) { await this . generatorProcess . init ( ) ; this . manifest = await this . generatorProcess . getManifest ( this . config ) ; } stop ( ) { this . generatorProcess . stop ( ) ; } generate ( ) { if ( ! this . options ) { throw new Error ( `Please first run .setOptions() on the Generator to initialize the options` ) ; } return this . generatorProcess . generate ( this . options ) ; } setOptions ( options ) { this . options = options ; } setBinaryPaths ( binaryPaths ) { if ( ! this . options ) { throw new Error ( `Please first run .setOptions() on the Generator to initialize the options` ) ; } this . options . binaryPaths = binaryPaths ; } /**
     * Returns the pretty name of the generator specified in the manifest (e.g.,
     * "Prisma Client"), or, if the former is not defined, the generator's
     * provider name (e.g., "prisma-client-js") as a fallback.
     */ getPrettyName ( ) { return this . manifest ?. prettyName ?? this . getProvider ( ) ; } /**
     * Returns the provider name, parsed and resolved from environment variable
     * if necessary.
     */ getProvider ( ) { return parseEnvValue ( this . config . provider ) ; } }