Lb1/scripts/dev.mjs

47 lines
1.5 KiB
JavaScript

import { spawn } from 'node:child_process';
import path from 'node:path';
import fs from 'node:fs';
console.log('🚀 Starting Luxe Monorepo Development Environment...');
// Load .env file manually into process.env
const envPath = path.resolve(process.cwd(), '.env');
if (fs.existsSync(envPath)) {
const envConfig = fs.readFileSync(envPath, 'utf8');
envConfig.split(/\r?\n/).forEach((line) => {
// Skip comments and empty lines
if (line.trim().startsWith('#') || !line.includes('=')) return;
const index = line.indexOf('=');
const key = line.substring(0, index).trim();
let val = line.substring(index + 1).trim();
// Unquote value if quoted
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
val = val.substring(1, val.length - 1);
}
// Set environment variable if not already set by system
if (key && !process.env[key]) {
process.env[key] = val;
}
});
console.log('📝 Loaded environment variables from .env');
}
const services = [
{ name: 'Gateway', command: 'npx', args: ['tsx', 'watch', 'services/gateway/src/index.ts'] },
{ name: 'Notifications', command: 'npx', args: ['tsx', 'watch', 'services/notification-service/src/index.ts'] },
];
services.forEach((service) => {
const proc = spawn(service.command, service.args, {
stdio: 'inherit',
shell: true,
env: { ...process.env },
});
proc.on('close', (code) => {
console.log(`[${service.name}] process exited with code ${code}`);
});
});