From f0ccfa321508a2db5bb4fa34190d67c4f9442498 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Wed, 22 Apr 2020 17:56:08 +0800 Subject: [PATCH] improve cli --- cli.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/cli.js b/cli.js index 07e5e4d..5463150 100644 --- a/cli.js +++ b/cli.js @@ -23,11 +23,11 @@ const cli = meow(` Options --out Out video path (defaults to ./editly-out.mp4) - can also be a .gif - --json Use JSON config, all other options will be ignored - --transition-name Name of default transition to use + --json Use JSON edit spec + --transition-name Name of default transition to use (default: random) --transition-duration Default transition duration in milliseconds - --width Width which all videos will be converted to - --height Height which all videos will be converted to + --width Width which all media will be converted to + --height Height which all media will be converted to --fps FPS which all videos will be converted to --font-path Set default font to a .ttf --audio-file-path Add an audio track @@ -35,9 +35,12 @@ const cli = meow(` --fast, -f Fast mode (low resolution and FPS, useful for getting a quick preview) --verbose + For more detailed explanation, see: + https://github.com/mifi/editly + Examples $ editly title:'My video' clip1.mov clip2.mov title:'My slideshow' img1.jpg img2.jpg title:'THE END' --audio-file-path /path/to/music.mp3 --font-path /path/to/my-favorite-font.ttf - $ editly --json my-editly.json --out output.gif + $ editly my-editly.json5 --out output.gif `, { flags: { fast: { type: 'boolean', alias: 'f' }, @@ -49,11 +52,16 @@ const cli = meow(` }); (async () => { + let { json } = cli.flags; + // eslint-disable-next-line prefer-destructuring + if (cli.input.length === 1 && /\.(json|json5|js)$/.test(cli.input[0].toLowerCase())) json = cli.input[0]; + let params = { defaults: {}, }; - if (cli.flags.json) { - params = JSON5.parse(fs.readFileSync(cli.flags.json, 'utf-8')); + + if (json) { + params = JSON5.parse(fs.readFileSync(json, 'utf-8')); } else { const clipsIn = cli.input; if (clipsIn.length < 1) cli.showHelp(); @@ -62,7 +70,13 @@ const cli = meow(` const match = clip.match(/^title:(.+)$/); if (match) return { type: 'title-background', text: match[1] }; - const { mime } = await FileType.fromFile(clip); + const fileType = await FileType.fromFile(clip); + if (!fileType) { + console.error('Invalid file for clip', clip); + cli.showHelp(); + } + + const { mime } = fileType; if (mime.startsWith('video')) return { type: 'video', path: clip }; if (mime.startsWith('image')) return { type: 'image', path: clip };