update checker middleware
This commit is contained in:
parent
9204eb81be
commit
04412d7cbc
@ -4,6 +4,8 @@ import { input, select } from '@inquirer/prompts'
|
|||||||
import clone from 'git-clone'
|
import clone from 'git-clone'
|
||||||
import path from 'node:path'
|
import path from 'node:path'
|
||||||
|
|
||||||
|
import { checkForUpdate } from '../utils/update'
|
||||||
|
|
||||||
function builder(yargs: Argv) {
|
function builder(yargs: Argv) {
|
||||||
return yargs
|
return yargs
|
||||||
.option('projectName', {
|
.option('projectName', {
|
||||||
@ -18,6 +20,7 @@ function builder(yargs: Argv) {
|
|||||||
type: 'string',
|
type: 'string',
|
||||||
demandOption: false,
|
demandOption: false,
|
||||||
})
|
})
|
||||||
|
.middleware(async () => await checkForUpdate())
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handler(args: ArgumentsCamelCase) {
|
async function handler(args: ArgumentsCamelCase) {
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
import yargs from 'yargs'
|
import yargs from 'yargs'
|
||||||
|
|
||||||
import create from './commands/create'
|
import create from './commands/create'
|
||||||
import { checkForUpdate } from './utils/update'
|
|
||||||
|
|
||||||
yargs.middleware(checkForUpdate)
|
|
||||||
|
|
||||||
yargs
|
yargs
|
||||||
.usage('<cmd> [args]')
|
.usage('<cmd> [args]')
|
||||||
|
@ -10,17 +10,20 @@ type Version = {
|
|||||||
message: string
|
message: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkForUpdate() {
|
export async function checkForUpdate(): Promise<void> {
|
||||||
yargs.showVersion(version =>
|
return new Promise(res => {
|
||||||
axios.get<Version[]>(latestVersionURL).then(({ data }) => {
|
yargs.showVersion(version =>
|
||||||
const latestVersion = data[0].name
|
axios
|
||||||
|
.get<Version[]>(latestVersionURL)
|
||||||
|
.then(({ data }) => {
|
||||||
|
const latestVersion = data[0].name
|
||||||
|
|
||||||
if (!(latestVersion === version))
|
if (!(latestVersion === version))
|
||||||
notifyUserAboutUpdate(latestVersion)
|
notifyUserAboutUpdate(latestVersion)
|
||||||
|
})
|
||||||
return
|
.then(() => res()),
|
||||||
}),
|
)
|
||||||
)
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function notifyUserAboutUpdate(version: string) {
|
function notifyUserAboutUpdate(version: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user