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

View File

@ -1,12 +1,14 @@
{
"name": "rage-framework-cli",
"name": "rage-fw",
"version": "0.0.23",
"bin": {
"rage-fw": "bin/index.js"
"rage-fw": "dist/index.js"
},
"main": "bin/index.js",
"main": "dist/index.js",
"scripts": {
"watch": "tsc -w"
"watch": "tsc -w",
"build": "tsup",
"start": "npx ./dist create"
},
"description": "CLI to scaffold a template project for RageFW",
"keywords": [],
@ -16,7 +18,8 @@
"@inquirer/prompts": "^5.0.5",
"chalk": "4.1.2",
"git-clone": "^0.2.0",
"yargs": "^17.7.2"
"yargs": "^17.7.2",
"axios": "^1.7.2"
},
"devDependencies": {
"@types/git-clone": "^0.2.4",

View File

@ -1,4 +1,4 @@
import type { CommandModule, ArgumentsCamelCase } from 'yargs'
import type { CommandModule } from 'yargs'
import c from 'chalk'
import { input, select } from '@inquirer/prompts'
import clone from 'git-clone'

View File

@ -1,6 +1,9 @@
import yargs from 'yargs'
import create from './commands/create'
import { checkForUpdate } from './utils/update'
yargs.middleware(checkForUpdate)
yargs
.usage('<cmd> [args]')

28
cli/src/utils/update.ts Normal file
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}`))
}

10
cli/tsup.config.ts Normal file
View File

@ -0,0 +1,10 @@
import { defineConfig } from 'tsup'
export default defineConfig({
entry: ['src/index.ts'],
outDir: './dist',
bundle: true,
splitting: false,
sourcemap: false,
clean: true,
})

View File

@ -65,6 +65,9 @@ importers:
'@inquirer/prompts':
specifier: ^5.0.5
version: 5.0.5
axios:
specifier: ^1.7.2
version: 1.7.2
chalk:
specifier: 4.1.2
version: 4.1.2