// Update NOSE itself and restart.

import { $ } from "bun"
import restart from "./restart"

export default async function update() {
  if (process.env.NODE_ENV !== "production") {
    return { error: "Can only update in production." }
  }

  const { stdout } = await $`git pull`.quiet()
  const out = stdout.toString()

  if (/up to date/.test(out)) {
    return "Up to date."
  } else {
    return restart()
  }
}

export const GET = update