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
1 changed files with 19 additions and 17 deletions

View File

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