@augment-vir/node
Version:
A collection of augments, helpers types, functions, and classes only for Node.js (backend) JavaScript environments.
25 lines (24 loc) • 1.23 kB
JavaScript
import { collapseWhiteSpace } from '@augment-vir/common';
import { existsSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { runPrismaCommand } from './run-prisma-command.js';
export async function generatePrismaClient(schemaFilePath, env = {}) {
await runPrismaCommand({ command: 'generate' }, schemaFilePath, env);
}
async function areSchemasEqual(originalSchema, generatedClientSchema) {
if (!existsSync(originalSchema)) {
throw new Error(`Schema file does not exist: '${originalSchema}'`);
}
else if (!existsSync(generatedClientSchema)) {
return false;
}
const originalSchemaContents = String(await readFile(originalSchema));
const generatedClientSchemaContents = String(await readFile(generatedClientSchema));
return (collapseWhiteSpace(originalSchemaContents, { keepNewLines: true }) ===
collapseWhiteSpace(generatedClientSchemaContents, { keepNewLines: true }));
}
export async function isGeneratedPrismaClientCurrent({ jsClientOutputDir, schemaFilePath, }) {
const clientSchemaFilePath = join(jsClientOutputDir, 'schema.prisma');
return areSchemasEqual(schemaFilePath, clientSchemaFilePath);
}