62 lines
2.8 KiB
JavaScript
62 lines
2.8 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.loadConfigFile = void 0;
|
|
const bundler_1 = require("@remotion/bundler");
|
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
const node_path_1 = __importDefault(require("node:path"));
|
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
const log_1 = require("./log");
|
|
const loadConfigFile = async (remotionRoot, configFileName, isJavascript) => {
|
|
const resolved = node_path_1.default.resolve(remotionRoot, configFileName);
|
|
const tsconfigJson = node_path_1.default.join(remotionRoot, 'tsconfig.json');
|
|
if (!isJavascript && !node_fs_1.default.existsSync(tsconfigJson)) {
|
|
log_1.Log.error({ indent: false, logLevel: 'error' }, 'Could not find a tsconfig.json file in your project. Did you delete it? Create a tsconfig.json in the root of your project. Copy the default file from https://github.com/remotion-dev/template-helloworld/blob/main/tsconfig.json.');
|
|
log_1.Log.error({ indent: false, logLevel: 'error' }, 'The root directory is:', remotionRoot);
|
|
process.exit(1);
|
|
}
|
|
const virtualOutfile = 'bundle.js';
|
|
const result = await bundler_1.BundlerInternals.esbuild.build({
|
|
platform: 'node',
|
|
target: 'node16',
|
|
bundle: true,
|
|
entryPoints: [resolved],
|
|
tsconfig: isJavascript ? undefined : tsconfigJson,
|
|
absWorkingDir: remotionRoot,
|
|
outfile: virtualOutfile,
|
|
write: false,
|
|
packages: 'external',
|
|
});
|
|
if (result.errors.length > 0) {
|
|
log_1.Log.error({ indent: false, logLevel: 'error' }, 'Error in remotion.config.ts file');
|
|
for (const err in result.errors) {
|
|
log_1.Log.error({ indent: false, logLevel: 'error' }, err);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
const firstOutfile = result.outputFiles[0];
|
|
if (!firstOutfile) {
|
|
log_1.Log.error({ indent: false, logLevel: 'error' }, 'No output files found in the config file.');
|
|
process.exit(1);
|
|
}
|
|
let str = new TextDecoder().decode(firstOutfile.contents);
|
|
const currentCwd = process.cwd();
|
|
// The config file is always executed from the Remotion root, if `process.cwd()` is being used. We cannot enforce this in worker threads used for testing
|
|
if (node_worker_threads_1.isMainThread) {
|
|
process.chdir(remotionRoot);
|
|
}
|
|
if (process.env.PATCH_BUN_DEVELOPMENT) {
|
|
str = str.replace('@remotion/cli/config', './config');
|
|
}
|
|
// Exectute the contents of the config file
|
|
// eslint-disable-next-line no-eval
|
|
eval(str);
|
|
if (node_worker_threads_1.isMainThread) {
|
|
process.chdir(currentCwd);
|
|
}
|
|
return resolved;
|
|
};
|
|
exports.loadConfigFile = loadConfigFile;
|