()
| 76 | } |
| 77 | |
| 78 | function main() { |
| 79 | const packageRoot = findPackageRoot(__dirname) |
| 80 | const pkg = readPackageJson(packageRoot) |
| 81 | const version = pkg?.version || '' |
| 82 | |
| 83 | if (hasFlag('--help-lite')) { |
| 84 | printHelpLite() |
| 85 | process.exit(0) |
| 86 | } |
| 87 | |
| 88 | if (hasFlag('--version') || hasFlag('-v')) { |
| 89 | process.stdout.write(`${version}\n`) |
| 90 | process.exit(0) |
| 91 | } |
| 92 | |
| 93 | // Native binary (npm optionalDependencies, no GitHub postinstall). |
| 94 | const nativeBin = tryResolveNativeBinaryFromOptionalDeps() |
| 95 | if (nativeBin) { |
| 96 | run(nativeBin, process.argv.slice(2)) |
| 97 | } |
| 98 | |
| 99 | // Node.js runtime fallback. |
| 100 | const distEntry = path.join(packageRoot, 'dist', 'index.js') |
| 101 | if (fs.existsSync(distEntry)) { |
| 102 | run(process.execPath, [distEntry, ...process.argv.slice(2)]) |
| 103 | } |
| 104 | |
| 105 | // Final fallback: explain what to do |
| 106 | process.stderr.write( |
| 107 | [ |
| 108 | '❌ Kode is not runnable on this system.', |
| 109 | '', |
| 110 | 'Tried:', |
| 111 | '- Native binary (optionalDependencies)', |
| 112 | '- Node.js runtime (dist/index.js)', |
| 113 | '', |
| 114 | 'Fix:', |
| 115 | '- Reinstall with optionalDependencies enabled (avoid --no-optional/--omit=optional)', |
| 116 | '- Or install a platform binary package: @shareai-lab/kode-bin-<platform>-<arch>', |
| 117 | '- Or reinstall and ensure dist/ is present (npm install -g @shareai-lab/kode)', |
| 118 | '- Or run from source: bun run dev', |
| 119 | '', |
| 120 | version ? `Package version: ${version}` : '', |
| 121 | ].join('\n'), |
| 122 | ) |
| 123 | process.exit(1) |
| 124 | } |
| 125 | |
| 126 | if (require.main === module) { |
| 127 | main() |
no test coverage detected