Skip to content

🎥 Make videos programmatically with React

update package.json and del create-directory

Shankhadeep Deye51d98682d3d
diff --git a/package.json b/package.json
index 0be6b1a225..6523b622d6 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,6 @@
"@react-three/fiber": "^6.1.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
- "strip-ansi": "^3.0.1",
"three": "^0.128.0"
}
}
diff --git a/packages/create-video/package.json b/packages/create-video/package.json
index 8f2f067f58..0f3914e3af 100644
--- a/packages/create-video/package.json
+++ b/packages/create-video/package.json
@@ -26,7 +26,6 @@
"@jonny/eslint-config": "^2.1.233",
"@types/fs-extra": "^9.0.11",
"@types/node": "^15.0.1",
- "@types/npm-package-arg": "^6.1.0",
"@types/prompts": "^2.0.12",
"eslint": "^7.15.0",
"ts-node": "^9.1.1",
diff --git a/packages/create-video/src/create-directory.ts b/packages/create-video/src/create-directory.ts
deleted file mode 100644
index 1ab5052858..0000000000
--- a/packages/create-video/src/create-directory.ts
+++ /dev/null
@@ -1,65 +0,0 @@
-import fs from 'fs-extra';
-import * as path from 'path';
-
-const TOLERABLE_FILES = [
- // System
- '.DS_Store',
- 'Thumbs.db',
- // Git
- '.git',
- '.gitattributes',
- '.gitignore',
- // Project
- '.npmignore',
- '.travis.yml',
- 'LICENSE',
- 'docs',
- '.idea',
- // Package manager
- 'npm-debug.log',
- 'yarn-debug.log',
- 'yarn-error.log',
-];
-
-export function validateName(name?: string): string | true {
- if (typeof name !== 'string' || name === '') {
- return 'The project name can not be empty.';
- }
- if (!/^[a-z0-9@.\-_]+$/i.test(name)) {
- return 'The project name can only contain URL-friendly characters (alphanumeric and @ . - _)';
- }
- return true;
-}
-
-export function getConflictsForDirectory(
- projectRoot: string,
- tolerableFiles: string[] = TOLERABLE_FILES
-): string[] {
- return fs
- .readdirSync(projectRoot)
- .filter(
- (file: string) => !(/\.iml$/.test(file) || tolerableFiles.includes(file))
- );
-}
-
-export async function assertFolderEmptyAsync({
- projectRoot,
- folderName = path.dirname(projectRoot),
- overwrite,
-}: {
- projectRoot: string;
- folderName?: string;
- overwrite: boolean;
-}): Promise<boolean> {
- const conflicts = getConflictsForDirectory(projectRoot);
- if (conflicts.length) {
- if (overwrite) {
- await Promise.all(
- conflicts.map((conflict) => fs.remove(path.join(projectRoot, conflict)))
- );
- return true;
- }
- return false;
- }
- return true;
-}
diff --git a/packages/create-video/src/init-v2.ts b/packages/create-video/src/init.ts
similarity index 91%
rename from packages/create-video/src/init-v2.ts
rename to packages/create-video/src/init.ts
index 9cdc29be37..9078b5652f 100644
--- a/packages/create-video/src/init-v2.ts
+++ b/packages/create-video/src/init.ts
@@ -3,7 +3,6 @@ import execa from 'execa';
import fs from 'fs-extra';
import path from 'path';
import stripAnsi from 'strip-ansi';
-import * as CreateDirectory from './create-directory';
import {Log} from './log';
import prompts, {selectAsync} from './prompts';
@@ -42,8 +41,18 @@ function padEnd(str: string, width: number): string {
return str + Array(len + 1).join(' ');
}
+export function validateName(name?: string): string | true {
+ if (typeof name !== 'string' || name === '') {
+ return 'The project name can not be empty.';
+ }
+ if (!/^[a-z0-9@.\-_]+$/i.test(name)) {
+ return 'The project name can only contain URL-friendly characters (alphanumeric and @ . - _)';
+ }
+ return true;
+}
+
function assertValidName(folderName: string) {
- const validation = CreateDirectory.validateName(folderName);
+ const validation = validateName(folderName);
if (typeof validation === 'string') {
throw new Error(
`Cannot create an app named ${chalk.red(
@@ -57,16 +66,14 @@ async function assertFolderEmptyAsync(
projectRoot: string,
folderName?: string
) {
- if (
- !(await CreateDirectory.assertFolderEmptyAsync({
- projectRoot,
- folderName,
- overwrite: false,
- }))
- ) {
+ 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.';
Log.newLine();
- Log.info(message);
+ Log.error(message);
Log.newLine();
process.exit(1);
}
@@ -145,9 +152,7 @@ const resolveProjectRootAsync = async () => {
message: 'What would you like to name your video?',
initial: 'my-video',
validate: (name) => {
- const validation = CreateDirectory.validateName(
- path.basename(path.resolve(name))
- );
+ const validation = validateName(path.basename(path.resolve(name)));
if (typeof validation === 'string') {
return 'Invalid project name: ' + validation;
}