This commit is contained in:
2026-10-29 13:21:30 +06:00
parent 2ae9f84ddf
commit 3acc0de8de
132 changed files with 35007 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
#!/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);
}
}

85
scripts/start-all.js Normal file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/env node
const { spawn, execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
console.log('\n======================================================================');
console.log(' 🚀 Secure Video & File Sharing Management System');
console.log(` 💻 Operating System: ${process.platform} (${process.arch})`);
console.log('======================================================================\n');
const rootDir = path.resolve(__dirname, '..');
// 1. Ensure storage directory exists with cross-platform permissions
const storageDir = path.join(rootDir, 'storage');
if (!fs.existsSync(storageDir)) {
console.log(`📁 [1/3] Creating storage volume at: ${storageDir}`);
fs.mkdirSync(storageDir, { recursive: true, mode: 0o755 });
} else {
console.log(`📁 [1/3] Storage directory ready: ${storageDir}`);
}
// 2. Generate Prisma Client & Build Shared Package
console.log('⚡ [2/3] Generating Prisma Database Client & Shared Types...');
try {
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
execSync(`${npmCmd} run prisma:generate --workspace=apps/backend`, {
stdio: 'inherit',
cwd: rootDir,
shell: true,
});
execSync(`${npmCmd} run build --workspace=@fileshare/shared`, {
stdio: 'inherit',
cwd: rootDir,
shell: true,
});
} catch (err) {
console.warn('⚠️ Warning: Prisma/Shared setup warning (proceeding):', err.message);
}
// 3. Determine dev vs prod mode
const isDev = process.argv.includes('--dev');
console.log(`\n🌟 [3/3] Starting Full-Stack Services (${isDev ? 'Development Watch Mode' : 'Production Mode'})...`);
console.log('----------------------------------------------------------------------');
console.log(' 🌐 Frontend Portal: http://localhost:3000');
console.log(' 📚 Swagger API Docs: http://localhost:4000/api/docs');
console.log(' 🔌 REST API Base: http://localhost:4000/api/v1');
console.log('----------------------------------------------------------------------\n');
const frontendCmd = isDev
? 'npm run dev --workspace=apps/frontend'
: 'npm run start --workspace=apps/frontend';
// If in production mode, backend runs from apps/backend directory
const fullBackendCmd = isDev
? 'npm run start:dev --workspace=apps/backend'
: 'npm run start:prod --workspace=apps/backend';
const concurrentlyBin = process.platform === 'win32' ? 'npx.cmd' : 'npx';
const args = [
'concurrently',
'--kill-others',
'--prefix-colors', 'cyan,magenta',
'--names', 'BACKEND,FRONTEND',
`"${fullBackendCmd}"`,
`"${frontendCmd}"`,
];
const child = spawn(concurrentlyBin, args, {
stdio: 'inherit',
cwd: rootDir,
shell: true,
});
child.on('exit', (code) => {
process.exit(code || 0);
});
// Forward interrupt signals
process.on('SIGINT', () => {
child.kill('SIGINT');
});
process.on('SIGTERM', () => {
child.kill('SIGTERM');
});

35
scripts/stop-servers.js Normal file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
console.log('🛑 Stopping FileShare background servers on ports 3000 and 4000...');
const ports = [3000, 4000];
const isWindows = process.platform === 'win32';
ports.forEach((port) => {
try {
if (isWindows) {
const output = execSync(`netstat -ano | findstr LISTENING | findstr :${port}`, { encoding: 'utf8' }).trim();
const lines = output.split('\n');
lines.forEach((line) => {
const parts = line.trim().split(/\s+/);
const pid = parts[parts.length - 1];
if (pid && !isNaN(parseInt(pid))) {
console.log(`Killing process on port ${port} (PID: ${pid})...`);
try {
execSync(`taskkill /F /PID ${pid}`, { stdio: 'ignore' });
} catch {
// Already exited
}
}
});
} else {
execSync(`fuser -k ${port}/tcp || true`, { stdio: 'ignore' });
}
} catch {
// Port not open
}
});
console.log('✅ Ports 3000 and 4000 are now clear.');