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

Method parse

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

Source from the content-addressed store, hash-verified

48 `)
49
50 public async parse(
51 argv: string[],
52 config: PrismaConfigInternal,
53 baseDir: string = process.cwd(),
54 ): Promise<string | Error> {
55 const before = Math.round(performance.now())
56 const args = arg(argv, {
57 '--help': Boolean,
58 '-h': '--help',
59 '--schema': String,
60 '--config': String,
61 '--telemetry-information': String,
62 '--check': Boolean,
63 })
64
65 if (args instanceof Error) {
66 return this.help(args.message)
67 }
68
69 if (args['--help']) {
70 return this.help()
71 }
72
73 const { schemaPath, schemas } = await getSchemaWithPath({
74 schemaPath: createSchemaPathInput({
75 schemaPathFromArgs: args['--schema'],
76 schemaPathFromConfig: config.schema,
77 baseDir,
78 }),
79 })
80 printSchemaLoadedMessage(schemaPath)
81
82 const formattedDatamodel = await formatSchema({ schemas })
83
84 // Validate whether the formatted output is a valid schema
85 validate({
86 schemas: formattedDatamodel,
87 })
88
89 if (args['--check']) {
90 for (const [filename, formattedSchema] of formattedDatamodel) {
91 const originalSchemaTuple = schemas.find((s) => s[0] === filename)
92 if (!originalSchemaTuple) {
93 return new HelpError(`${bold(red(`!`))} The schema ${underline(filename)} is not found in the schema list.`)
94 }
95 const [, originalSchema] = originalSchemaTuple
96 if (originalSchema !== formattedSchema) {
97 return new HelpError(
98 `${bold(red(`!`))} There are unformatted files. Run ${underline('prisma format')} to format them.`,
99 )
100 }
101 }
102 return 'All files are formatted correctly!'
103 }
104
105 for (const [filename, data] of formattedDatamodel) {
106 await fs.writeFile(filename, data)
107 }

Callers

nothing calls this directly

Calls 8

helpMethod · 0.95
argFunction · 0.90
getSchemaWithPathFunction · 0.90
createSchemaPathInputFunction · 0.90
printSchemaLoadedMessageFunction · 0.90
formatSchemaFunction · 0.90
validateFunction · 0.90
formatmsFunction · 0.90

Tested by

no test coverage detected