Skip to content

🎥 Make videos programmatically with React

add init-v2 package

Shankhadeep Deyfafed6fa7b97
diff --git a/packages/create-video/bin.js b/packages/create-video/bin.js
old mode 100644
new mode 100755
index 577a3ff301..874c6b3d2a
--- a/packages/create-video/bin.js
+++ b/packages/create-video/bin.js
@@ -1,6 +1,6 @@
#! /usr/bin/env node
-const {init} = require('./dist/init');
+const {init} = require('./dist/init-v2');
init()
.then(() => process.exit(0))
.catch((err) => {
diff --git a/packages/create-video/src/init-v2.ts b/packages/create-video/src/init-v2.ts
index 5660876c2a..11cd59f731 100644
--- a/packages/create-video/src/init-v2.ts
+++ b/packages/create-video/src/init-v2.ts
@@ -1 +1,45 @@
-export const init = async () => {};
+import chalk from 'chalk';
+import path from 'path';
+import prompts from 'prompts';
+import {validateName} from './create-directory';
+
+export const init = async () => {
+ let projectName = process.argv[2];
+
+ console.log(projectName, 'new');
+ if (!projectName) {
+ try {
+ const {answer} = await prompts({
+ type: 'text',
+ name: 'answer',
+ message: 'What would you like to name your app?',
+ initial: 'my-app',
+ validate: (name) => {
+ const validation = validateName(path.basename(path.resolve(name)));
+ if (typeof validation === 'string') {
+ return 'Invalid project name: ' + validation;
+ }
+ return true;
+ },
+ });
+
+ if (typeof answer === 'string') {
+ projectName = answer.trim();
+ }
+ } catch (error) {
+ // Handle the aborted message in a custom way.
+ console.log('nice');
+ if (error.code !== 'ABORTED') {
+ throw error;
+ }
+ }
+ const validation = validateName(projectName);
+ if (typeof validation === 'string') {
+ throw new Error(
+ `Cannot create an app named ${chalk.red(
+ `"${projectName}"`
+ )}. ${validation}`
+ );
+ }
+ }
+};