Skip to content

🎥 Make videos programmatically with React

init improvements

Jonny Burgerd876c9685a81
diff --git a/packages/create-video/package.json b/packages/create-video/package.json
index bfc987cc55..b2e974d643 100644
--- a/packages/create-video/package.json
+++ b/packages/create-video/package.json
@@ -12,7 +12,8 @@
],
"scripts": {
"build": "tsc -d",
- "watch": "tsc -w"
+ "watch": "tsc -w",
+ "test": "eslint src --ext ts,tsx"
},
"author": "",
"license": "SEE LICENSE IN LICENSE.md",
diff --git a/packages/create-video/src/init.ts b/packages/create-video/src/init.ts
index 6f3228be57..22a4231023 100644
--- a/packages/create-video/src/init.ts
+++ b/packages/create-video/src/init.ts
@@ -80,21 +80,20 @@ function assertValidName(folderName: string) {
}
}
-async function assertFolderEmptyAsync(
- projectRoot: string,
- folderName?: string
-) {
+function assertFolderEmptyAsync(projectRoot: string): {exists: boolean} {
const conflicts = fs
.readdirSync(projectRoot)
.filter((file: string) => !/\.iml$/.test(file));
- if (conflicts.length) {
- const message = 'Try using a new directory name, or moving these files.';
+ if (conflicts.length > 0) {
Log.newLine();
- Log.error(message);
+ Log.error(`Something already exists at "${projectRoot}"`);
+ Log.error('Try using a new directory name, or moving these files.');
Log.newLine();
- process.exit(1);
+ return {exists: true};
}
+
+ return {exists: false};
}
const shouldUseYarn = (): boolean => {
@@ -125,14 +124,17 @@ const initGitRepoAsync = async (
await execa('git', ['rev-parse', '--is-inside-work-tree'], {
cwd: root,
});
- !flags.silent &&
+ if (!flags.silent) {
Log.info(
'New project is already inside of a git repo, skipping git init.'
);
+ }
} catch (e) {
if ((e as {errno: string}).errno === 'ENOENT') {
- !flags.silent &&
+ if (!flags.silent) {
Log.warn('Unable to initialize git repo. `git` not in PATH.');
+ }
+
return false;
}
}
@@ -140,7 +142,9 @@ const initGitRepoAsync = async (
// not in git tree, so let's init
try {
await execa('git', ['init'], {cwd: root});
- !flags.silent && Log.info('Initialized a git repository.');
+ if (!flags.silent) {
+ Log.info('Initialized a git repository.');
+ }
if (flags.commit) {
await execa('git', ['add', '--all'], {cwd: root, stdio: 'ignore'});
@@ -162,7 +166,7 @@ const initGitRepoAsync = async (
}
};
-const resolveProjectRootAsync = async () => {
+const resolveProjectRootAsync = async (): Promise<[string, string]> => {
let projectName = '';
try {
const {answer} = await prompts({
@@ -197,7 +201,9 @@ const resolveProjectRootAsync = async () => {
await fs.ensureDir(projectRoot);
- await assertFolderEmptyAsync(projectRoot, folderName);
+ if (assertFolderEmptyAsync(projectRoot).exists) {
+ return resolveProjectRootAsync();
+ }
return [projectRoot, folderName];
};
@@ -213,7 +219,7 @@ export const init = async () => {
)
) + 2;
- const template = await selectAsync(
+ const selectedTemplate = await selectAsync(
{
message: 'Choose a template:',
optionsPerPage: 20,
@@ -234,7 +240,7 @@ export const init = async () => {
);
try {
- const emitter = degit(`https://github.com/${template}`);
+ const emitter = degit(`https://github.com/${selectedTemplate}`);
await emitter.clone(projectRoot);
Log.info(`Cloned template into ${projectRoot}`);
@@ -251,14 +257,18 @@ export const init = async () => {
Log.info('> yarn');
const promise = execa('yarn', [], {
cwd: projectRoot,
+ stdio: 'inherit',
+ env: {...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1'},
});
promise.stderr?.pipe(process.stderr);
promise.stdout?.pipe(process.stdout);
await promise;
} else {
Log.info('> npm install');
- const promise = execa('npm', ['install'], {
+ const promise = execa('npm', ['install', '--no-fund'], {
+ stdio: 'inherit',
cwd: projectRoot,
+ env: {...process.env, ADBLOCK: '1', DISABLE_OPENCOLLECTIVE: '1'},
});
promise.stderr?.pipe(process.stderr);
promise.stdout?.pipe(process.stdout);
@@ -266,10 +276,14 @@ export const init = async () => {
}
await initGitRepoAsync(projectRoot, {
- silent: false,
+ silent: true,
commit: true,
});
+ Log.info();
+ Log.info();
+ Log.info();
+ Log.info();
Log.info(`Welcome to ${chalk.blue('Remotion')}!`);
Log.info(`✨ Your video has been created at ${chalk.blue(folderName)}.\n`);
@@ -281,8 +295,8 @@ export const init = async () => {
Log.info(chalk.blue(shouldUseYarn() ? 'yarn build' : 'npm run build'));
Log.info('');
Log.info(
- 'Read the documentation at',
- chalk.underline('https://remotion.dev')
+ 'Docs to get you started:',
+ chalk.underline('https://www.remotion.dev/docs/the-fundamentals')
);
Log.info('Enjoy Remotion!');
};
diff --git a/packages/create-video/src/log.ts b/packages/create-video/src/log.ts
index d8f0f325f5..cb16f0eca7 100644
--- a/packages/create-video/src/log.ts
+++ b/packages/create-video/src/log.ts
@@ -3,7 +3,7 @@
import chalk from 'chalk';
export const Log = {
- chalk: chalk,
+ chalk,
verbose: (...args: Parameters<typeof console.log>) => {
return console.log(chalk.blueBright(...args));
},
diff --git a/packages/create-video/src/prompts.ts b/packages/create-video/src/prompts.ts
index 0467810ee7..8bc8124520 100644
--- a/packages/create-video/src/prompts.ts
+++ b/packages/create-video/src/prompts.ts
@@ -33,7 +33,7 @@ export async function selectAsync(
{
limit: 11,
...questions,
- // @ts-ignore: onRender not in the types
+ // @ts-expect-error: onRender not in the types
onRender(this: {
cursor: number;
firstRender: boolean;
@@ -53,6 +53,7 @@ export async function selectAsync(
this.cursor++;
if (this.cursor > this.choices.length - 1) break;
}
+
this.fire();
// Without this, the value will be `0` instead of a string.
this.value = (this.choices[this.cursor] || {}).value;
@@ -60,11 +61,13 @@ export async function selectAsync(
// Support up arrow and `k` key -- no looping
this.up = () => {
let next = this.cursor;
+ // eslint-disable-next-line no-constant-condition
while (true) {
if (next <= 0) break;
next--;
if (!this.choices[next].disabled) break;
}
+
if (!this.choices[next].disabled && next !== this.cursor) {
this.moveCursor(next);
this.render();
@@ -76,11 +79,13 @@ export async function selectAsync(
// Support down arrow and `j` key -- no looping
this.down = () => {
let next = this.cursor;
+ // eslint-disable-next-line no-constant-condition
while (true) {
if (next >= this.choices.length - 1) break;
next++;
if (!this.choices[next].disabled) break;
}
+
if (!this.choices[next].disabled && next !== this.cursor) {
this.moveCursor(next);
this.render();
@@ -98,12 +103,13 @@ export async function selectAsync(
next = (next + 1) % this.choices.length;
if (!this.choices[next].disabled) break;
}
- if (!this.choices[next].disabled) {
- this.moveCursor(next);
- this.render();
- } else {
+
+ if (this.choices[next].disabled) {
// unexpected
this.bell();
+ } else {
+ this.moveCursor(next);
+ this.render();
}
};
}