feat(cli): ask for the page url or path to local file

This commit is contained in:
Xmader 2020-11-26 16:53:01 -05:00
parent a99bfc5923
commit 604678b29a
No known key found for this signature in database
GPG key ID: A20B97FB9EB730E4

View file

@ -18,7 +18,7 @@ const SCORE_URL_PREFIX = 'https://musescore.com/'
const EXT = '.mscz' const EXT = '.mscz'
interface Params { interface Params {
url: string; fileInit: string;
confirmed: boolean; confirmed: boolean;
part: number; part: number;
types: number[]; types: number[];
@ -26,25 +26,27 @@ interface Params {
} }
void (async () => { void (async () => {
const fileInit: string | undefined = process.argv[2]
const isLocalFile = fileInit?.endsWith(EXT) && fs.existsSync(fileInit)
let scoreinfo: ScoreInfo let scoreinfo: ScoreInfo
if (!isLocalFile) { // ask for the page url or path to local file
// ask for the page url const { fileInit } = await inquirer.prompt<Params>({
const { url } = await inquirer.prompt<Params>({ type: 'input',
type: 'input', name: 'fileInit',
name: 'url', message: 'Score URL or path to local MSCZ file:',
message: 'Score URL:', suffix: `\n (starts with "${SCORE_URL_PREFIX}" or local filepath ends with "${EXT}")\n `,
suffix: ` (starts with "${SCORE_URL_PREFIX}")\n `, validate (input: string) {
validate (input: string) { return input &&
return input && input.startsWith(SCORE_URL_PREFIX) (
}, input.startsWith(SCORE_URL_PREFIX) ||
default: fileInit, (input.endsWith(EXT) && fs.statSync(input).isFile())
}) )
},
default: process.argv[2],
})
const isLocalFile = fileInit.endsWith(EXT)
if (!isLocalFile) {
// request scoreinfo // request scoreinfo
scoreinfo = await ScoreInfoHtml.request(url) scoreinfo = await ScoreInfoHtml.request(fileInit)
// confirmation // confirmation
const { confirmed } = await inquirer.prompt<Params>({ const { confirmed } = await inquirer.prompt<Params>({