Skip to content

🎥 Make videos programmatically with React

simplify

Jonny Burgerf0b3b677c711
diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsx
index f5e47f6429..94342ebd7e 100644
--- a/packages/cli/src/render.tsx
+++ b/packages/cli/src/render.tsx
@@ -1,4 +1,3 @@
-import {bundle, BundlerInternals} from '@remotion/bundler';
import {
getCompositions,
OnErrorInfo,
@@ -20,10 +19,10 @@ import {Log} from './log';
import {parsedCli} from './parse-command-line';
import {
createProgressBar,
- makeBundlingProgress,
makeRenderingProgress,
makeStitchingProgres,
} from './progress-bar';
+import {bundleOnCli} from './setup-cache';
import {checkAndValidateFfmpegVersion} from './validate-ffmpeg-version';
const onError = async (info: OnErrorInfo) => {
@@ -80,39 +79,7 @@ export const render = async () => {
const steps = shouldOutputImageSequence ? 2 : 3;
- const shouldCache = Internals.getWebpackCaching();
- const cacheExistedBefore = BundlerInternals.cacheExists('production', null);
- if (cacheExistedBefore && !shouldCache) {
- process.stdout.write('🧹 Cache disabled but found. Deleting... ');
- await BundlerInternals.clearCache('production', null);
- process.stdout.write('done. \n');
- }
-
- const bundleStartTime = Date.now();
- const bundlingProgress = createProgressBar();
- const bundled = await bundle(
- fullPath,
- (progress) => {
- bundlingProgress.update(
- makeBundlingProgress({progress: progress / 100, steps, doneIn: null})
- );
- },
- {
- enableCaching: shouldCache,
- }
- );
- bundlingProgress.update(
- makeBundlingProgress({
- progress: 1,
- steps,
- doneIn: Date.now() - bundleStartTime,
- }) + '\n'
- );
- Log.verbose('Bundled under', bundled);
- const cacheExistedAfter = BundlerInternals.cacheExists('production', null);
- if (cacheExistedAfter && !cacheExistedBefore) {
- Log.info('⚡️ Cached bundle. Subsequent builds will be faster.');
- }
+ const bundled = await bundleOnCli(fullPath, steps);
const openedBrowser = await browserInstance;
const comps = await getCompositions(bundled, {
diff --git a/packages/cli/src/setup-cache.ts b/packages/cli/src/setup-cache.ts
new file mode 100644
index 0000000000..31625c8019
--- /dev/null
+++ b/packages/cli/src/setup-cache.ts
@@ -0,0 +1,42 @@
+import {bundle, BundlerInternals} from '@remotion/bundler';
+import {Internals} from 'remotion';
+import {Log} from './log';
+import {createProgressBar, makeBundlingProgress} from './progress-bar';
+
+export const bundleOnCli = async (fullPath: string, steps: number) => {
+ const shouldCache = Internals.getWebpackCaching();
+ const cacheExistedBefore = BundlerInternals.cacheExists('production', null);
+ if (cacheExistedBefore && !shouldCache) {
+ process.stdout.write('🧹 Cache disabled but found. Deleting... ');
+ await BundlerInternals.clearCache('production', null);
+ process.stdout.write('done. \n');
+ }
+
+ const bundleStartTime = Date.now();
+ const bundlingProgress = createProgressBar();
+ const bundled = await bundle(
+ fullPath,
+ (progress) => {
+ bundlingProgress.update(
+ makeBundlingProgress({progress: progress / 100, steps, doneIn: null})
+ );
+ },
+ {
+ enableCaching: shouldCache,
+ }
+ );
+ bundlingProgress.update(
+ makeBundlingProgress({
+ progress: 1,
+ steps,
+ doneIn: Date.now() - bundleStartTime,
+ }) + '\n'
+ );
+ Log.verbose('Bundled under', bundled);
+ const cacheExistedAfter = BundlerInternals.cacheExists('production', null);
+ if (cacheExistedAfter && !cacheExistedBefore) {
+ Log.info('⚡️ Cached bundle. Subsequent builds will be faster.');
+ }
+
+ return bundled;
+};
diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.ts
index 4afd498167..cb5a833ad6 100644
--- a/packages/cli/src/still.ts
+++ b/packages/cli/src/still.ts
@@ -1,4 +1,3 @@
-import {bundle, BundlerInternals} from '@remotion/bundler';
import {
getCompositions,
RenderInternals,
@@ -14,11 +13,8 @@ import {handleCommonError} from './handle-common-errors';
import {initializeRenderCli} from './initialize-render-cli';
import {Log} from './log';
import {parsedCli} from './parse-command-line';
-import {
- createProgressBar,
- makeBundlingProgress,
- makeRenderingProgress,
-} from './progress-bar';
+import {createProgressBar, makeRenderingProgress} from './progress-bar';
+import {bundleOnCli} from './setup-cache';
import {getUserPassedOutputLocation} from './user-passed-output-location';
export const still = async () => {
@@ -56,40 +52,7 @@ export const still = async () => {
const steps = 2;
- const shouldCache = Internals.getWebpackCaching();
- const cacheExistedBefore = BundlerInternals.cacheExists('production', null);
- if (cacheExistedBefore && !shouldCache) {
- process.stdout.write('🧹 Cache disabled but found. Deleting... ');
- await BundlerInternals.clearCache('production', null);
- process.stdout.write('done. \n');
- }
-
- const bundleStartTime = Date.now();
- const bundlingProgress = createProgressBar();
- const bundled = await bundle(
- fullPath,
- (progress) => {
- bundlingProgress.update(
- makeBundlingProgress({progress: progress / 100, steps, doneIn: null})
- );
- },
- {
- enableCaching: shouldCache,
- }
- );
- bundlingProgress.update(
- makeBundlingProgress({
- progress: 1,
- steps,
- doneIn: Date.now() - bundleStartTime,
- }) + '\n'
- );
- Log.verbose('Bundled under', bundled);
-
- const cacheExistedAfter = BundlerInternals.cacheExists('production', null);
- if (cacheExistedAfter && !cacheExistedBefore) {
- Log.info('⚡️ Cached bundle. Subsequent builds will be faster.');
- }
+ const bundled = await bundleOnCli(fullPath, steps);
const openedBrowser = await browserInstance;
const comps = await getCompositions(bundled, {