musescore-downloader/src/npm-data.ts

31 lines
782 B
TypeScript
Raw Normal View History

2021-01-20 16:05:56 +00:00
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { exec as _exec } from 'child_process'
import { promisify } from 'util'
2021-01-20 15:52:08 +00:00
import { version } from '../package.json'
const exec = promisify(_exec)
2021-01-20 15:52:08 +00:00
export async function isNpx (): Promise<boolean> {
2021-01-15 07:55:06 +00:00
const output = await exec('npm list -g musescore-downloader')
return output.stdout.includes('(empty)')
}
2021-01-20 15:52:08 +00:00
export function getInstalledVer (): string {
return version
}
2021-01-20 15:52:08 +00:00
export async function getLatestVer (): Promise<string> {
return (await exec('npm info musescore-downloader version')).stdout.trim()
}
2021-01-20 16:05:56 +00:00
export async function getVerInfo () {
const installed = getInstalledVer()
const latest = await getLatestVer()
return {
installed,
latest,
isLatest: installed === latest,
}
}