-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
generator.ts
executable file
·60 lines (52 loc) · 2.17 KB
/
generator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Debug from '@prisma/debug'
import { enginesVersion } from '@prisma/engines-version'
import { generatorHandler } from '@prisma/generator-helper'
import { ClientEngineType, getClientEngineType, parseEnvValue } from '@prisma/sdk'
import { externalToInternalDmmf } from '../runtime/externalToInternalDmmf'
import { generateClient } from './generateClient'
import { getDMMF } from './getDMMF'
import { dmmfToTypes } from './utils/types/dmmfToTypes'
const debug = Debug('prisma:client:generator')
// See https://www.notion.so/prismaio/Prisma-Generators-a2cdf262207a4e9dbcd0e362dfac8dc0
const pkg = require('../../package.json')
const clientVersion = pkg.version
// if the file has been run as a CLI
if (process.argv[1] === __filename) {
generatorHandler({
onManifest(config) {
const requiredEngine = getClientEngineType(config) === ClientEngineType.Library ? 'libqueryEngine' : 'queryEngine'
debug(`requiredEngine: ${requiredEngine}`)
return {
defaultOutput: '.prisma/client', // the value here doesn't matter, as it's resolved in https://github.com/prisma/prisma/blob/main/cli/sdk/src/getGenerators.ts
prettyName: 'Prisma Client',
requiresEngines: [requiredEngine],
version: clientVersion,
requiresEngineVersion: enginesVersion,
}
},
async onGenerate(options) {
// CLI versions < 2.20.0 still send a string
// CLIs >= 2.20.0 send an `EnvValue`
const outputDir =
typeof options.generator.output === 'string'
? options.generator.output
: parseEnvValue(options.generator.output!)
return generateClient({
datamodel: options.datamodel,
schemaPath: options.schemaPath,
binaryPaths: options.binaryPaths!,
datasources: options.datasources,
outputDir,
copyRuntime: Boolean(options.generator.config.copyRuntime),
dmmf: options.dmmf,
generator: options.generator,
engineVersion: options.version,
clientVersion,
transpile: true,
activeProvider: options.datasources[0]?.activeProvider,
dataProxy: options.dataProxy,
})
},
})
}
export { dmmfToTypes, externalToInternalDmmf, getDMMF }