1+ import type { ChildProcess } from 'node:child_process'
12import fs from 'node:fs/promises'
23import path from 'node:path'
3- import type { ChildProcess } from 'node:child_process'
44
5+ import { formatSchema , getGenerators } from '@prisma/internals'
56import { printSchema } from 'graphql'
6- import { getGenerators , formatSchema } from '@prisma/internals'
7- import { ExitError } from './scripts/utils'
8- import { initialiseLists } from './lib/core/initialise-lists'
9- import { type System , getSystemPaths } from './lib/createSystem'
107import { printPrismaSchema } from './lib/core/prisma-schema-printer'
8+ import type { System } from './lib/system'
119import { printGeneratedTypes } from './lib/typescript-schema-printer'
1210
1311export function getFormattedGraphQLSchema ( schema : string ) {
@@ -30,32 +28,29 @@ async function readFileOrUndefined(path: string) {
3028
3129export async function validateArtifacts ( cwd : string , system : System ) {
3230 const paths = system . getPaths ( cwd )
33- const artifacts = await getArtifacts ( system )
31+ const artifacts = await buildArtifacts ( system )
3432 const [ writtenGraphQLSchema , writtenPrismaSchema ] = await Promise . all ( [
3533 readFileOrUndefined ( paths . schema . graphql ) ,
3634 readFileOrUndefined ( paths . schema . prisma ) ,
3735 ] )
3836
3937 if ( writtenGraphQLSchema !== artifacts . graphql && writtenPrismaSchema !== artifacts . prisma ) {
40- console . error ( 'Your Prisma and GraphQL schemas are not up to date' )
41- throw new ExitError ( 1 )
38+ throw new Error ( 'Your Prisma and GraphQL schemas are not up to date' )
4239 }
4340
4441 if ( writtenGraphQLSchema !== artifacts . graphql ) {
45- console . error ( 'Your GraphQL schema is not up to date' )
46- throw new ExitError ( 1 )
42+ throw new Error ( 'Your GraphQL schema is not up to date' )
4743 }
4844
4945 if ( writtenPrismaSchema !== artifacts . prisma ) {
50- console . error ( 'Your Prisma schema is not up to date' )
51- throw new ExitError ( 1 )
46+ throw new Error ( 'Your Prisma schema is not up to date' )
5247 }
5348}
5449
55- export async function getArtifacts ( system : System ) {
56- const lists = initialiseLists ( system . config )
50+ // exported for tests
51+ export async function buildArtifacts ( system : System ) {
5752 const prismaSchema = await formatSchema ( {
58- schemas : [ [ system . config . db . prismaSchemaPath , printPrismaSchema ( system . config , lists ) ] ] ,
53+ schemas : [ [ system . config . db . prismaSchemaPath , printPrismaSchema ( system . config , system . lists ) ] ] ,
5954 } )
6055
6156 return {
@@ -65,15 +60,15 @@ export async function getArtifacts(system: System) {
6560}
6661
6762export async function generateArtifacts ( cwd : string , system : System ) {
68- const paths = getSystemPaths ( cwd , system . config )
69- const artifacts = await getArtifacts ( system )
63+ const paths = system . getPaths ( cwd )
64+ const artifacts = await buildArtifacts ( system )
7065 await fs . writeFile ( paths . schema . graphql , artifacts . graphql )
7166 await fs . writeFile ( paths . schema . prisma , artifacts . prisma )
7267 return artifacts
7368}
7469
7570export async function generateTypes ( cwd : string , system : System ) {
76- const paths = getSystemPaths ( cwd , system . config )
71+ const paths = system . getPaths ( cwd )
7772 const schema = printGeneratedTypes (
7873 paths . types . relativePrismaPath ,
7974 system . graphQLSchemaSudo ,
@@ -84,7 +79,7 @@ export async function generateTypes(cwd: string, system: System) {
8479}
8580
8681export async function generatePrismaClient ( cwd : string , system : System ) {
87- const paths = getSystemPaths ( cwd , system . config )
82+ const paths = system . getPaths ( cwd )
8883 const generators = await getGenerators ( {
8984 schemaPath : paths . schema . prisma ,
9085 } )
0 commit comments