11import { Result } from 'meow' ;
2- import React , { useEffect , useState } from 'react' ;
2+ import React , { ReactNode , useEffect , useState } from 'react' ;
33import { Flags } from '../../lib/cli-flags.js' ;
44import { Box , Text } from 'ink' ;
55import Spinner from 'ink-spinner' ;
6- import { $ } from 'execa' ;
6+ import { $ , execa } from 'execa' ;
77import SelectInput from 'ink-select-input' ;
88import { Item } from '../../lib/types.js' ;
99import { UncontrolledTextInput } from 'ink-text-input' ;
@@ -14,11 +14,9 @@ export default function Create({cli}: {cli: Result<Flags>}) {
1414 const [ framework , setFramework ] = useState < string | undefined > ( undefined ) ;
1515 const [ projectName , setProjectName ] = useState < string | undefined > ( undefined ) ;
1616
17- const [ isCreated , setIsCreated ] = useState ( false ) ;
1817 const [ isFrameworkSelected , setIsFrameworkSelected ] = useState ( false ) ;
1918
20- const [ isPathValid , setIsPathValid ] = useState ( true ) ;
21- const [ isCloneFailed , setIsCloneFailed ] = useState ( false ) ;
19+ const [ message , setMessage ] = useState < ReactNode > ( ) ;
2220
2321 const frameworkItems : Item < string > [ ] = [
2422 {
@@ -48,15 +46,34 @@ export default function Create({cli}: {cli: Result<Flags>}) {
4846 async function createFromTemplate ( name : string ) {
4947 if ( framework === 'react' ) {
5048 // Clone the template repository
49+ setMessage (
50+ < Box >
51+ < Spinner type = "dots" />
52+ < Text >
53+ { ' ' }
54+ Creating a new Pulse Editor app using React template...
55+ </ Text >
56+ </ Box > ,
57+ ) ;
5158 try {
5259 await $ `git clone https://github.com/ClayPulse/pulse-editor-extension-template.git ${ name } ` ;
53- setIsCreated ( true ) ;
5460 } catch ( error ) {
55- setIsCloneFailed ( true ) ;
61+ setMessage (
62+ < Text color = "redBright" >
63+ ❌ Failed to clone the template. Please check your internet
64+ connection and try again.
65+ </ Text > ,
66+ ) ;
5667 return ;
5768 }
5869
5970 // Modify the package.json file to update the name
71+ setMessage (
72+ < Box >
73+ < Spinner type = "dots" />
74+ < Text > Initializing project...</ Text >
75+ </ Box > ,
76+ ) ;
6077 const packageJsonPath = path . join ( process . cwd ( ) , name , 'package.json' ) ;
6178 const packageJson = JSON . parse (
6279 fs . readFileSync ( packageJsonPath , 'utf8' ) ,
@@ -65,14 +82,42 @@ export default function Create({cli}: {cli: Result<Flags>}) {
6582
6683 // Write the modified package.json back to the file
6784 fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson , null , 2 ) ) ;
85+
86+ setMessage (
87+ < Box >
88+ < Spinner type = "dots" />
89+ < Text > Installing dependencies...</ Text >
90+ </ Box > ,
91+ ) ;
92+ // Run `npm i`
93+ try {
94+ await execa ( `npm install` , {
95+ cwd : path . join ( process . cwd ( ) , name ) ,
96+ } ) ;
97+ } catch ( error ) {
98+ setMessage (
99+ < Text color = "redBright" >
100+ ❌ Failed to install dependencies. Please check your internet
101+ connection and try again.
102+ </ Text > ,
103+ ) ;
104+ return ;
105+ }
106+ setMessage (
107+ < Text > 🚀 Pulse Editor React app project created successfully!</ Text > ,
108+ ) ;
68109 }
69110 }
70111
71112 if ( projectName ) {
72113 // Check if the project already exists
73114 const projectPath = path . join ( process . cwd ( ) , projectName ) ;
74115 if ( fs . existsSync ( projectPath ) ) {
75- setIsPathValid ( false ) ;
116+ setMessage (
117+ < Text color = "redBright" >
118+ ❌ A project with same name already exists in current path.
119+ </ Text > ,
120+ ) ;
76121 return ;
77122 }
78123 createFromTemplate ( projectName ) ;
@@ -116,31 +161,7 @@ export default function Create({cli}: {cli: Result<Flags>}) {
116161
117162 { projectName && (
118163 < >
119- { framework === 'react' &&
120- ( ! isPathValid ? (
121- < Text color = "redBright" >
122- ❌ A project with same name already exists in current path.
123- </ Text >
124- ) : isCloneFailed ? (
125- < Text color = "redBright" >
126- ❌ Failed to clone the template. Please check your internet
127- connection and try again.
128- </ Text >
129- ) : isCreated ? (
130- < Text >
131- 🚀 Pulse Editor React app project created successfully!
132- </ Text >
133- ) : (
134- < >
135- < Box >
136- < Spinner type = "dots" />
137- < Text >
138- { ' ' }
139- Creating a new Pulse Editor app using React template...
140- </ Text >
141- </ Box >
142- </ >
143- ) ) }
164+ { framework === 'react' && < > { message } </ > }
144165 { framework !== 'react' && (
145166 < Text >
146167 🚧 Currently not available. We'd like to invite you to work on
0 commit comments