refactor: check version info
This commit is contained in:
parent
085c6a2d2a
commit
3c72b5a92f
2 changed files with 14 additions and 7 deletions
|
@ -10,7 +10,7 @@ import { loadMscore, INDV_DOWNLOADS, WebMscore } from './mscore'
|
|||
import { ScoreInfo, ScoreInfoHtml, ScoreInfoObj, getActualId } from './scoreinfo'
|
||||
import { getLibreScoreLink } from './librescore-link'
|
||||
import { escapeFilename } from './utils'
|
||||
import { isNpx, isLatest, getInstalledVer, getLatestVer } from './npm-data'
|
||||
import { isNpx, getVerInfo } from './npm-data'
|
||||
import i18n from './i18n'
|
||||
|
||||
const inquirer: typeof import('inquirer') = require('inquirer')
|
||||
|
@ -187,10 +187,9 @@ void (async () => {
|
|||
spinner.succeed('OK')
|
||||
|
||||
if (!(await isNpx())) {
|
||||
const installed = getInstalledVer()
|
||||
const latest = await getLatestVer()
|
||||
if (!isLatest(installed, latest)) {
|
||||
console.log(chalk.yellowBright(`Your installed version (${installed}) of the musescore-downloader CLI is not the latest one (${latest})!\nRun npm i -g musescore-downloader to update.`))
|
||||
const { installed, latest, isLatest } = await getVerInfo()
|
||||
if (!isLatest) {
|
||||
console.log(chalk.yellowBright(`\nYour installed version (${installed}) of the musescore-downloader CLI is not the latest one (${latest})!\nRun npm i -g musescore-downloader to update.`))
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { exec as _exec } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
import { version } from '../package.json'
|
||||
|
@ -17,6 +19,12 @@ export async function getLatestVer (): Promise<string> {
|
|||
return (await exec('npm info musescore-downloader version')).stdout.trim()
|
||||
}
|
||||
|
||||
export function isLatest (installed: string, lastest: string): boolean {
|
||||
return installed === lastest
|
||||
export async function getVerInfo () {
|
||||
const installed = getInstalledVer()
|
||||
const latest = await getLatestVer()
|
||||
return {
|
||||
installed,
|
||||
latest,
|
||||
isLatest: installed === latest,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue