86 lines
2.8 KiB
JavaScript
86 lines
2.8 KiB
JavaScript
#!/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');
|
|
});
|