feat: add View in LibreScore in msdl cli

This commit is contained in:
Xmader 2021-01-02 02:34:19 -05:00
parent bca9f5e150
commit 60d842bac7
No known key found for this signature in database
GPG key ID: A20B97FB9EB730E4

View file

@ -8,6 +8,7 @@ import os from 'os'
import { fetchMscz, setMscz, MSCZ_URL_SYM } from './mscz' import { fetchMscz, setMscz, MSCZ_URL_SYM } from './mscz'
import { loadMscore, INDV_DOWNLOADS, WebMscore } from './mscore' 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 { escapeFilename } from './utils' import { escapeFilename } from './utils'
import i18n from './i18n' import i18n from './i18n'
@ -38,6 +39,7 @@ void (async () => {
} // For MacOS, no hint is needed because the paste shortcut is universal. } // For MacOS, no hint is needed because the paste shortcut is universal.
let scoreinfo: ScoreInfo let scoreinfo: ScoreInfo
let librescoreLink: Promise<string> | undefined
// ask for the page url or path to local file // ask for the page url or path to local file
const { fileInit } = await inquirer.prompt<Params>({ const { fileInit } = await inquirer.prompt<Params>({
type: 'input', type: 'input',
@ -77,7 +79,12 @@ void (async () => {
default: true, default: true,
}) })
if (!confirmed) return if (!confirmed) return
console.log() // print a blank line to the terminal
// initiate LibreScore link request
librescoreLink = getLibreScoreLink(scoreinfo)
// print a blank line to the terminal
console.log()
} else { } else {
scoreinfo = new ScoreInfoObj(0, path.basename(fileInit, EXT)) scoreinfo = new ScoreInfoObj(0, path.basename(fileInit, EXT))
} }
@ -105,6 +112,11 @@ void (async () => {
if (!isLocalFile) { if (!isLocalFile) {
spinner.info(`File URL: ${scoreinfo.store.get(MSCZ_URL_SYM) as string}`) spinner.info(`File URL: ${scoreinfo.store.get(MSCZ_URL_SYM) as string}`)
} }
if (librescoreLink) {
try {
spinner.info(`View in LibreScore: ${await librescoreLink}`)
} catch { } // it doesn't affect the main feature
}
spinner.start() spinner.start()
// load score using webmscore // load score using webmscore