#!/usr/bin/env bun import { $ } from "bun" import fs from "fs" import path from "path" import { fileURLToPath } from "url" const __dirname = path.dirname(fileURLToPath(import.meta.url)) const dir = path.resolve(__dirname, "..") process.chdir(dir) const NPM_TAG = process.env.NPM_TAG || "latest" // Get binaries from dist const binaries: Record = {} for (const filepath of new Bun.Glob("*/package.json").scanSync({ cwd: "./dist" })) { const pkg = await Bun.file(`./dist/${filepath}`).json() if (pkg.name.startsWith("@toothfairyai/tfcode-")) { binaries[pkg.name] = pkg.version } } console.log("Binaries:", binaries) // Check which ones are already published const toPublish: string[] = [] for (const [name, version] of Object.entries(binaries)) { try { const publishedVersion = await $`npm view ${name} version` .quiet() .text() .then((t) => t.trim()) if (publishedVersion === version) { console.log(`${name} already published at ${version}`) } else { console.log(`${name} needs publishing: local ${version}, npm ${publishedVersion}`) toPublish.push(name) } } catch (error) { console.log(`${name} not published yet`) toPublish.push(name) } } // Publish remaining for (const name of toPublish) { console.log(`Publishing ${name}...`) const dirName = name.replace("@toothfairyai/", "") try { await $`cd ./dist/${dirName} && bun pm pack && npm publish *.tgz --access public --tag ${NPM_TAG}` console.log(`✓ Published ${name}`) } catch (error) { console.error(`Failed to publish ${name}:`, error) } } // Publish main package console.log("Publishing main package...") try { await $`cd ./dist/tfcode && bun pm pack && npm publish *.tgz --access public --tag ${NPM_TAG}` console.log("✓ Published main package") } catch (error) { console.error("Failed to publish main package:", error) }