feat: tfcode

This commit is contained in:
Gab
2026-03-24 23:27:38 +11:00
parent 2ae12f8d6b
commit 3fe808d64c
6 changed files with 157 additions and 10 deletions

View File

@@ -109,15 +109,29 @@ async function createMainPackage() {
await Bun.file(`./dist/tfcode/postinstall.mjs`).write(await Bun.file("./script/postinstall-tfcode.mjs").text())
await Bun.file(`./dist/tfcode/LICENSE`).write(await Bun.file("../../LICENSE").text())
// Copy the current platform's binary to the main package
// This makes installation faster (no need to download or copy from optionalDependencies)
const currentPlatform = process.platform === "darwin" ? "darwin" : process.platform === "linux" ? "linux" : "windows"
const currentArch = process.arch
const platformBinDir = `./dist/tfcode-${currentPlatform}-${currentArch}/bin`
const binaryName = process.platform === "win32" ? "tfcode.exe" : "tfcode"
if (fs.existsSync(`${platformBinDir}/${binaryName}`)) {
console.log(`Including ${currentPlatform}-${currentArch} binary in main package`)
await $`cp ${platformBinDir}/${binaryName} ./dist/tfcode/bin/`
} else {
console.log(`Warning: No binary found for current platform (${currentPlatform}-${currentArch})`)
console.log(`The postinstall script will need to download or copy from optionalDependencies`)
}
// Create a simple wrapper script that runs the installed binary
const wrapper = `#!/usr/bin/env node
const { spawn } = require('child_process')
const path = require('path')
const fs = require('fs')
const binDir = path.join(__dirname, 'bin')
const binary = process.platform === 'win32' ? 'tfcode.exe' : 'tfcode'
const binaryPath = path.join(binDir, binary)
const binaryPath = path.join(__dirname, binary)
if (!fs.existsSync(binaryPath)) {
console.error('tfcode binary not found. Run: npm install @toothfairyai/tfcode')