🎥 Make videos programmatically with React
feat: get compositions from CLI
Antoinecf685f8dfc1e
diff --git a/packages/cli/src/index.tsx b/packages/cli/src/index.tsxindex ffcbb5dcda..a5d89d70f1 100644--- a/packages/cli/src/index.tsx+++ b/packages/cli/src/index.tsx@@ -1,6 +1,7 @@import {checkNodeVersion} from './check-version';import {Log} from './log';import {parsedCli} from './parse-command-line';+import {listCompositionsCommand} from "./listCompositions";import {previewCommand} from './preview';import {printHelp} from './print-help';import {render} from './render';@@ -29,7 +30,9 @@ export const cli = async () => {}try {- if (command === 'preview') {+ if (command === 'compositions') {+ await listCompositionsCommand();+ } else if (command === 'preview') {await previewCommand();} else if (command === 'render') {await render();diff --git a/packages/cli/src/listCompositions.tsx b/packages/cli/src/listCompositions.tsxnew file mode 100644index 0000000000..31e2b300b3--- /dev/null+++ b/packages/cli/src/listCompositions.tsx@@ -0,0 +1,18 @@+import path from "path";+import {bundle} from '@remotion/bundler';+import {getCompositions} from "@remotion/renderer";+import {loadConfig} from "./get-config-file-name";+import {parsedCli} from "./parse-command-line";++export const listCompositionsCommand = async () => {+ const file = parsedCli._[1];+ const fullPath = path.join(process.cwd(), file);++ loadConfig();++ const bundled = await bundle(fullPath);++ const compositions = await getCompositions(bundled);++ console.log(compositions.map(({ id }) => id).join('\n'))+}diff --git a/packages/cli/src/print-help.ts b/packages/cli/src/print-help.tsindex f27af74121..dc4346915d 100644--- a/packages/cli/src/print-help.ts+++ b/packages/cli/src/print-help.ts@@ -59,6 +59,11 @@ export const printHelp = () => {['--port', 'Custom port to use for the HTTP server'],['--env-file', 'Specify a location for a dotenv file'],]);+ Log.info();+ Log.info('remotion compositions <index-file.ts>');+ Log.info(+ chalk.gray('Print list of composition ids from the index file provided separated by line break')+ );Log.info();Log.info('remotion ' + VERSIONS_COMMAND);Log.info(diff --git a/packages/docs/docs/cli.md b/packages/docs/docs/cli.mdindex 7e870c4e6a..7e87bf8f63 100644--- a/packages/docs/docs/cli.md+++ b/packages/docs/docs/cli.md@@ -36,6 +36,14 @@ Render a still frame basd on the entry point, the composition ID and save it tonpx remotion still <entry-file> <composition-id> <output-location>```+### `npx remotion compositions`++Print list of composition ids from the index file provided separated by line break.++```bash+npx remotion compositions <entry-file>+```+### `npx remotion versions`Prints and validates versions of all Remotion packages.diff --git a/packages/example/package.json b/packages/example/package.jsonindex 97c62ee4ce..86771f47bf 100644--- a/packages/example/package.json+++ b/packages/example/package.json@@ -12,6 +12,7 @@"scripts": {"start": "remotion preview src/index.tsx","start-js": "remotion preview src/entry.jsx",+ "comps": "remotion compositions src/index.tsx","lint": "eslint src --ext ts,tsx,js,jsx","test": "jest","build": "tsc -d",