feat: build scripts

This commit is contained in:
Gab 2026-03-24 18:55:20 +11:00
parent 943278e380
commit d716f9a6d6
2 changed files with 26 additions and 25 deletions

View File

@ -18,6 +18,7 @@ import pkg from "../package.json"
// tfcode version
const TFCODE_VERSION = pkg.version
const TFCODE_NAME = "tfcode"
const GITEA_REPO = "ToothFairyAI/tf_code"
// Fetch models snapshot
const modelsUrl = process.env.TFCODE_MODELS_URL || "https://models.dev"
@ -191,4 +192,4 @@ if (Script.release || process.env.TFCODE_RELEASE) {
console.log("Binaries packaged. Upload to Gitea releases manually or use publish.ts")
}
export { binaries, TFCODE_VERSION }
export { binaries, TFCODE_VERSION }

View File

@ -13,7 +13,7 @@ process.chdir(dir)
const TFCODE_VERSION = pkg.version
const GITEA_HOST = process.env.GITEA_HOST || "gitea.toothfairyai.com"
const GITEA_TOKEN = process.env.GITEA_TOKEN
const GITEA_REPO = process.env.GITEA_REPO || "ToothFairyAI/tfcode"
const GITEA_REPO = process.env.GITEA_REPO || "ToothFairyAI/tf_code"
// Collect binaries
const binaries: Record<string, string> = {}
@ -39,7 +39,7 @@ async function uploadToGitea() {
try {
const res = await fetch(releaseUrl, {
headers: { Authorization: `token ${GITEA_TOKEN}` }
headers: { Authorization: `token ${GITEA_TOKEN}` },
})
if (res.ok) {
const release = await res.json()
@ -55,22 +55,22 @@ async function uploadToGitea() {
method: "POST",
headers: {
Authorization: `token ${GITEA_TOKEN}`,
"Content-Type": "application/json"
"Content-Type": "application/json",
},
body: JSON.stringify({
tag_name: `v${TFCODE_VERSION}`,
name: `v${TFCODE_VERSION}`,
body: `tfcode v${TFCODE_VERSION}\n\nSee CHANGELOG.md for details.`,
draft: false,
prerelease: TFCODE_VERSION.includes("-")
})
prerelease: TFCODE_VERSION.includes("-"),
}),
})
if (!res.ok) {
console.error("Failed to create release:", await res.text())
process.exit(1)
}
const release = await res.json()
releaseId = release.id
console.log(`Created release v${TFCODE_VERSION}`)
@ -83,17 +83,17 @@ async function uploadToGitea() {
const assetPath = `./dist/${asset}`
const file = Bun.file(assetPath)
const uploadUrl = `https://${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${releaseId}/assets?name=${asset}`
console.log(`Uploading ${asset}...`)
const res = await fetch(uploadUrl, {
method: "POST",
headers: {
Authorization: `token ${GITEA_TOKEN}`,
"Content-Type": "application/octet-stream"
"Content-Type": "application/octet-stream",
},
body: file
body: file,
})
if (!res.ok) {
console.error(`Failed to upload ${asset}:`, await res.text())
} else {
@ -109,7 +109,7 @@ async function createMainPackage() {
await $`cp -r ./bin ./dist/tfcode/bin`
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())
await Bun.file(`./dist/tfcode/package.json`).write(
JSON.stringify(
{
@ -122,24 +122,24 @@ async function createMainPackage() {
homepage: "https://toothfairyai.com/developers/tfcode",
repository: {
type: "git",
url: `https://${GITEA_HOST}/${GITEA_REPO}.git`
}
url: `https://${GITEA_HOST}/${GITEA_REPO}.git`,
},
},
null,
2
)
2,
),
)
// Pack and publish
if (process.platform !== "win32") {
await $`chmod -R 755 ./dist/tfcode`
}
for (const [name, version] of Object.entries(binaries)) {
console.log(`Publishing ${name}...`)
await $`cd ./dist/${name.replace('@toothfairyai/', '')} && bun pm pack && npm publish *.tgz --access public --tag beta`
await $`cd ./dist/${name.replace("@toothfairyai/", "")} && bun pm pack && npm publish *.tgz --access public --tag beta`
}
console.log("Publishing main package...")
await $`cd ./dist/tfcode && bun pm pack && npm publish *.tgz --access public --tag beta`
}
@ -150,7 +150,7 @@ async function createHomebrewFormula() {
const x64Sha = await $`sha256sum ./dist/tfcode-linux-x64.tar.gz | cut -d' ' -f1`.text().then((x) => x.trim())
const macX64Sha = await $`sha256sum ./dist/tfcode-darwin-x64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
const macArm64Sha = await $`sha256sum ./dist/tfcode-darwin-arm64.zip | cut -d' ' -f1`.text().then((x) => x.trim())
const formula = [
"# typed: false",
"# frozen_string_literal: true",
@ -198,9 +198,9 @@ async function createHomebrewFormula() {
" end",
" end",
"end",
""
"",
].join("\n")
await Bun.file("./dist/tfcode.rb").write(formula)
console.log("Created Homebrew formula: ./dist/tfcode.rb")
console.log("To publish: Create a tap repo and push this formula")
@ -233,4 +233,4 @@ if (process.argv.includes("--all")) {
await uploadToGitea()
await createMainPackage()
await createHomebrewFormula()
}
}