Files
project-fileshare/scripts/prisma-generate.js
2026-10-29 13:21:30 +06:00

45 lines
1.5 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const rootDir = path.resolve(__dirname, '..');
const backendDir = path.join(rootDir, 'apps', 'backend');
const dotPrismaClientPath = path.join(rootDir, 'node_modules', '.prisma', 'client', 'index.d.ts');
try {
const npxCmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
execSync(`${npxCmd} prisma generate`, {
cwd: backendDir,
stdio: 'inherit',
shell: true,
});
} catch (err) {
// Check if client is already generated
let isClientValid = false;
if (fs.existsSync(dotPrismaClientPath)) {
try {
const content = fs.readFileSync(dotPrismaClientPath, 'utf8');
if (content.includes('Model User') && content.includes('Model FileAsset')) {
isClientValid = true;
}
} catch {
// ignore
}
}
if (isClientValid) {
console.warn('\n⚠️ [Prisma Generator] A running Node.js process is currently holding the Prisma query engine DLL.');
console.warn(' Existing generated Prisma Client is valid and intact. Proceeding safely.\n');
process.exit(0);
} else {
console.error('\n❌ [Prisma Generator Error] Failed to generate Prisma Client:', err.message);
if (process.platform === 'win32') {
console.error(' Hint: A running Node process may have locked the query engine DLL.');
console.error(' Run "npm run stop" or close active server windows, then rebuild.\n');
}
process.exit(1);
}
}