refactor: add check for latest version
This commit is contained in:
parent
1eb0f35bde
commit
085c6a2d2a
2 changed files with 10 additions and 9 deletions
|
@ -10,7 +10,7 @@ import { loadMscore, INDV_DOWNLOADS, WebMscore } from './mscore'
|
||||||
import { ScoreInfo, ScoreInfoHtml, ScoreInfoObj, getActualId } from './scoreinfo'
|
import { ScoreInfo, ScoreInfoHtml, ScoreInfoObj, getActualId } from './scoreinfo'
|
||||||
import { getLibreScoreLink } from './librescore-link'
|
import { getLibreScoreLink } from './librescore-link'
|
||||||
import { escapeFilename } from './utils'
|
import { escapeFilename } from './utils'
|
||||||
import { isNpx, isLatest, installedVersion, latestVersion } from './npm-data'
|
import { isNpx, isLatest, getInstalledVer, getLatestVer } from './npm-data'
|
||||||
import i18n from './i18n'
|
import i18n from './i18n'
|
||||||
|
|
||||||
const inquirer: typeof import('inquirer') = require('inquirer')
|
const inquirer: typeof import('inquirer') = require('inquirer')
|
||||||
|
@ -187,8 +187,8 @@ void (async () => {
|
||||||
spinner.succeed('OK')
|
spinner.succeed('OK')
|
||||||
|
|
||||||
if (!(await isNpx())) {
|
if (!(await isNpx())) {
|
||||||
const installed = await installedVersion()
|
const installed = getInstalledVer()
|
||||||
const latest = await latestVersion()
|
const latest = await getLatestVer()
|
||||||
if (!isLatest(installed, latest)) {
|
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.`))
|
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.`))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,22 @@
|
||||||
import { exec as _exec } from 'child_process'
|
import { exec as _exec } from 'child_process'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
|
import { version } from '../package.json'
|
||||||
|
|
||||||
const exec = promisify(_exec)
|
const exec = promisify(_exec)
|
||||||
|
|
||||||
export async function isNpx() {
|
export async function isNpx (): Promise<boolean> {
|
||||||
const output = await exec('npm list -g musescore-downloader')
|
const output = await exec('npm list -g musescore-downloader')
|
||||||
return output.stdout.includes('(empty)')
|
return output.stdout.includes('(empty)')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function installedVersion() {
|
export function getInstalledVer (): string {
|
||||||
return require('../package.json').version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function latestVersion() {
|
export async function getLatestVer (): Promise<string> {
|
||||||
return (await exec('npm info musescore-downloader version')).stdout.trim()
|
return (await exec('npm info musescore-downloader version')).stdout.trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isLatest() {
|
export function isLatest (installed: string, lastest: string): boolean {
|
||||||
return await installedVersion() === await latestVersion()
|
return installed === lastest
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue