import { execSync } from 'child_process' import fs from 'fs' import { execConfig } from '../helpers' export const generateAlternatePath = async () => { try { const mainPrismaSchemaFile = './prisma/schema.prisma' // Clean out the Folder // >>> START <<< const distPrismaSchemaFile = './dist/server/schema.prisma' // Make a copy of the prisma schema file for testing purposes fs.cpSync(mainPrismaSchemaFile, distPrismaSchemaFile) // Add the output to be located in the server folder. // So when the dist is zipped to prod, it has prisma attached. const schemaFileContents = fs.readFileSync(distPrismaSchemaFile).toString() const newContents = schemaFileContents.replace('generator client {', 'generator client {\n output = "./"') fs.writeFileSync(distPrismaSchemaFile, newContents) // So that the index.spec.ts files have a reference of the Prisma Types execSync(`npx prisma generate --schema=${distPrismaSchemaFile}`, execConfig) // >>> END <<< } catch (error) { console.info('Copy Error', error) } }