From 396e9c0ee61ed14dc09557b9fb7b776530c04754 Mon Sep 17 00:00:00 2001 From: Oleksandr Honcharov <0976053529@ukr.net> Date: Thu, 13 Jun 2024 21:16:52 +0300 Subject: [PATCH] cli check for update --- cli/package.json | 13 ++++++++----- cli/src/commands/create.ts | 2 +- cli/src/index.ts | 3 +++ cli/src/utils/update.ts | 28 ++++++++++++++++++++++++++++ cli/tsup.config.ts | 10 ++++++++++ pnpm-lock.yaml | 3 +++ 6 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 cli/src/utils/update.ts create mode 100644 cli/tsup.config.ts diff --git a/cli/package.json b/cli/package.json index f4c6426..1d3c092 100644 --- a/cli/package.json +++ b/cli/package.json @@ -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", diff --git a/cli/src/commands/create.ts b/cli/src/commands/create.ts index 114c613..a9e4ee7 100644 --- a/cli/src/commands/create.ts +++ b/cli/src/commands/create.ts @@ -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' diff --git a/cli/src/index.ts b/cli/src/index.ts index 512d938..396b839 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,6 +1,9 @@ import yargs from 'yargs' import create from './commands/create' +import { checkForUpdate } from './utils/update' + +yargs.middleware(checkForUpdate) yargs .usage(' [args]') diff --git a/cli/src/utils/update.ts b/cli/src/utils/update.ts new file mode 100644 index 0000000..29e555a --- /dev/null +++ b/cli/src/utils/update.ts @@ -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(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}`)) +} diff --git a/cli/tsup.config.ts b/cli/tsup.config.ts new file mode 100644 index 0000000..d0c0ce1 --- /dev/null +++ b/cli/tsup.config.ts @@ -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, +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39ea74b..7cae70e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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