Skip to content

🎥 Make videos programmatically with React

scaffold out a cli

Jonny Burgerd2bdb9412aa2
diff --git a/packages/lambda/.eslintrc b/packages/lambda/.eslintrc
index 58011e33c5..92b10568b4 100644
--- a/packages/lambda/.eslintrc
+++ b/packages/lambda/.eslintrc
@@ -4,6 +4,7 @@
"project": "./tsconfig.json"
},
"rules": {
+ "no-console": "error",
"ts-exports/unused-exports": "off"
}
}
diff --git a/packages/lambda/package.json b/packages/lambda/package.json
index a524b2cebf..86739b08b9 100644
--- a/packages/lambda/package.json
+++ b/packages/lambda/package.json
@@ -4,6 +4,10 @@
"description": "Utility functions for audio and video",
"main": "dist/index.js",
"sideEffects": false,
+ "bin": {
+ "@remotion/lambda": "remotion-lambda-cli.js"
+ },
+ "module": "true",
"scripts": {
"test": "eslint src --ext ts,tsx",
"watch": "tsc -w",
@@ -24,6 +28,7 @@
"chalk": "^4.1.1",
"esbuild": "^0.11.12",
"lambdafs": "^2.0.3",
+ "minimist": "^1.2.5",
"remotion": "^2.0.2",
"ts-node": "^9.1.1",
"xns": "^2.0.7",
diff --git a/packages/lambda/remotion-lambda-cli.js b/packages/lambda/remotion-lambda-cli.js
new file mode 100644
index 0000000000..a7b816d181
--- /dev/null
+++ b/packages/lambda/remotion-lambda-cli.js
@@ -0,0 +1,10 @@
+#! /usr/bin/env node
+const {cli} = require('./dist/cli/index');
+
+cli()
+ .then(() => process.exit(0))
+ .catch((err) => {
+ // eslint-disable-next-line no-console
+ console.error(err);
+ process.exit(1);
+ });
diff --git a/packages/lambda/src/cli/help.ts b/packages/lambda/src/cli/help.ts
new file mode 100644
index 0000000000..5c2a0ef9f6
--- /dev/null
+++ b/packages/lambda/src/cli/help.ts
@@ -0,0 +1,17 @@
+import chalk from 'chalk';
+import {Log} from './log';
+
+const packagejson = require('../../package.json');
+
+export const printHelp = () => {
+ Log.info(
+ `@remotion/lambda ${
+ packagejson.version
+ } © ${new Date().getFullYear()} Jonny Burger`
+ );
+ Log.info();
+ Log.info('Available commands:');
+ Log.info('');
+ Log.info('@remotion/lambda deploy <index-file.ts>');
+ Log.info(chalk.gray('Deploy a lambda.'));
+};
diff --git a/packages/lambda/src/cli/index.ts b/packages/lambda/src/cli/index.ts
new file mode 100644
index 0000000000..d2ff625f3e
--- /dev/null
+++ b/packages/lambda/src/cli/index.ts
@@ -0,0 +1,14 @@
+import minimist from 'minimist';
+import {printHelp} from './help';
+
+type LambdaCommandLineOptions = {
+ help: boolean;
+};
+
+const parsedCli = minimist<LambdaCommandLineOptions>(process.argv.slice(2));
+
+export const cli = async () => {
+ if (parsedCli.help) {
+ printHelp();
+ }
+};
diff --git a/packages/lambda/src/cli/log.ts b/packages/lambda/src/cli/log.ts
new file mode 100644
index 0000000000..50c8e54d83
--- /dev/null
+++ b/packages/lambda/src/cli/log.ts
@@ -0,0 +1,29 @@
+/* eslint-disable no-console */
+
+import chalk from 'chalk';
+import {Internals} from 'remotion';
+
+// TODO: Move logging into core?
+
+export const Log = {
+ verbose: (...args: Parameters<typeof console.log>) => {
+ if (Internals.Logging.isEqualOrBelowLogLevel('verbose')) {
+ return console.log(chalk.blueBright(...args));
+ }
+ },
+ info: (...args: Parameters<typeof console.log>) => {
+ if (Internals.Logging.isEqualOrBelowLogLevel('info')) {
+ return console.log(...args);
+ }
+ },
+ warn: (...args: Parameters<typeof console.log>) => {
+ if (Internals.Logging.isEqualOrBelowLogLevel('warn')) {
+ return console.warn(chalk.yellow(...args));
+ }
+ },
+ error: (...args: Parameters<typeof console.log>) => {
+ if (Internals.Logging.isEqualOrBelowLogLevel('error')) {
+ return console.error(chalk.red(...args));
+ }
+ },
+};