From 04412d7cbc198e959e38bbcf2694f9cd83239b78 Mon Sep 17 00:00:00 2001 From: Danya H Date: Thu, 13 Jun 2024 19:41:05 +0100 Subject: [PATCH] update checker middleware --- cli/src/commands/create.ts | 3 +++ cli/src/index.ts | 3 --- cli/src/utils/update.ts | 23 +++++++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cli/src/commands/create.ts b/cli/src/commands/create.ts index c99ee9e..2175468 100644 --- a/cli/src/commands/create.ts +++ b/cli/src/commands/create.ts @@ -4,6 +4,8 @@ import { input, select } from '@inquirer/prompts' import clone from 'git-clone' import path from 'node:path' +import { checkForUpdate } from '../utils/update' + function builder(yargs: Argv) { return yargs .option('projectName', { @@ -18,6 +20,7 @@ function builder(yargs: Argv) { type: 'string', demandOption: false, }) + .middleware(async () => await checkForUpdate()) } async function handler(args: ArgumentsCamelCase) { diff --git a/cli/src/index.ts b/cli/src/index.ts index 7fbdcb9..a2efb24 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -1,9 +1,6 @@ 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 index 29e555a..d4f124e 100644 --- a/cli/src/utils/update.ts +++ b/cli/src/utils/update.ts @@ -10,17 +10,20 @@ type Version = { message: string } -export async function checkForUpdate() { - yargs.showVersion(version => - axios.get(latestVersionURL).then(({ data }) => { - const latestVersion = data[0].name +export async function checkForUpdate(): Promise { + return new Promise(res => { + yargs.showVersion(version => + axios + .get(latestVersionURL) + .then(({ data }) => { + const latestVersion = data[0].name - if (!(latestVersion === version)) - notifyUserAboutUpdate(latestVersion) - - return - }), - ) + if (!(latestVersion === version)) + notifyUserAboutUpdate(latestVersion) + }) + .then(() => res()), + ) + }) } function notifyUserAboutUpdate(version: string) {