Skip to content

Commit

Permalink
feat: add check for latest version
Browse files Browse the repository at this point in the history
Merge pull request Xmader#106 from RubenVerg/master
  • Loading branch information
Xmader authored Jan 20, 2021
2 parents 49fcb99 + bd94367 commit 1eb0f35
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 changes: 21 additions & 0 deletions src/npm-data.ts
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit 1eb0f35

Please sign in to comment.