π₯ Make videos programmatically with React
ask to put in .gitignore
Jonny Burger9d1edb0f5749
diff --git a/.gitignore b/.gitignoreindex ac296c8566..6f21fd87f2 100644--- a/.gitignore+++ b/.gitignore@@ -28,3 +28,5 @@ packages/lambda-python/remotion_lambda.egg-infopackages/cloudrun/container/cloudbuild.jsonpackages/example/public/offthreadvideoregression.git++packages/example/build\ No newline at end of filediff --git a/packages/bundler/src/bundle.ts b/packages/bundler/src/bundle.tsindex b10a45c072..8bc431d570 100644--- a/packages/bundler/src/bundle.ts+++ b/packages/bundler/src/bundle.ts@@ -119,13 +119,16 @@ const convertArgumentsIntoOptions = (args: Arguments): BundleOptions => {const recursionLimit = 5;-const findClosestPackageJsonFolder = (currentDir: string): string | null => {- let possiblePackageJson = '';+export const findClosestFolderWithFile = (+ currentDir: string,+ file: string,+): string | null => {+ let possibleFile = '';for (let i = 0; i < recursionLimit; i++) {- possiblePackageJson = path.join(currentDir, 'package.json');- const exists = fs.existsSync(possiblePackageJson);+ possibleFile = path.join(currentDir, file);+ const exists = fs.existsSync(possibleFile);if (exists) {- return path.dirname(possiblePackageJson);+ return path.dirname(possibleFile);}currentDir = path.dirname(currentDir);@@ -134,6 +137,10 @@ const findClosestPackageJsonFolder = (currentDir: string): string | null => {return null;};+const findClosestPackageJsonFolder = (currentDir: string): string | null => {+ return findClosestFolderWithFile(currentDir, 'package.json');+};+const validateEntryPoint = async (entryPoint: string) => {const contents = await promises.readFile(entryPoint, 'utf8');if (!contents.includes('registerRoot')) {diff --git a/packages/bundler/src/index.ts b/packages/bundler/src/index.tsindex efa51767b7..af5d56d065 100644--- a/packages/bundler/src/index.ts+++ b/packages/bundler/src/index.ts@@ -1,4 +1,4 @@-import {getConfig} from './bundle';+import {findClosestFolderWithFile, getConfig} from './bundle';import {indexHtml} from './index-html';import {readRecursively} from './read-recursively';import {cacheExists, clearCache} from './webpack-cache';@@ -14,6 +14,7 @@ export const BundlerInternals = {clearCache,getConfig,readRecursively,+ findClosestFolderWithFile,};export {bundle, BundleOptions, LegacyBundleOptions} from './bundle';diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex 5399ff1a40..b23fdb8a1b 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -229,6 +229,7 @@ export const benchmarkCommand = async (},quietProgress: false,quietFlag: quietFlagProvided(),+ outDir: null,});registerCleanupJob(() => cleanupBundle());diff --git a/packages/cli/src/bundle.ts b/packages/cli/src/bundle.tsindex 58ec31833c..e9616ba357 100644--- a/packages/cli/src/bundle.ts+++ b/packages/cli/src/bundle.ts@@ -1,4 +1,7 @@+import {BundlerInternals} from '@remotion/bundler';import type {LogLevel} from '@remotion/renderer';+import {existsSync, readFileSync, writeFileSync} from 'fs';+import path from 'path';import {chalk} from './chalk';import {findEntryPoint} from './entry-point';import {getCliOptions} from './get-cli-options';@@ -6,6 +9,7 @@ import {Log} from './log';import {quietFlagProvided} from './parse-command-line';import {bundleOnCli} from './setup-cache';import {shouldUseNonOverlayingLogger} from './should-use-non-overlaying-logger';+import {yesOrNo} from './yes-or-no';export const bundleCommand = async (remotionRoot: string,@@ -31,8 +35,12 @@ export const bundleCommand = async (const updatesDontOverwrite = shouldUseNonOverlayingLogger({logLevel});if (!file) {- // TODO: Proper error handling- throw new Error('No file found');+ Log.error('No entry point found.');+ Log.error(+ 'Pass another argument to the command specifying the entry point.',+ );+ Log.error('See: https://www.remotion.dev/docs/terminology#entry-point');+ process.exit(1);}const {publicDir} = await getCliOptions({@@ -42,6 +50,13 @@ export const bundleCommand = async (logLevel,});+ const outputPath = path.join(remotionRoot, 'build');+ const gitignoreFolder = BundlerInternals.findClosestFolderWithFile(+ outputPath,+ '.gitignore',+ );+ const existed = existsSync(outputPath);+const output = await bundleOnCli({fullPath: file,logLevel,@@ -54,8 +69,50 @@ export const bundleCommand = async (remotionRoot,onProgressCallback: () => {},quietFlag: quietFlagProvided(),+ outDir: outputPath,+ });++ Log.infoAdvanced(+ {indent: false, logLevel},+ chalk.blue(`${existed ? 'β' : '+'} ${output}`),+ );++ if (!gitignoreFolder) {+ return;+ }++ // Non-interactive terminal+ if (!process.stdout.isTTY) {+ return;+ }++ const gitignorePath = path.join(gitignoreFolder, '.gitignore');+ const gitIgnoreContents = readFileSync(gitignorePath, 'utf-8');+ const relativePathToGitIgnore = path.relative(gitignoreFolder, outputPath);++ const isInGitIgnore = gitIgnoreContents+ .split('\n')+ .includes(relativePathToGitIgnore);+ if (isInGitIgnore) {+ return;+ }++ const answer = await yesOrNo({+ defaultValue: true,+ question: `Do you want to add ${chalk.bold(+ relativePathToGitIgnore,+ )} to your ${chalk.bold('.gitignore')} file? (Y/n)`,});- // TODO: Not + if already existed- Log.infoAdvanced({indent: false, logLevel}, chalk.blue(`+ ${output}`));+ if (!answer) {+ return;+ }++ const newGitIgnoreContents =+ gitIgnoreContents + '\n' + relativePathToGitIgnore;+ writeFileSync(gitignorePath, newGitIgnoreContents);+ Log.infoAdvanced(+ {indent: false, logLevel},+ chalk.blue(`Added to .gitignore!`),+ );};diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 8814f2fa2f..daecf0da1e 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -66,6 +66,7 @@ export const listCompositionsCommand = async (},quietProgress: false,quietFlag: quietFlagProvided(),+ outDir: null,});registerCleanupJob(() => cleanupBundle());diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex a8a8fe3d8a..0be6e0a486 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -237,6 +237,7 @@ export const renderVideoFlow = async ({},quietProgress: updatesDontOverwrite,quietFlag: quietFlagProvided(),+ outDir: null,},);diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex aff7e1cd15..264b5894ba 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -170,6 +170,7 @@ export const renderStillFlow = async ({},quietProgress: updatesDontOverwrite,quietFlag: quietFlagProvided(),+ outDir: null,},);diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.tsindex fed5aad46e..5beb4adffb 100644--- a/packages/cli/src/setup-cache.ts+++ b/packages/cli/src/setup-cache.ts@@ -24,6 +24,7 @@ export const bundleOnCliOrTakeServeUrl = async ({onDirectoryCreated,quietProgress,quietFlag,+ outDir,}: {fullPath: string;remotionRoot: string;@@ -39,6 +40,7 @@ export const bundleOnCliOrTakeServeUrl = async ({onDirectoryCreated: (path: string) => void;quietProgress: boolean;quietFlag: boolean;+ outDir: string | null;}): Promise<{urlOrBundle: string;cleanup: () => void;@@ -72,6 +74,7 @@ export const bundleOnCliOrTakeServeUrl = async ({onDirectoryCreated,quietProgress,quietFlag,+ outDir,});return {@@ -92,6 +95,7 @@ export const bundleOnCli = async ({onDirectoryCreated,quietProgress,quietFlag,+ outDir,}: {fullPath: string;remotionRoot: string;@@ -107,6 +111,7 @@ export const bundleOnCli = async ({onDirectoryCreated: (path: string) => void;quietProgress: boolean;quietFlag: boolean;+ outDir: string | null;}) => {const shouldCache = ConfigInternals.getWebpackCaching();@@ -225,6 +230,7 @@ export const bundleOnCli = async ({updateProgress(false);},onDirectoryCreated,+ outDir: outDir ?? undefined,...options,});diff --git a/packages/cli/src/yes-or-no.ts b/packages/cli/src/yes-or-no.tsnew file mode 100644index 0000000000..ca88ec8bcb--- /dev/null+++ b/packages/cli/src/yes-or-no.ts@@ -0,0 +1,57 @@+import readline from 'readline';++const options = {+ yes: ['yes', 'y'],+ no: ['no', 'n'],+};++function defaultInvalidHandler({+ yesValues,+ noValues,+}: {+ question: string;+ yesValues: string[];+ noValues: string[];+}) {+ process.stdout.write('\nInvalid Response.\n');+ process.stdout.write('Answer either yes : (' + yesValues.join(', ') + ') \n');+ process.stdout.write('Or no: (' + noValues.join(', ') + ') \n\n');+}++export const yesOrNo = ({+ question,+ defaultValue,+}: {+ question: string;+ defaultValue: boolean;+}): Promise<boolean> => {+ const invalid = defaultInvalidHandler;++ const yesValues = options.yes.map((v) => v.toLowerCase());+ const noValues = options.no.map((v) => v.toLowerCase());++ const rl = readline.createInterface({+ input: process.stdin,+ output: process.stdout,+ });++ return new Promise<boolean>((resolve) => {+ rl.question(question + ' ', async (answer) => {+ rl.close();++ const cleaned = answer.trim().toLowerCase();+ if (cleaned === '' && defaultValue !== null) return resolve(defaultValue);++ if (yesValues.indexOf(cleaned) >= 0) return resolve(true);++ if (noValues.indexOf(cleaned) >= 0) return resolve(false);++ invalid({question, yesValues, noValues});+ const result = await yesOrNo({+ question,+ defaultValue,+ });+ resolve(result);+ });+ });+};