cli-release-version.ts33 lines · main
1import { NextApiRequest, NextApiResponse } from 'next'
2
3type GitHubRepositoryRelease = {
4 id: number
5 url: string
6 name: string
7 tag_name: string
8 published_at: string
9}
10
11const current = process.env.CURRENT_CLI_VERSION ? `v${process.env.CURRENT_CLI_VERSION}` : undefined
12
13const handler = async (_req: NextApiRequest, res: NextApiResponse) => {
14 try {
15 const { tag_name: latest, published_at }: GitHubRepositoryRelease = await fetch(
16 'https://api.github.com/repos/briven/cli/releases/latest'
17 ).then((res) => res.json())
18
19 const data: GitHubRepositoryRelease[] = await fetch(
20 'https://api.github.com/repos/briven/cli/releases?per_page=1'
21 )
22 .then((res) => res.json())
23 // Ignore errors fetching beta release version
24 .catch(() => [])
25 const beta = data[0]?.tag_name
26
27 return res.status(200).json({ current, latest, beta, published_at })
28 } catch {
29 return res.status(200).json({ current })
30 }
31}
32
33export default handler