launchbase 1.0.3 → 1.0.5
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.
package/bin/launchbase.js
CHANGED
|
@@ -6,7 +6,7 @@ const crypto = require('crypto');
|
|
|
6
6
|
const fs = require('fs-extra');
|
|
7
7
|
const { execSync, spawn } = require('child_process');
|
|
8
8
|
|
|
9
|
-
const VERSION = '1.0.
|
|
9
|
+
const VERSION = '1.0.5';
|
|
10
10
|
const program = new Command();
|
|
11
11
|
|
|
12
12
|
function replaceInFile(filePath, replacements) {
|
|
@@ -167,15 +167,88 @@ async function ensureDocker() {
|
|
|
167
167
|
|
|
168
168
|
// Check if Docker daemon is running
|
|
169
169
|
if (!checkDockerRunning()) {
|
|
170
|
-
console.log('\n⚠️ Docker is installed but not running.\n');
|
|
171
|
-
console.log('Please start Docker Desktop and run the command again.\n');
|
|
172
|
-
|
|
173
170
|
const platform = getPlatform();
|
|
174
|
-
if (platform === 'win32' || platform === 'darwin') {
|
|
175
|
-
console.log('💡 Tip: Open Docker Desktop from your applications.\n');
|
|
176
|
-
}
|
|
177
171
|
|
|
178
|
-
|
|
172
|
+
console.log('\n⚠️ Docker is installed but not running.');
|
|
173
|
+
|
|
174
|
+
// Try to start Docker Desktop automatically on Windows/macOS
|
|
175
|
+
if (platform === 'win32') {
|
|
176
|
+
console.log('🔄 Attempting to start Docker Desktop...\n');
|
|
177
|
+
try {
|
|
178
|
+
// Try to start Docker Desktop via PowerShell
|
|
179
|
+
execSync('Start-Process "C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"', {
|
|
180
|
+
shell: 'powershell.exe',
|
|
181
|
+
stdio: 'pipe'
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
console.log('⏳ Waiting for Docker to start');
|
|
185
|
+
|
|
186
|
+
// Wait for Docker to be ready (up to 60 seconds)
|
|
187
|
+
let retries = 60;
|
|
188
|
+
while (retries > 0) {
|
|
189
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
190
|
+
try {
|
|
191
|
+
execSync('docker info', { stdio: 'pipe' });
|
|
192
|
+
console.log('\n✅ Docker is now running!\n');
|
|
193
|
+
return true;
|
|
194
|
+
} catch {
|
|
195
|
+
process.stdout.write('.');
|
|
196
|
+
retries--;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
console.log('\n\n⚠️ Docker did not start in time. Please start Docker Desktop manually.\n');
|
|
201
|
+
process.exit(1);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.log('❌ Could not start Docker Desktop automatically.\n');
|
|
204
|
+
console.log('💡 Please start Docker Desktop from your Start menu and run the command again.\n');
|
|
205
|
+
process.exit(1);
|
|
206
|
+
}
|
|
207
|
+
} else if (platform === 'darwin') {
|
|
208
|
+
console.log('🔄 Attempting to start Docker Desktop...\n');
|
|
209
|
+
try {
|
|
210
|
+
execSync('open -a Docker', { stdio: 'pipe' });
|
|
211
|
+
|
|
212
|
+
console.log('⏳ Waiting for Docker to start');
|
|
213
|
+
|
|
214
|
+
// Wait for Docker to be ready (up to 60 seconds)
|
|
215
|
+
let retries = 60;
|
|
216
|
+
while (retries > 0) {
|
|
217
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
218
|
+
try {
|
|
219
|
+
execSync('docker info', { stdio: 'pipe' });
|
|
220
|
+
console.log('\n✅ Docker is now running!\n');
|
|
221
|
+
return true;
|
|
222
|
+
} catch {
|
|
223
|
+
process.stdout.write('.');
|
|
224
|
+
retries--;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
console.log('\n\n⚠️ Docker did not start in time. Please start Docker Desktop manually.\n');
|
|
229
|
+
process.exit(1);
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.log('❌ Could not start Docker Desktop automatically.\n');
|
|
232
|
+
console.log('💡 Please start Docker Desktop from your Applications and run the command again.\n');
|
|
233
|
+
process.exit(1);
|
|
234
|
+
}
|
|
235
|
+
} else {
|
|
236
|
+
// Linux - try systemctl
|
|
237
|
+
console.log('🔄 Attempting to start Docker daemon...\n');
|
|
238
|
+
try {
|
|
239
|
+
execSync('sudo systemctl start docker', { stdio: 'inherit' });
|
|
240
|
+
|
|
241
|
+
// Wait briefly and check
|
|
242
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
243
|
+
if (checkDockerRunning()) {
|
|
244
|
+
console.log('✅ Docker is now running!\n');
|
|
245
|
+
return true;
|
|
246
|
+
}
|
|
247
|
+
} catch {}
|
|
248
|
+
|
|
249
|
+
console.log('💡 Please start Docker manually and run the command again.\n');
|
|
250
|
+
process.exit(1);
|
|
251
|
+
}
|
|
179
252
|
}
|
|
180
253
|
|
|
181
254
|
return true;
|
|
@@ -208,34 +281,34 @@ async function startDatabase(projectDir) {
|
|
|
208
281
|
}
|
|
209
282
|
|
|
210
283
|
try {
|
|
211
|
-
|
|
284
|
+
// Stop any existing containers first to avoid port conflicts
|
|
285
|
+
try {
|
|
286
|
+
execSync('docker compose down', {
|
|
287
|
+
cwd: projectDir,
|
|
288
|
+
stdio: 'pipe'
|
|
289
|
+
});
|
|
290
|
+
} catch {}
|
|
291
|
+
|
|
292
|
+
execSync('docker compose up -d --wait', {
|
|
212
293
|
cwd: projectDir,
|
|
213
294
|
stdio: 'inherit'
|
|
214
295
|
});
|
|
215
296
|
|
|
216
|
-
console.log('\n
|
|
297
|
+
console.log('\n✅ Database is ready!\n');
|
|
298
|
+
return true;
|
|
299
|
+
} catch (error) {
|
|
300
|
+
console.log('\n❌ Failed to start database.');
|
|
217
301
|
|
|
218
|
-
//
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
console.log('✅ Database is ready!\n');
|
|
227
|
-
return true;
|
|
228
|
-
} catch {
|
|
229
|
-
process.stdout.write('.');
|
|
230
|
-
await new Promise(r => setTimeout(r, 1000));
|
|
231
|
-
retries--;
|
|
232
|
-
}
|
|
302
|
+
// Check for port conflict
|
|
303
|
+
if (error.message && error.message.includes('port is already allocated')) {
|
|
304
|
+
console.log(' Port conflict detected. Another PostgreSQL may be running.\n');
|
|
305
|
+
console.log('💡 Solutions:');
|
|
306
|
+
console.log(' 1. Stop the other PostgreSQL: docker stop <container>');
|
|
307
|
+
console.log(' 2. Or change the port in docker-compose.yml\n');
|
|
308
|
+
} else {
|
|
309
|
+
console.log(' Check Docker logs: docker compose logs\n');
|
|
233
310
|
}
|
|
234
311
|
|
|
235
|
-
console.log('\n⚠️ Database may not be ready yet. Check logs: docker compose logs\n');
|
|
236
|
-
return true;
|
|
237
|
-
} catch (error) {
|
|
238
|
-
console.log('\n❌ Failed to start database. Check Docker logs.\n');
|
|
239
312
|
return false;
|
|
240
313
|
}
|
|
241
314
|
}
|
|
@@ -347,6 +420,7 @@ program
|
|
|
347
420
|
}
|
|
348
421
|
|
|
349
422
|
// Setup Docker and database
|
|
423
|
+
let dbReady = false;
|
|
350
424
|
if (!options.noDocker) {
|
|
351
425
|
console.log('\n🐳 Setting up database...\n');
|
|
352
426
|
|
|
@@ -358,10 +432,15 @@ program
|
|
|
358
432
|
// Run migrations
|
|
359
433
|
console.log('📄 Running database migrations...\n');
|
|
360
434
|
runCommand('npx prisma migrate dev --name init', { cwd: targetDir });
|
|
435
|
+
dbReady = true;
|
|
361
436
|
}
|
|
362
437
|
}
|
|
363
438
|
}
|
|
364
439
|
|
|
440
|
+
// Generate Prisma client before starting dev server
|
|
441
|
+
console.log('📦 Generating Prisma client...\n');
|
|
442
|
+
runCommand('npx prisma generate', { cwd: targetDir });
|
|
443
|
+
|
|
365
444
|
// Start dev server
|
|
366
445
|
console.log('\n🚀 Starting development server...\n');
|
|
367
446
|
console.log('━'.repeat(50));
|
package/package.json
CHANGED
package/template/.env.example
CHANGED
|
@@ -15,7 +15,7 @@ FRONTEND_URL=http://localhost:5173
|
|
|
15
15
|
# Database
|
|
16
16
|
# ===========================================
|
|
17
17
|
# Local PostgreSQL (with Docker)
|
|
18
|
-
DATABASE_URL=postgresql://postgres:postgres@localhost:
|
|
18
|
+
DATABASE_URL=postgresql://postgres:postgres@localhost:5433/__APP_NAME__?schema=public
|
|
19
19
|
# SQLite (for simple local dev)
|
|
20
20
|
# DATABASE_URL="file:./dev.db"
|
|
21
21
|
|
|
@@ -7,9 +7,14 @@ services:
|
|
|
7
7
|
POSTGRES_PASSWORD: postgres
|
|
8
8
|
POSTGRES_DB: launchbase
|
|
9
9
|
ports:
|
|
10
|
-
- "
|
|
10
|
+
- "5433:5432"
|
|
11
11
|
volumes:
|
|
12
12
|
- db_data:/var/lib/postgresql/data
|
|
13
|
+
healthcheck:
|
|
14
|
+
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
15
|
+
interval: 5s
|
|
16
|
+
timeout: 5s
|
|
17
|
+
retries: 5
|
|
13
18
|
|
|
14
19
|
api:
|
|
15
20
|
build: .
|
|
@@ -21,7 +26,8 @@ services:
|
|
|
21
26
|
ports:
|
|
22
27
|
- "3000:3000"
|
|
23
28
|
depends_on:
|
|
24
|
-
|
|
29
|
+
db:
|
|
30
|
+
condition: service_healthy
|
|
25
31
|
|
|
26
32
|
volumes:
|
|
27
33
|
db_data:
|
package/template/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"private": true,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "tsc -p tsconfig.build.json",
|
|
7
|
+
"build": "prisma generate && tsc -p tsconfig.build.json",
|
|
8
8
|
"start": "node dist/src/main.js",
|
|
9
9
|
"start:dev": "ts-node-dev --respawn --transpile-only src/main.ts",
|
|
10
10
|
"prisma:generate": "prisma generate",
|
|
@@ -4,7 +4,7 @@ import LaunchBase from '@launchbasex/sdk'
|
|
|
4
4
|
|
|
5
5
|
@Injectable()
|
|
6
6
|
export class LaunchBaseService implements OnModuleInit {
|
|
7
|
-
private client
|
|
7
|
+
private client!: LaunchBase // Definite assignment assertion - initialized in onModuleInit
|
|
8
8
|
|
|
9
9
|
constructor(private configService: ConfigService) {}
|
|
10
10
|
|