-
Notifications
You must be signed in to change notification settings - Fork 2
feat: single binary using bun #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/env tsx | ||
|
|
||
| /** | ||
| * Build standalone binaries for all supported platforms using `bun build --compile`. | ||
| * | ||
| * Usage: | ||
| * npx tsx scripts/build-binaries.ts # build all targets | ||
| * npx tsx scripts/build-binaries.ts linux-x64 # build one target | ||
| */ | ||
|
|
||
| import { execSync } from 'child_process'; | ||
| import { mkdirSync } from 'fs'; | ||
| import { join } from 'path'; | ||
|
|
||
| const ENTRY = 'src/cli-binary.ts'; | ||
| const OUT_DIR = join(process.cwd(), 'bin'); | ||
|
|
||
| const targets: Record<string, { bunTarget: string; outName: string }> = { | ||
| 'darwin-arm64': { | ||
| bunTarget: 'bun-darwin-arm64', | ||
| outName: 'tigris-darwin-arm64', | ||
| }, | ||
| 'darwin-x64': { | ||
| bunTarget: 'bun-darwin-x64', | ||
| outName: 'tigris-darwin-x64', | ||
| }, | ||
| 'linux-x64': { | ||
| bunTarget: 'bun-linux-x64', | ||
| outName: 'tigris-linux-x64', | ||
| }, | ||
| 'linux-arm64': { | ||
| bunTarget: 'bun-linux-arm64', | ||
| outName: 'tigris-linux-arm64', | ||
| }, | ||
| 'windows-x64': { | ||
| bunTarget: 'bun-windows-x64', | ||
| outName: 'tigris-windows-x64.exe', | ||
| }, | ||
| }; | ||
|
|
||
| // Allow filtering to specific targets via CLI args | ||
| const requestedTargets = process.argv.slice(2); | ||
| const selectedTargets = | ||
| requestedTargets.length > 0 | ||
| ? Object.fromEntries( | ||
| Object.entries(targets).filter(([key]) => | ||
| requestedTargets.includes(key) | ||
| ) | ||
| ) | ||
| : targets; | ||
|
|
||
| if (Object.keys(selectedTargets).length === 0) { | ||
| console.error( | ||
| `No matching targets. Available: ${Object.keys(targets).join(', ')}` | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| mkdirSync(OUT_DIR, { recursive: true }); | ||
|
|
||
| for (const [name, { bunTarget, outName }] of Object.entries(selectedTargets)) { | ||
| const outFile = join(OUT_DIR, outName); | ||
| const cmd = `bun build ${ENTRY} --compile --target=${bunTarget} --outfile=${outFile}`; | ||
| console.log(`\n[${name}] ${cmd}`); | ||
| try { | ||
| execSync(cmd, { stdio: 'inherit' }); | ||
| console.log(`[${name}] ✓ ${outFile}`); | ||
| } catch { | ||
| console.error(`[${name}] ✗ build failed`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| console.log('\nAll builds complete.'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| #!/usr/bin/env tsx | ||
|
|
||
| /** | ||
| * Auto-generate command-registry.ts from specs.yaml. | ||
| * | ||
| * specs.yaml is the single source of truth for command structure. | ||
| * This script generates static imports for commands that have implementations. | ||
| * | ||
| * Run: npm run generate:registry | ||
| */ | ||
|
|
||
| import { readFileSync, existsSync, writeFileSync } from 'fs'; | ||
| import { join } from 'path'; | ||
| import * as YAML from 'yaml'; | ||
|
|
||
| const ROOT = process.cwd(); | ||
| const SPECS_PATH = join(ROOT, 'src/specs.yaml'); | ||
| const OUTPUT_PATH = join(ROOT, 'src/command-registry.ts'); | ||
|
|
||
| interface CommandSpec { | ||
| name: string; | ||
| alias?: string; | ||
| commands?: CommandSpec[]; | ||
| default?: string; | ||
| } | ||
|
|
||
| interface Specs { | ||
| commands: CommandSpec[]; | ||
| } | ||
|
|
||
| interface RegistryEntry { | ||
| key: string; | ||
| importName: string; | ||
| importPath: string; | ||
| } | ||
|
|
||
| /** | ||
| * Convert kebab-case to camelCase | ||
| */ | ||
| function toCamelCase(str: string): string { | ||
| return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()); | ||
| } | ||
|
|
||
| /** | ||
| * Find the implementation file for a command path | ||
| */ | ||
| function findImplementationPath(commandPath: string[]): string | null { | ||
| const basePath = join(ROOT, 'src/lib', ...commandPath); | ||
|
|
||
| // Check for direct file: src/lib/{path}.ts | ||
| const directPath = `${basePath}.ts`; | ||
| if (existsSync(directPath)) { | ||
| return `./lib/${commandPath.join('/')}.js`; | ||
| } | ||
|
|
||
| // Check for index file: src/lib/{path}/index.ts | ||
| const indexPath = join(basePath, 'index.ts'); | ||
| if (existsSync(indexPath)) { | ||
| return `./lib/${commandPath.join('/')}/index.js`; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Generate import name from command path | ||
| * e.g., ["buckets", "list"] -> "bucketsList" | ||
| * e.g., ["iam", "policies", "create"] -> "iamPoliciesCreate" | ||
| */ | ||
| function toImportName(path: string[]): string { | ||
| return path | ||
| .map((part, index) => { | ||
| const camel = toCamelCase(part); | ||
| return index === 0 | ||
| ? camel | ||
| : camel.charAt(0).toUpperCase() + camel.slice(1); | ||
| }) | ||
| .join(''); | ||
| } | ||
|
|
||
| /** | ||
| * Recursively collect all registry entries from the command tree | ||
| */ | ||
| function collectEntries( | ||
| commands: CommandSpec[], | ||
| parentPath: string[] = [] | ||
| ): RegistryEntry[] { | ||
| const entries: RegistryEntry[] = []; | ||
|
|
||
| for (const cmd of commands) { | ||
| const currentPath = [...parentPath, cmd.name]; | ||
|
|
||
| if (cmd.commands && cmd.commands.length > 0) { | ||
| // Has sub-commands - recurse into them | ||
| entries.push(...collectEntries(cmd.commands, currentPath)); | ||
| } else { | ||
| // Leaf command - check if implementation exists | ||
| const implPath = findImplementationPath(currentPath); | ||
| if (implPath) { | ||
| entries.push({ | ||
| key: currentPath.join('/'), | ||
| importName: toImportName(currentPath), | ||
| importPath: implPath, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return entries; | ||
| } | ||
|
|
||
| /** | ||
| * Generate the command-registry.ts file content | ||
| */ | ||
| function generateRegistry(entries: RegistryEntry[]): string { | ||
| const imports = entries | ||
| .map((e) => `import * as ${e.importName} from '${e.importPath}';`) | ||
| .join('\n'); | ||
|
|
||
| const registryEntries = entries | ||
| .map((e) => ` '${e.key}': ${e.importName},`) | ||
| .join('\n'); | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return `// Auto-generated from specs.yaml - DO NOT EDIT | ||
| // Run: npm run generate:registry | ||
|
|
||
| ${imports} | ||
|
|
||
| export const commandRegistry: Record<string, Record<string, unknown>> = { | ||
| ${registryEntries} | ||
| }; | ||
| `; | ||
| } | ||
|
|
||
| // Main | ||
| const specsContent = readFileSync(SPECS_PATH, 'utf8'); | ||
| const specs: Specs = YAML.parse(specsContent, { schema: 'core' }); | ||
|
|
||
| const entries = collectEntries(specs.commands); | ||
|
|
||
| console.log(`Found ${entries.length} command implementations:`); | ||
| entries.forEach((e) => console.log(` ${e.key}`)); | ||
|
|
||
| const output = generateRegistry(entries); | ||
| writeFileSync(OUTPUT_PATH, output); | ||
|
|
||
| console.log(`\nGenerated: ${OUTPUT_PATH}`); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.