launchbase 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/launchbase.js +43 -26
  2. package/package.json +1 -1
package/bin/launchbase.js CHANGED
@@ -7,7 +7,7 @@ const crypto = require('crypto');
7
7
  const fs = require('fs-extra');
8
8
  const { execSync, spawn } = require('child_process');
9
9
 
10
- const VERSION = '1.0.6';
10
+ const VERSION = '1.0.8';
11
11
  const program = new Command();
12
12
 
13
13
  function findAvailablePort(startPort = 5432, maxAttempts = 100) {
@@ -296,32 +296,34 @@ async function startDatabase(projectDir) {
296
296
 
297
297
  console.log('🐳 Starting database with Docker Compose...\n');
298
298
 
299
- try {
300
- // Check if containers are already running
301
- const psOutput = execSync('docker compose ps -q', {
302
- cwd: projectDir,
303
- stdio: 'pipe',
304
- encoding: 'utf8'
305
- }).trim();
306
-
307
- if (psOutput) {
308
- console.log('āœ… Database containers already running\n');
309
- return true;
310
- }
311
- } catch {
312
- // Containers not running, proceed to start
313
- }
299
+ // Get project name from directory
300
+ const projectName = path.basename(projectDir);
314
301
 
315
302
  try {
316
- // Stop any existing containers first to avoid port conflicts
303
+ // First, stop any containers with this project name (from previous runs)
317
304
  try {
318
- execSync('docker compose down', {
305
+ execSync(`docker compose -p ${projectName} down --remove-orphans`, {
319
306
  cwd: projectDir,
320
307
  stdio: 'pipe'
321
308
  });
322
309
  } catch {}
323
310
 
324
- execSync('docker compose up -d --wait', {
311
+ // Also try to remove any containers with similar names
312
+ try {
313
+ const containers = execSync('docker ps -a --format "{{.Names}}"', {
314
+ stdio: 'pipe',
315
+ encoding: 'utf8'
316
+ });
317
+ const containerList = containers.trim().split('\n').filter(c => c.includes(projectName));
318
+ for (const container of containerList) {
319
+ try {
320
+ execSync(`docker rm -f ${container}`, { stdio: 'pipe' });
321
+ } catch {}
322
+ }
323
+ } catch {}
324
+
325
+ // Start fresh containers with explicit project name
326
+ execSync(`docker compose -p ${projectName} up -d --wait --force-recreate`, {
325
327
  cwd: projectDir,
326
328
  stdio: 'inherit'
327
329
  });
@@ -333,10 +335,10 @@ async function startDatabase(projectDir) {
333
335
 
334
336
  // Check for port conflict
335
337
  if (error.message && error.message.includes('port is already allocated')) {
336
- console.log(' Port conflict detected. Another PostgreSQL may be running.\n');
337
- console.log('šŸ’” Solutions:');
338
- console.log(' 1. Stop the other PostgreSQL: docker stop <container>');
339
- console.log(' 2. Or change the port in docker-compose.yml\n');
338
+ console.log(' Port conflict detected. Another service is using this port.\n');
339
+ console.log('šŸ’” Try stopping other databases:');
340
+ console.log(' docker ps # list running containers');
341
+ console.log(' docker stop <container_id> # stop the conflicting container\n');
340
342
  } else {
341
343
  console.log(' Check Docker logs: docker compose logs\n');
342
344
  }
@@ -470,11 +472,17 @@ program
470
472
  console.log('šŸ“¦ Installing dependencies...\n');
471
473
  runCommand('npm install', { cwd: targetDir });
472
474
 
475
+ // Install frontend dependencies if template was requested
473
476
  if (options.template) {
474
477
  const frontendPath = path.join(targetDir, 'frontend');
478
+ console.log(` Checking frontend path: ${frontendPath}`);
479
+ console.log(` Frontend exists: ${await fs.pathExists(frontendPath)}`);
480
+
475
481
  if (await fs.pathExists(frontendPath)) {
476
482
  console.log('\nšŸ“¦ Installing frontend dependencies...\n');
477
483
  runCommand('npm install', { cwd: frontendPath });
484
+ } else {
485
+ console.log(' āš ļø Frontend folder not found. Template may not have been copied.\n');
478
486
  }
479
487
  }
480
488
 
@@ -488,9 +496,18 @@ program
488
496
  // Wait a moment for DB to be fully ready
489
497
  await new Promise(r => setTimeout(r, 2000));
490
498
 
491
- // Run migrations
492
- console.log('šŸ“„ Running database migrations...\n');
493
- runCommand('npx prisma migrate dev --name init', { cwd: targetDir });
499
+ // Run migrations - use reset for fresh projects to avoid drift
500
+ console.log('šŸ“„ Setting up database schema...\n');
501
+ try {
502
+ // Try reset first (for fresh DB or when there's drift)
503
+ execSync('npx prisma migrate reset --force', {
504
+ cwd: targetDir,
505
+ stdio: 'inherit'
506
+ });
507
+ } catch {
508
+ // If reset fails, try regular migrate
509
+ runCommand('npx prisma migrate dev --name init', { cwd: targetDir });
510
+ }
494
511
  dbReady = true;
495
512
  }
496
513
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "launchbase",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Generate production-ready NestJS backends with authentication, multi-tenancy, billing, and deployment in minutes",
5
5
  "author": "LaunchBase",
6
6
  "keywords": [