124 lines
4.2 KiB
JavaScript
124 lines
4.2 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
const { spawn, exec } = require("child_process");
|
|
const os = require('os');
|
|
const isWindows = process.platform === 'win32';
|
|
|
|
console.log('🚀 Starting minimal development environment...');
|
|
|
|
// Detect architecture
|
|
const arch = os.arch();
|
|
const isAppleSilicon = arch === 'arm64' && process.platform === 'darwin';
|
|
|
|
console.log(`🖥️ Detected architecture: ${arch}`);
|
|
console.log(`🍎 Apple Silicon: ${isAppleSilicon ? 'Yes' : 'No'}`);
|
|
|
|
// Use minimal compose file (only PostgreSQL and Redis)
|
|
const composeFile = "docker-compose.dev.minimal.yml";
|
|
console.log(`📦 Using minimal Docker Compose file: ${composeFile}`);
|
|
|
|
function runCommand(command, env) {
|
|
return new Promise((resolve, reject) => {
|
|
exec(command, { env: env ?? process.env }, (error, stdout, stderr) => {
|
|
if (stdout) process.stdout.write(stdout);
|
|
if (stderr) process.stderr.write(stderr);
|
|
if (error) {
|
|
reject(error);
|
|
return;
|
|
}
|
|
resolve(undefined);
|
|
});
|
|
});
|
|
}
|
|
|
|
// Check if docker-compose is available
|
|
exec('docker-compose --version', (error) => {
|
|
if (error) {
|
|
console.error('❌ docker-compose not found');
|
|
console.error('💡 Please install Docker Desktop or use: npm run dev:simple');
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('✅ docker-compose found, starting services...');
|
|
|
|
// Start Docker services
|
|
const dockerProcess = spawn('docker-compose', ['-f', composeFile, 'up', '-d'], {
|
|
stdio: 'inherit',
|
|
shell: isWindows
|
|
});
|
|
|
|
dockerProcess.on('close', (code) => {
|
|
if (code === 0) {
|
|
console.log('✅ Docker services started');
|
|
console.log('🗄️ PostgreSQL: localhost:5432');
|
|
console.log('📦 Redis: localhost:6379');
|
|
console.log('📧 Note: Mailhog not included (use npm run dev:simple for email testing)');
|
|
|
|
// Wait a bit for services to be ready
|
|
setTimeout(() => {
|
|
const devEnv = {
|
|
...process.env,
|
|
DATABASE_URL:
|
|
process.env.DATABASE_URL ||
|
|
"postgresql://portfolio_user:portfolio_dev_pass@localhost:5432/portfolio_dev?schema=public",
|
|
REDIS_URL: "redis://localhost:6379",
|
|
NODE_ENV: "development",
|
|
};
|
|
|
|
// Ensure DB schema exists before starting Next dev server.
|
|
// This prevents "table does not exist" errors for Projects/CMS/Analytics.
|
|
(async () => {
|
|
try {
|
|
console.log("🗄️ Applying Prisma migrations (dev)...");
|
|
await runCommand("npx prisma generate", devEnv);
|
|
await runCommand("npx prisma migrate deploy", devEnv);
|
|
// seeding is optional; keep it non-blocking
|
|
await runCommand("npx prisma db seed", devEnv).catch(() => {});
|
|
console.log("✅ Database is ready");
|
|
} catch (_e) {
|
|
console.warn("⚠️ Could not run Prisma migrations automatically.");
|
|
console.warn(" You can run: npm run db:setup");
|
|
}
|
|
|
|
console.log("🚀 Starting Next.js development server...");
|
|
|
|
// Start Next.js dev server
|
|
const nextProcess = spawn("npm", ["run", "dev:next"], {
|
|
stdio: "inherit",
|
|
shell: isWindows,
|
|
env: devEnv,
|
|
});
|
|
|
|
nextProcess.on("close", (code) => {
|
|
console.log(`Next.js dev server exited with code ${code}`);
|
|
});
|
|
|
|
// Handle process signals
|
|
process.on("SIGINT", () => {
|
|
console.log("\n🛑 Stopping development environment...");
|
|
nextProcess.kill("SIGTERM");
|
|
|
|
// Stop Docker services
|
|
const stopProcess = spawn("docker-compose", ["-f", composeFile, "down"], {
|
|
stdio: "inherit",
|
|
shell: isWindows,
|
|
});
|
|
|
|
stopProcess.on("close", () => {
|
|
console.log("✅ Development environment stopped");
|
|
process.exit(0);
|
|
});
|
|
});
|
|
})();
|
|
|
|
}, 5000); // Wait 5 seconds for services to be ready
|
|
|
|
} else {
|
|
console.error('❌ Failed to start Docker services');
|
|
console.error('💡 Try using: npm run dev:simple');
|
|
process.exit(1);
|
|
}
|
|
});
|
|
});
|