Skip to content

πŸŽ₯ Make videos programmatically with React

simplify

Jonny Burger9c2f4d5f6af9
diff --git a/packages/create-video/src/init.ts b/packages/create-video/src/init.ts
index 2b3d863261..78cd1155f3 100644
--- a/packages/create-video/src/init.ts
+++ b/packages/create-video/src/init.ts
@@ -74,10 +74,9 @@ const getGitStatus = async (root: string): Promise<void> => {
};
export const init = async () => {
- Log.info(`Welcome to ${chalk.blueBright('Remotion')}!`);
- Log.info();
-
+ Log.info(`Welcome to ${chalk.blue('Remotion')}!`);
const {projectRoot, folderName} = await resolveProjectRoot();
+ Log.info();
const result = await checkGitAvailability(projectRoot, 'git', ['--version']);
@@ -129,12 +128,6 @@ export const init = async () => {
process.exit(1);
}
- Log.info(
- `Copied ${chalk.blueBright(
- selectedTemplate.shortName,
- )} to ${chalk.blueBright(folderName)}.`,
- );
-
createYarnYmlFile({
pkgManager,
pkgManagerVersion,
@@ -148,18 +141,21 @@ export const init = async () => {
? projectRoot
: relativeToCurrent;
+ Log.info();
Log.info(
- `✨ Your video has been created at ${chalk.blueBright(cdToFolder)}.`,
+ `Copied ${chalk.blue(
+ selectedTemplate.shortName,
+ )} to ${chalk.blue(cdToFolder)}.`,
);
Log.info();
- Log.info('Get started by running');
- Log.info(chalk.blueBright(`cd ${cdToFolder}`));
- Log.info(chalk.blueBright(getInstallCommand(pkgManager)));
- Log.info(chalk.blueBright(getDevCommand(pkgManager, selectedTemplate)));
+ Log.info('Get started by running:');
+ Log.info(' ' + chalk.blue(`cd ${cdToFolder}`));
+ Log.info(' ' + chalk.blue(getInstallCommand(pkgManager)));
+ Log.info(' ' + chalk.blue(getDevCommand(pkgManager, selectedTemplate)));
Log.info('');
- Log.info('To render a video, run');
- Log.info(chalk.blueBright(getRenderCommand(pkgManager)));
+ Log.info('To render a video, run:');
+ Log.info(' ' + chalk.blue(getRenderCommand(pkgManager)));
Log.info('');
Log.info(
'Docs to get you started:',
diff --git a/packages/create-video/src/log.ts b/packages/create-video/src/log.ts
index cb16f0eca7..3fbdcfe622 100644
--- a/packages/create-video/src/log.ts
+++ b/packages/create-video/src/log.ts
@@ -5,7 +5,7 @@ import chalk from 'chalk';
export const Log = {
chalk,
verbose: (...args: Parameters<typeof console.log>) => {
- return console.log(chalk.blueBright(...args));
+ return console.log(chalk.blue(...args));
},
info: (...args: Parameters<typeof console.log>) => {
return console.log(...args);
diff --git a/packages/create-video/src/open-in-editor-flow.ts b/packages/create-video/src/open-in-editor-flow.ts
index f354af587b..4902e1fc87 100644
--- a/packages/create-video/src/open-in-editor-flow.ts
+++ b/packages/create-video/src/open-in-editor-flow.ts
@@ -21,7 +21,7 @@ export const openInEditorFlow = async (projectRoot: string) => {
const should = await yesOrNo({
defaultValue: true,
- question: `πŸ’» Do you want to open the project in ${displayName}? (Y/n):`,
+ question: `πŸ’» Open the ${displayName}? (Y/n):`,
});
if (should) {
diff --git a/packages/create-video/src/prompts.ts b/packages/create-video/src/prompts.ts
index 30fa9a9745..17ecb074fc 100644
--- a/packages/create-video/src/prompts.ts
+++ b/packages/create-video/src/prompts.ts
@@ -8,11 +8,10 @@ export type NamelessQuestion = Omit<Question<'value'>, 'name' | 'type'>;
type PromptOptions = {nonInteractiveHelp?: string} & Options;
export default function prompt(
- questions: Question | Question[],
+ questions: Question,
{nonInteractiveHelp, ...options}: PromptOptions = {},
) {
- questions = Array.isArray(questions) ? questions : [questions];
- return prompts(questions, {
+ return prompts([questions], {
onCancel() {
throw new Error();
},
@@ -20,112 +19,102 @@ export default function prompt(
});
}
-prompt.separator = (title: string) => ({
- title,
- disabled: true,
- value: undefined,
-});
-
export async function selectAsync(
questions: NamelessQuestion,
- options?: PromptOptions,
): Promise<unknown> {
- 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) {
- // Ensure the initial state isn't on a disabled item.
- while ((this.choices[this.cursor] as Choice).disabled) {
- this.cursor++;
- if (this.cursor > this.choices.length - 1) break;
- }
+ 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) {
+ // Ensure the initial state isn't on a disabled item.
+ while ((this.choices[this.cursor] as Choice).disabled) {
+ this.cursor++;
+ if (this.cursor > this.choices.length - 1) break;
+ }
- this.fire();
- // Without this, the value will be `0` instead of a string.
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
- this.value = (this.choices[this.cursor] || {}).value;
+ this.fire();
+ // Without this, the value will be `0` instead of a string.
+ // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
+ this.value = (this.choices[this.cursor] || {}).value;
- // Support up arrow and `k` key -- no looping
- 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;
- }
+ // Support up arrow and `k` key -- no looping
+ 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();
- }
- };
+ if (
+ !(this.choices[next] as Choice).disabled &&
+ next !== this.cursor
+ ) {
+ this.moveCursor(next);
+ this.render();
+ } else {
+ this.bell();
+ }
+ };
- // Support down arrow and `j` key -- no looping
- 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;
- }
+ // Support down arrow and `j` key -- no looping
+ 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();
- }
- };
+ if (
+ !(this.choices[next] as Choice).disabled &&
+ next !== this.cursor
+ ) {
+ this.moveCursor(next);
+ this.render();
+ } else {
+ this.bell();
+ }
+ };
- // Support tab -- looping
- 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;
- }
+ // Support tab -- looping
+ 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) {
- // unexpected
- this.bell();
- } else {
- this.moveCursor(next);
- this.render();
- }
- };
- }
- },
- name: 'value',
- type: 'select',
+ if ((this.choices[next] as Choice).disabled) {
+ // unexpected
+ this.bell();
+ } else {
+ this.moveCursor(next);
+ this.render();
+ }
+ };
+ }
},
- options,
- );
+ name: 'value',
+ type: 'select',
+ });
return value ?? null;
}
diff --git a/packages/create-video/src/select-template.ts b/packages/create-video/src/select-template.ts
index 195e05ea7b..52be039ebb 100644
--- a/packages/create-video/src/select-template.ts
+++ b/packages/create-video/src/select-template.ts
@@ -1,8 +1,7 @@
import chalk from 'chalk';
import minimist from 'minimist';
import {makeHyperlink} from './hyperlinks/make-link';
-import prompts, {selectAsync} from './prompts';
-import {stripAnsi} from './strip-ansi';
+import {selectAsync} from './prompts';
import type {Template} from './templates';
import {FEATURED_TEMPLATES} from './templates';
@@ -14,21 +13,8 @@ const parsed = minimist<Options>(process.argv.slice(2), {
boolean: [...FEATURED_TEMPLATES.map((f) => f.cliId), 'tmp'],
});
-function padEnd(str: string, width: number): string {
- // Pulled from commander for overriding
- const len = Math.max(0, width - stripAnsi(str).length);
- return str + Array(len + 1).join(' ');
-}
-
export const isTmpFlagSelected = () => parsed.tmp;
-const descriptionColumn =
- Math.max(
- ...FEATURED_TEMPLATES.map((t) =>
- typeof t === 'object' ? t.shortName.length : 0,
- ),
- ) + 2;
-
export const selectTemplate = async () => {
const isFlagSelected = FEATURED_TEMPLATES.find((f) => {
return parsed[f.cliId];
@@ -38,31 +24,23 @@ export const selectTemplate = async () => {
return isFlagSelected;
}
- return (await selectAsync(
- {
- message: 'Choose a template:',
- optionsPerPage: 20,
- choices: FEATURED_TEMPLATES.map((template) => {
- if (typeof template === 'string') {
- return prompts.separator(template);
- }
-
- return {
- value: template,
- title:
- chalk.bold(
- padEnd(
- makeHyperlink({
- text: template.shortName,
- url: `https://remotion.dev/templates/${template.cliId}`,
- fallback: template.shortName,
- }),
- descriptionColumn,
- ),
- ) + template.description.trim(),
- };
- }),
- },
- {},
- )) as Template;
+ return (await selectAsync({
+ message: 'Choose a template:',
+ optionsPerPage: 20,
+
+ choices: FEATURED_TEMPLATES.map((template) => {
+ return {
+ value: template,
+ title: `${chalk.blue(template.shortName)}${chalk.reset(
+ ` ${chalk.gray(template.description.trim())} ${chalk.gray(
+ makeHyperlink({
+ text: '(?)',
+ url: `https://remotion.dev/templates/${template.cliId}`,
+ fallback: '',
+ }),
+ )}`,
+ )}`,
+ };
+ }),
+ })) as Template;
};