MCPcopy
hub / github.com/prisma/prisma / parse

Method parse

packages/cli/src/Generate.ts:108–336  ·  view source on GitHub ↗
(
    argv: string[],
    config: PrismaConfigInternal,
    baseDir: string = process.cwd(),
  )

Source from the content-addressed store, hash-verified

106 })
107
108 public async parse(
109 argv: string[],
110 config: PrismaConfigInternal,
111 baseDir: string = process.cwd(),
112 ): Promise<string | Error> {
113 const args = arg(argv, {
114 '--help': Boolean,
115 '-h': '--help',
116 '--watch': Boolean,
117 '--schema': String,
118 '--config': String,
119 '--no-hints': Boolean,
120 '--generator': [String],
121 '--telemetry-information': String,
122 '--require-models': Boolean,
123 '--sql': Boolean,
124 })
125
126 const allowNoModels = !args['--require-models']
127
128 const cwd = process.cwd()
129 if (isError(args)) {
130 return this.help(args.message)
131 }
132
133 if (args['--help']) {
134 return this.help()
135 }
136
137 const watchMode = args['--watch'] || false
138
139 const schemaResult = await getSchemaWithPath({
140 schemaPath: createSchemaPathInput({
141 schemaPathFromArgs: args['--schema'],
142 schemaPathFromConfig: config.schema,
143 baseDir,
144 }),
145 cwd,
146 })
147
148 if (!schemaResult) return ''
149
150 const schemaContext = await processSchemaResult({ schemaResult })
151
152 // TODO Extract logic from here
153 let hasJsClient = false
154 let generators: Generator[] | undefined
155 let clientGeneratorVersion: string | null = null
156
157 let typedSqlData: { validatedConfig: PrismaConfigWithDatasource; typedSql: SqlQueryOutput[] } | undefined
158 if (args['--sql']) {
159 const validatedConfig = validatePrismaConfigWithDatasource({ config, cmd: 'generate --sql' })
160 const typedSql = await introspectSql(validatedConfig, baseDir, schemaContext)
161 typedSqlData = {
162 validatedConfig,
163 typedSql,
164 }
165 }

Callers

nothing calls this directly

Calls 15

helpMethod · 0.95
addMethod · 0.95
argFunction · 0.90
isErrorFunction · 0.90
getSchemaWithPathFunction · 0.90
createSchemaPathInputFunction · 0.90
processSchemaResultFunction · 0.90
introspectSqlFunction · 0.90
getGeneratorsFunction · 0.90
parseEnvValueFunction · 0.90
sqlDirPathFunction · 0.90

Tested by

no test coverage detected