|
| 1 | +#!/usr/bin/env bun |
| 2 | +// Ultra-fast clapp-based router - uses clapp APIs for all commands |
| 3 | +import { cli } from '@stacksjs/clapp' |
| 4 | +import { dim, gray } from '@stacksjs/cli' |
| 5 | + |
| 6 | +const args = process.argv.slice(2) |
| 7 | +const command = args[0] || '' |
| 8 | +const startTime = performance.now() |
| 9 | + |
| 10 | +// Helper to show execution time |
| 11 | +function showExecutionTime() { |
| 12 | + const elapsed = performance.now() - startTime |
| 13 | + const timeMs = Math.round(elapsed) |
| 14 | + |
| 15 | + // Only show for commands that take >100ms (skip instant ones) |
| 16 | + if (timeMs > 100) { |
| 17 | + console.log(dim(gray(`\n⏱ Execution time: ${timeMs}ms`))) |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +// Create lightweight clapp instance |
| 22 | +const buddy = cli('buddy') |
| 23 | + |
| 24 | +// Add version |
| 25 | +const pkg = require('./package.json') |
| 26 | +buddy.version(pkg.version) |
| 27 | + |
| 28 | +// Fast path commands - register with minimal overhead |
| 29 | +buddy |
| 30 | + .command('dev', 'Start development server (ultra-fast)') |
| 31 | + .alias('serve') |
| 32 | + .example('buddy dev') |
| 33 | + .example('buddy serve') |
| 34 | + .action(async () => { |
| 35 | + const { serve } = await import('bun-plugin-stx/serve') |
| 36 | + console.log('🚀 Starting STX development server on http://localhost:3456\n') |
| 37 | + await serve({ |
| 38 | + patterns: ['resources/views'], |
| 39 | + port: 3456, |
| 40 | + }) |
| 41 | + }) |
| 42 | + |
| 43 | +buddy |
| 44 | + .command('build', 'Bundle your project for production') |
| 45 | + .example('buddy build') |
| 46 | + .action(async () => { |
| 47 | + const { build } = await import('./storage/framework/core/actions/src/build') |
| 48 | + await build({}) |
| 49 | + showExecutionTime() |
| 50 | + }) |
| 51 | + |
| 52 | +buddy |
| 53 | + .command('test [filter]', 'Run your test suite') |
| 54 | + .alias('t') |
| 55 | + .example('buddy test') |
| 56 | + .example('buddy test --filter=unit') |
| 57 | + .action(async () => { |
| 58 | + const { runAction } = await import('@stacksjs/actions') |
| 59 | + await runAction('test') |
| 60 | + showExecutionTime() |
| 61 | + }) |
| 62 | + |
| 63 | +buddy |
| 64 | + .command('lint', 'Lint and format your code') |
| 65 | + .example('buddy lint') |
| 66 | + .example('buddy lint --fix') |
| 67 | + .action(async () => { |
| 68 | + const { runAction } = await import('@stacksjs/actions') |
| 69 | + await runAction('lint') |
| 70 | + showExecutionTime() |
| 71 | + }) |
| 72 | + |
| 73 | +// For all other commands, lazy load the full CLI |
| 74 | +const fastCommands = ['version', 'dev', 'serve', 'build', 'test', 't', 'lint', '-v', '--version', '-h', '--help', 'help'] |
| 75 | +if (command && !fastCommands.includes(command)) { |
| 76 | + // Load full CLI for other commands |
| 77 | + await import('./storage/framework/core/buddy/src/cli') |
| 78 | + showExecutionTime() |
| 79 | +} else { |
| 80 | + // Use lightweight clapp for fast commands |
| 81 | + buddy.help() |
| 82 | + await buddy.parse() |
| 83 | +} |
0 commit comments