import Debug from '@prisma/debug' ; import { BinaryType } from '@prisma/fetch-engine' ; import execa from 'execa' ; import fs from 'fs' ; import { resolveBinary } from '../resolveBinary' ; const debug = Debug ( 'prisma:formatSchema' ) ; const MAX_BUFFER = 1000000000 ; export async function formatSchema ( { schema } ) ; export async function formatSchema ( { schemaPath } ) ; export async function formatSchema ( { schemaPath , schema } ) { if ( ! schema && ! schemaPath ) { throw new Error ( `Parameter schema or schemaPath must be passed.` ) ; } const prismaFmtPath = await resolveBinary ( BinaryType . prismaFmt ) ; const showColors = ! process . env . NO_COLOR && process . stdout . isTTY ; const options = { env : { RUST_BACKTRACE : '1' , ... ( showColors ? { CLICOLOR_FORCE : '1' } : { } ) , } , maxBuffer : MAX_BUFFER , } as execa . Options ; let result ; if ( schemaPath ) { if ( ! fs . existsSync ( schemaPath ) ) { throw new Error ( `Schema at ${ schemaPath } does not exist.` ) ; } result = await execa ( prismaFmtPath , [ 'format' , '-i' , schemaPath ] , options ) ; } else if ( schema ) { result = await execa ( prismaFmtPath , [ 'format' ] , { ... options , input : schema , } ) ; } return result . stdout ; }