refactor: add check for latest version

This commit is contained in:
Xmader 2021-01-20 10:52:08 -05:00
parent 1eb0f35bde
commit 085c6a2d2a
No known key found for this signature in database
GPG Key ID: A20B97FB9EB730E4
2 changed files with 10 additions and 9 deletions

View File

@ -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, installedVersion, latestVersion } from './npm-data'
import { isNpx, isLatest, getInstalledVer, getLatestVer } from './npm-data'
import i18n from './i18n'
const inquirer: typeof import('inquirer') = require('inquirer')
@ -187,8 +187,8 @@ void (async () => {
spinner.succeed('OK')
if (!(await isNpx())) {
const installed = await installedVersion()
const latest = await latestVersion()
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.`))
}

View File

@ -1,21 +1,22 @@
import { exec as _exec } from 'child_process'
import { promisify } from 'util'
import { version } from '../package.json'
const exec = promisify(_exec)
export async function isNpx() {
export async function isNpx (): Promise<boolean> {
const output = await exec('npm list -g musescore-downloader')
return output.stdout.includes('(empty)')
}
export async function installedVersion() {
return require('../package.json').version
export function getInstalledVer (): string {
return version
}
export async function latestVersion() {
export async function getLatestVer (): Promise<string> {
return (await exec('npm info musescore-downloader version')).stdout.trim()
}
export async function isLatest() {
return await installedVersion() === await latestVersion()
export function isLatest (installed: string, lastest: string): boolean {
return installed === lastest
}