🎥 Make videos programmatically with React
Added multiselect functioality
Stefan Uzunov8d66c2457eb9
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 8be8860172..b1e5b4f06a 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -9,12 +9,12 @@ import path from 'path';import {chalk} from './chalk';import {ConfigInternals} from './config';import {getCliOptions, getFinalCodec} from './get-cli-options';-import {getCompositionId} from './get-composition-id';import {getRenderMediaOptions} from './get-render-media-options';import {Log} from './log';import {makeProgressBar} from './make-progress-bar';import {parsedCli, quietFlagProvided} from './parse-command-line';import {createOverwriteableCliOutput} from './progress-bar';+import {selectComposition} from './select-composition';import {bundleOnCliOrTakeServeUrl} from './setup-cache';import {truthy} from './truthy';@@ -200,15 +200,14 @@ export const benchmarkCommand = async (puppeteerInstance,});- const ids = (args[1] ?? '')- .split(',')- .map((c) => c.trim())- .filter(truthy);-- if (ids[0] === '') {- const composition = await getCompositionId();- return composition;- }+ const ids = (+ args[1]+ ? args[1]+ .split(',')+ .map((c) => c.trim())+ .filter(truthy)+ : await selectComposition(true)+ ) as string[];const compositions = ids.map((compId) => {const composition = comps.find((c) => c.id === compId);diff --git a/packages/cli/src/composition-prompts.ts b/packages/cli/src/composition-prompts.tsindex cd3025869c..cce200cee8 100644--- a/packages/cli/src/composition-prompts.ts+++ b/packages/cli/src/composition-prompts.ts@@ -1,10 +1,10 @@-import type {Choice, Options, PromptObject} from 'prompts';+import type {Options, PromptObject} from 'prompts';import prompts from 'prompts';export type Question<V extends string = string> = PromptObject<V> & {optionsPerPage?: number;};-export type NamelessQuestion = Omit<Question<'value'>, 'name' | 'type'>;+export type NamelessQuestion = Omit<Question<'value'>, 'name'>;type PromptOptions = {nonInteractiveHelp?: string} & Options;export default function prompt(@@ -14,124 +14,22 @@ export default function prompt(questions = Array.isArray(questions) ? questions : [questions];return prompts(questions, {onCancel() {- throw new Error();+ throw new Error('User cancelled selection.');},...options,});}-prompt.separator = (title: string) => ({- title,- disabled: true,- value: undefined,-});-export async function selectAsync(- questions: NamelessQuestion,+ question: NamelessQuestion,options?: PromptOptions-): Promise<unknown> {+): Promise<string | string[]> {const {value} = await prompt({limit: 11,- ...questions,- // @ts-expect-error: onRender not in the types- onRender(this: {- cursor: number;- firstRender: boolean;- choices: (Omit<prompts.Choice, 'disable'> & {disabled?: boolean})[];- value: string;- render: () => void;- moveCursor: (n: number) => void;- fire: () => void;- up: () => void;- down: () => void;- bell: () => void;- next: () => void;- }) {- if (this.firstRender) {- while ((this.choices[this.cursor] as Choice).disabled) {- this.cursor++;- if (this.cursor > this.choices.length - 1) {- break;- }- }-- this.fire();- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain- this.value = (this.choices[this.cursor] || {}).value;-- this.up = () => {- let next = this.cursor;- // eslint-disable-next-line no-constant-condition- while (true) {- if (next <= 0) {- break;- }-- next--;- if (!(this.choices[next] as Choice).disabled) {- break;- }- }-- if (- !(this.choices[next] as Choice).disabled &&- next !== this.cursor- ) {- this.moveCursor(next);- this.render();- } else {- this.bell();- }- };-- this.down = () => {- let next = this.cursor;- // eslint-disable-next-line no-constant-condition- while (true) {- if (next >= this.choices.length - 1) {- break;- }-- next++;- if (!(this.choices[next] as Choice).disabled) {- break;- }- }-- if (- !(this.choices[next] as Choice).disabled &&- next !== this.cursor- ) {- this.moveCursor(next);- this.render();- } else {- this.bell();- }- };-- this.next = () => {- let next = this.cursor;- let i = 0;- while (i < this.choices.length) {- i++;- next = (next + 1) % this.choices.length;- if ((this.choices[next] as Choice).disabled) {- break;- }- }-- if ((this.choices[next] as Choice).disabled) {- this.bell();- } else {- this.moveCursor(next);- this.render();- }- };- }- },+ ...question,name: 'value',- type: 'select',+ type: question.type,},options);diff --git a/packages/cli/src/get-composition-id.ts b/packages/cli/src/get-composition-id.tsindex ee41fdfb19..0dfad07d34 100644--- a/packages/cli/src/get-composition-id.ts+++ b/packages/cli/src/get-composition-id.ts@@ -3,12 +3,16 @@ import {parsedCli} from './parse-command-line';import {selectComposition} from './select-composition';export const getCompositionId = async () => {- if (!parsedCli._[2]) {- Log.error('Composition ID not passed.');+ if (parsedCli._[2]) {+ return parsedCli._[2];+ }+ if (!process.env.CI) {const selectedComposition = await selectComposition();- return selectedComposition;+ if (selectedComposition && typeof selectedComposition === 'string') {+ return selectedComposition;+ }}- return parsedCli._[2];+ Log.error('Composition ID not passed.');};diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex a5ba1585f2..ddb46ebcee 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -95,6 +95,10 @@ export const render = async (remotionRoot: string) => {const compositionId = await getCompositionId();+ if (!compositionId) {+ throw new Error(`No composition ID provided.`);+ }+const relativeOutputLocation = getOutputFilename({codec,imageSequence: shouldOutputImageSequence,diff --git a/packages/cli/src/select-composition.ts b/packages/cli/src/select-composition.tsindex 846f674e2e..58e22a6f97 100644--- a/packages/cli/src/select-composition.ts+++ b/packages/cli/src/select-composition.ts@@ -4,7 +4,6 @@ import {RenderInternals,} from '@remotion/renderer';import path from 'path';-import prompts from './composition-prompts';// eslint-disable-next-line no-restricted-importsimport {Internals} from 'remotion';import {selectAsync} from './composition-prompts';@@ -18,7 +17,9 @@ import {bundleOnCliOrTakeServeUrl} from './setup-cache';import type {RenderStep} from './step';import {getUserPassedOutputLocation} from './user-passed-output-location';-export const selectComposition = async () => {+export const selectComposition = async (+ multiple = false+): Promise<string[] | string> => {const remotionRoot = findRemotionRoot();const file = parsedCli._[1];const downloadMap = RenderInternals.makeDownloadMap();@@ -85,23 +86,27 @@ export const selectComposition = async () => {port,});- const selectedComposition = (await selectAsync(+ if (compositions.length === 1) {+ const onlyComposition = compositions.pop();+ if (onlyComposition) {+ return [onlyComposition.id];+ }+ }++ const selectedComposition = await selectAsync({- message: 'Select a composition:',+ message: multiple ? 'Select composition/s: ' : 'Select a composition:',optionsPerPage: 20,+ type: multiple ? 'multiselect' : 'select',choices: compositions.map((comp) => {- if (typeof comp.id === 'string') {- return prompts.separator(comp.id);- }-return {- value: comp.id,- title: chalk.bold(comp.id),+ value: comp.id as string,+ title: chalk.bold(comp.id as string),};}),},{}- )) as string;+ );return selectedComposition;};diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex 3875f04dcf..04176015ad 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -77,6 +77,10 @@ export const still = async (remotionRoot: string) => {isLambda: false,});+ if (!compositionId) {+ throw new Error('No Composition ID provided.');+ }+const relativeOutputLocation = getOutputLocation({compositionId,defaultExtension: imageFormat,