feat: add check for latest version
Merge pull request #106 from RubenVerg/master
This commit is contained in:
commit
1eb0f35bde
3 changed files with 31 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "musescore-downloader",
|
||||
"version": "0.23.4",
|
||||
"version": "0.23.5",
|
||||
"description": "download sheet music from musescore.com for free, no login or Musescore Pro required | 免登录、免 Musescore Pro,免费下载 musescore.com 上的曲谱",
|
||||
"main": "dist/main.js",
|
||||
"bin": "dist/cli.js",
|
||||
|
|
|
@ -10,6 +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 i18n from './i18n'
|
||||
|
||||
const inquirer: typeof import('inquirer') = require('inquirer')
|
||||
|
@ -184,4 +185,12 @@ void (async () => {
|
|||
}),
|
||||
)
|
||||
spinner.succeed('OK')
|
||||
|
||||
if (!(await isNpx())) {
|
||||
const installed = await installedVersion()
|
||||
const latest = await latestVersion()
|
||||
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.`))
|
||||
}
|
||||
}
|
||||
})()
|
||||
|
|
21
src/npm-data.ts
Normal file
21
src/npm-data.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { exec as _exec } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const exec = promisify(_exec)
|
||||
|
||||
export async function isNpx() {
|
||||
const output = await exec('npm list -g musescore-downloader')
|
||||
return output.stdout.includes('(empty)')
|
||||
}
|
||||
|
||||
export async function installedVersion() {
|
||||
return require('../package.json').version
|
||||
}
|
||||
|
||||
export async function latestVersion() {
|
||||
return (await exec('npm info musescore-downloader version')).stdout.trim()
|
||||
}
|
||||
|
||||
export async function isLatest() {
|
||||
return await installedVersion() === await latestVersion()
|
||||
}
|
Loading…
Reference in a new issue