Skip to content

🎥 Make videos programmatically with React

better copy dir

Jonny Burgera3d1a25953bf
diff --git a/packages/bundler/src/bundler.ts b/packages/bundler/src/bundler.ts
index 53152812e2..a5ec663922 100644
--- a/packages/bundler/src/bundler.ts
+++ b/packages/bundler/src/bundler.ts
@@ -1,10 +1,10 @@
-import execa from 'execa';
import fs from 'fs';
import os from 'os';
import path from 'path';
import {Internals, WebpackOverrideFn} from 'remotion';
import {promisify} from 'util';
import webpack from 'webpack';
+import {copyDir} from './copy-dir';
import {indexHtml} from './static-preview';
import {webpackConfig} from './webpack-config';
@@ -54,20 +54,14 @@ export const bundle = async (
throw new Error(errors[0].message + '\n' + errors[0].details);
}
+ // TODO: What if public folder does not exist?
+
// TODO: Make this better in Lambda
const html = indexHtml(`/public`);
fs.writeFileSync(path.join(outDir, 'index.html'), html);
- if (process.platform === 'win32') {
- await execa('xcopy', [
- path.join(process.cwd(), 'public'),
- path.join(outDir, 'public'),
- '/s',
- '/e',
- '/y',
- ]);
- } else {
- await execa('cp', ['-a', path.join(process.cwd(), 'public'), outDir]);
- }
+ const from = path.join(process.cwd(), 'public');
+ const to = path.join(outDir, 'public');
+ await copyDir(from, to);
return outDir;
};
diff --git a/packages/bundler/src/copy-dir.ts b/packages/bundler/src/copy-dir.ts
new file mode 100644
index 0000000000..640abd9af8
--- /dev/null
+++ b/packages/bundler/src/copy-dir.ts
@@ -0,0 +1,18 @@
+import path from 'path';
+import fs from 'fs';
+
+export async function copyDir(src: string, dest: string) {
+ await fs.promises.mkdir(dest, {recursive: true});
+ const entries = await fs.promises.readdir(src, {withFileTypes: true});
+
+ for (const entry of entries) {
+ const srcPath = path.join(src, entry.name);
+ const destPath = path.join(dest, entry.name);
+
+ if (entry.isDirectory()) {
+ await copyDir(srcPath, destPath);
+ } else {
+ await fs.promises.copyFile(srcPath, destPath);
+ }
+ }
+}