cli check for update

This commit is contained in:
Oleksandr Honcharov
2024-06-13 21:16:52 +03:00
parent 839dff9b78
commit 396e9c0ee6
6 changed files with 53 additions and 6 deletions
+28
View File
@@ -0,0 +1,28 @@
import axios from 'axios'
import c from 'chalk'
import yargs from 'yargs'
const latestVersionURL =
'https://git.entityseven.com/api/v1/repos/entityseven/rage-framework/tags?page=1&limit=1'
type Version = {
name: string
message: string
}
export async function checkForUpdate() {
yargs.showVersion(version =>
axios.get<Version[]>(latestVersionURL).then(({ data }) => {
const latestVersion = data[0].name
if (!(latestVersion === version))
notifyUserAboutUpdate(latestVersion)
return
}),
)
}
function notifyUserAboutUpdate(version: string) {
console.log(c.green(`Update available. New version: ${version}`))
}