|
1 | 1 | #!/usr/bin/env bun
|
2 |
| -import fs from 'node:fs' |
3 | 2 | import path from 'node:path'
|
4 | 3 | import process from 'node:process'
|
5 | 4 | import { CAC } from 'cac'
|
6 | 5 | import { resolveCommand } from '../src/commands'
|
7 | 6 | import { config } from '../src/config'
|
8 |
| -// Avoid importing the dev barrel here to prevent parsing heavy modules at startup |
9 |
| -// doctor helpers no longer needed here; delegated via modular command |
10 |
| -// import { formatDoctorReport, runDoctorChecks } from '../src/doctor' |
11 |
| -// info helpers no longer needed here; delegated via modular command |
12 |
| -// import { formatPackageInfo, formatPackageNotFound, getDetailedPackageInfo, packageExists } from '../src/info' |
13 |
| -// search helpers no longer needed here; delegated via modular command |
14 |
| -// import { formatSearchResults, getPopularPackages, searchPackages } from '../src/search' |
15 |
| -// shim helpers no longer needed here; delegated via modular command |
16 |
| -// import { create_shim, shim_dir } from '../src/shim' |
17 |
| -// tags helpers no longer needed here; delegated via modular command |
18 |
| -// import { formatCategoriesList, formatPackagesByCategory, formatTagSearchResults, getAvailableCategories, getPackagesByCategory, searchPackagesByTag } from '../src/tags' |
| 7 | + |
19 | 8 | process.env.LAUNCHPAD_CLI_MODE = '1'
|
20 | 9 | // Import package.json for version
|
21 | 10 | const packageJson = await import('../package.json')
|
|
345 | 334 | const argv: string[] = []
|
346 | 335 | if (options?.verbose)
|
347 | 336 | argv.push('--verbose')
|
348 |
| - if (options?.path) { argv.push('--path', options.path) } |
| 337 | + if (options?.path) |
| 338 | + argv.push('--path', options.path) |
349 | 339 | if (options?.force)
|
350 | 340 | argv.push('--force')
|
351 | 341 | if (options?.autoPath === false)
|
|
385 | 375 | argv.push('--force')
|
386 | 376 | if (options?.verbose)
|
387 | 377 | argv.push('--verbose')
|
388 |
| - if (options?.release) { argv.push('--release', options.release) } |
389 |
| - if (options?.target) { argv.push('--target', options.target) } |
| 378 | + if (options?.release) |
| 379 | + argv.push('--release', options.release) |
| 380 | + if (options?.target) |
| 381 | + argv.push('--target', options.target) |
390 | 382 | const cmd = await resolveCommand('setup')
|
391 | 383 | if (!cmd)
|
392 | 384 | return
|
|
449 | 441 | argv.push('--force')
|
450 | 442 | if (options?.verbose)
|
451 | 443 | argv.push('--verbose')
|
452 |
| - if (options?.target) { argv.push('--target', options.target) } |
453 |
| - if (options?.release) { argv.push('--release', options.release) } |
| 444 | + if (options?.target) |
| 445 | + argv.push('--target', options.target) |
| 446 | + if (options?.release) |
| 447 | + argv.push('--release', options.release) |
454 | 448 | if (options?.dryRun)
|
455 | 449 | argv.push('--dry-run')
|
456 | 450 | const cmd = await resolveCommand('upgrade')
|
@@ -552,12 +546,15 @@ cli
|
552 | 546 | .option('--test-mode', 'Generate shellcode for testing (bypasses test environment checks)')
|
553 | 547 | .action(async ({ testMode }) => {
|
554 | 548 | try {
|
555 |
| - // Use computed dynamic import to prevent Bun from pre-parsing this module at CLI startup |
556 |
| - const mod = await import('../src/dev/' + 'shellcode') |
557 |
| - const { shellcode } = mod as { shellcode: (testMode?: boolean) => string } |
558 |
| - console.log(shellcode(testMode)) |
559 |
| - // Force immediate exit to prevent any hanging |
560 |
| - process.exit(0) |
| 549 | + const argv: string[] = [] |
| 550 | + if (testMode) |
| 551 | + argv.push('--test-mode') |
| 552 | + const cmd = await resolveCommand('dev:shellcode') |
| 553 | + if (!cmd) |
| 554 | + return |
| 555 | + const code = await cmd.run({ argv, env: process.env }) |
| 556 | + if (typeof code === 'number' && code !== 0) |
| 557 | + process.exit(code) |
561 | 558 | }
|
562 | 559 | catch (error) {
|
563 | 560 | console.error('Failed to generate shellcode:', error instanceof Error ? error.message : String(error))
|
@@ -1380,20 +1377,21 @@ cli
|
1380 | 1377 | json?: boolean
|
1381 | 1378 | }) => {
|
1382 | 1379 | try {
|
1383 |
| - const { runFileDetectionBenchmark } = await import('../src/dev/benchmark') |
1384 |
| - |
1385 |
| - const depths = options?.depths && typeof options.depths === 'string' |
1386 |
| - ? options.depths.split(',').map(d => Number.parseInt(d.trim(), 10)).filter(d => !Number.isNaN(d)) |
1387 |
| - : [3, 7, 15, 25] |
1388 |
| - |
1389 |
| - const iterations = options?.iterations ? Number.parseInt(options.iterations, 10) : undefined |
1390 |
| - |
1391 |
| - await runFileDetectionBenchmark({ |
1392 |
| - depths, |
1393 |
| - iterations, |
1394 |
| - verbose: options?.verbose || false, |
1395 |
| - json: options?.json || false, |
1396 |
| - }) |
| 1380 | + const argv: string[] = [] |
| 1381 | + if (options?.iterations) |
| 1382 | + argv.push('--iterations', String(options.iterations)) |
| 1383 | + if (options?.depths) |
| 1384 | + argv.push('--depths', options.depths) |
| 1385 | + if (options?.verbose) |
| 1386 | + argv.push('--verbose') |
| 1387 | + if (options?.json) |
| 1388 | + argv.push('--json') |
| 1389 | + const cmd = await resolveCommand('benchmark:file-detection') |
| 1390 | + if (!cmd) |
| 1391 | + return |
| 1392 | + const code = await cmd.run({ argv, env: process.env }) |
| 1393 | + if (typeof code === 'number' && code !== 0) |
| 1394 | + process.exit(code) |
1397 | 1395 | }
|
1398 | 1396 | catch (error) {
|
1399 | 1397 | console.error('Benchmark failed:', error instanceof Error ? error.message : String(error))
|
@@ -1433,40 +1431,25 @@ cli
|
1433 | 1431 | password?: string
|
1434 | 1432 | }) => {
|
1435 | 1433 | try {
|
1436 |
| - const { createProjectDatabase, generateLaravelConfig } = await import('../src/services/database') |
1437 |
| - const dbName = options.name || path.basename(process.cwd()).replace(/\W/g, '_') |
1438 |
| - |
1439 |
| - const dbOptions = { |
1440 |
| - host: options.host, |
1441 |
| - port: options.port ? Number.parseInt(options.port, 10) : undefined, |
1442 |
| - user: options.user, |
1443 |
| - password: options.password, |
1444 |
| - type: options.type === 'auto' ? undefined : options.type as any, |
1445 |
| - } |
1446 |
| - |
1447 |
| - const connectionInfo = await createProjectDatabase(dbName, dbOptions) |
1448 |
| - |
1449 |
| - console.warn('\n📋 Database Connection Details:') |
1450 |
| - console.warn(` Type: ${connectionInfo.type}`) |
1451 |
| - if (connectionInfo.host) |
1452 |
| - console.warn(` Host: ${connectionInfo.host}`) |
1453 |
| - if (connectionInfo.port) |
1454 |
| - console.warn(` Port: ${connectionInfo.port}`) |
1455 |
| - console.warn(` Database: ${connectionInfo.database}`) |
1456 |
| - if (connectionInfo.username) |
1457 |
| - console.warn(` Username: ${connectionInfo.username}`) |
1458 |
| - if (connectionInfo.path) |
1459 |
| - console.warn(` Path: ${connectionInfo.path}`) |
1460 |
| - |
1461 |
| - // Generate Laravel .env configuration |
1462 |
| - const envConfig = generateLaravelConfig(connectionInfo) |
1463 |
| - console.warn('\n🔧 Laravel .env configuration:') |
1464 |
| - console.warn(envConfig) |
1465 |
| - |
1466 |
| - // Check if this is a Laravel project and offer to update .env |
1467 |
| - if (fs.existsSync('artisan') && fs.existsSync('.env')) { |
1468 |
| - console.warn('\n💡 Laravel project detected! You can update your .env file with the configuration above.') |
1469 |
| - } |
| 1434 | + const argv: string[] = [] |
| 1435 | + if (options?.name) |
| 1436 | + argv.push('--name', options.name) |
| 1437 | + if (options?.type) |
| 1438 | + argv.push('--type', options.type) |
| 1439 | + if (options?.host) |
| 1440 | + argv.push('--host', options.host) |
| 1441 | + if (options?.port) |
| 1442 | + argv.push('--port', String(options.port)) |
| 1443 | + if (options?.user) |
| 1444 | + argv.push('--user', options.user) |
| 1445 | + if (options?.password) |
| 1446 | + argv.push('--password', options.password) |
| 1447 | + const cmd = await resolveCommand('db:create') |
| 1448 | + if (!cmd) |
| 1449 | + return |
| 1450 | + const code = await cmd.run({ argv, env: process.env }) |
| 1451 | + if (typeof code === 'number' && code !== 0) |
| 1452 | + process.exit(code) |
1470 | 1453 | }
|
1471 | 1454 | catch (error) {
|
1472 | 1455 | console.error(`Failed to create database: ${error instanceof Error ? error.message : String(error)}`)
|
|
0 commit comments