45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
|
|
#!/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);
|
|||
|
|
}
|
|||
|
|
}
|