@@ -5,7 +5,7 @@ import chalk from "chalk"
55import inquirer from "inquirer"
66import selectShell from "select-shell"
77import ora from "ora"
8- import { camelCaseToDash } from "../utils/functions"
8+ import { AppNameToNodePackageName } from "../utils/functions"
99import fs from "fs"
1010
1111enum TYPE_OF_APP {
@@ -45,8 +45,8 @@ function isValidateComponentNaming(name: string) {
4545 if ( ! name ) {
4646 shell . echo ( chalk . redBright ( "Please provide name of your app." ) )
4747 return false
48- } else if ( ! / ^ [ a - z 0 - 9 ] + $ / i. test ( name ) ) {
49- shell . echo ( chalk . redBright ( "App name should be alphaNumeric ." ) )
48+ } else if ( ! / ^ [ a - z 0 - 9 \- _ ] + $ / i. test ( name ) ) {
49+ shell . echo ( chalk . redBright ( "App name cannot contain special symbols ." ) )
5050 return false
5151 } else if ( fs . existsSync ( `./${ name } ` ) ) {
5252 shell . echo ( chalk . redBright ( "App name with the same name already exists." ) )
@@ -59,7 +59,7 @@ async function nameTheApp() {
5959 return inquirer . prompt ( [
6060 {
6161 name : "value" ,
62- message : "Name of your app (alphaNumeric): "
62+ message : "Name of your app: "
6363 }
6464 ] )
6565}
@@ -89,33 +89,36 @@ async function isWantStyle() {
8989 ] )
9090}
9191
92- function createApp ( gitURL : string , nameOfApp : string ) {
92+ function createApp ( gitURL : string , nameOfApp : string , defaultNodePackageName : string ) {
9393 const gitDownSpinner = ora ( "Creating app: " + nameOfApp + "...\n" )
9494 gitDownSpinner . start ( )
9595 shell . exec ( `git clone ${ gitURL } ${ nameOfApp } ` , ( code : number , stdout : string , stderr : string ) => {
9696 gitDownSpinner . stop ( )
97- flowUp ( code , stdout , stderr , nameOfApp )
97+ if ( code !== 0 ) {
98+ shell . echo ( chalk . cyanBright ( `code: ${ code } ` ) )
99+ shell . echo ( chalk . cyanBright ( `Program output: ${ stdout } ` ) )
100+ shell . echo ( chalk . cyanBright ( `Program stderr: ${ stderr } ` ) )
101+ }
102+ flowUp ( nameOfApp , defaultNodePackageName )
98103 } )
99104}
100105
101- function flowUp ( code : number , stdout : string , stderr : string , nameOfApp : string ) {
106+ function flowUp ( nameOfApp : string , defaultNodePackageName : string ) {
102107 const projectCleanupSpinner = ora ( "Project Cleanup...\n" )
103108 projectCleanupSpinner . start ( )
104- if ( code !== 0 ) {
105- shell . echo ( chalk . cyanBright ( `code: ${ code } ` ) )
106- shell . echo ( chalk . cyanBright ( `Program output: ${ stdout } ` ) )
107- shell . echo ( chalk . cyanBright ( `Program stderr: ${ stderr } ` ) )
108- }
109+
109110
110111 setTimeout ( ( ) => {
111- shell . sed ( "-i" , "flow-react-ts" , camelCaseToDash ( `${ nameOfApp } ` ) , `./${ nameOfApp } /package.json` )
112-
112+ shell . sed ( "-i" , defaultNodePackageName , AppNameToNodePackageName ( `${ nameOfApp } ` ) , `./${ nameOfApp } /package.json` )
113113 shell . rm ( "-rf" , `${ nameOfApp } /.git` )
114114 projectCleanupSpinner . stop ( )
115115
116- shell . echo ( chalk . greenBright ( nameOfApp + " created." ) )
117- shell . echo ( chalk . greenBright ( "cd " + nameOfApp + " and npm install and npm run dev." ) )
116+ const npmInstallSpinner = ora ( "npm install...just a moment, please.\n" ) . start ( )
117+ shell . cd ( nameOfApp )
118+ shell . exec ( "npm install" )
119+ npmInstallSpinner . stop ( )
118120
121+ shell . echo ( chalk . greenBright ( nameOfApp + " created." ) )
119122 process . exit ( 0 )
120123 } , 2000 )
121124}
@@ -142,6 +145,17 @@ function getGitURL(selectValue: number, style: string): string {
142145 }
143146}
144147
148+ function getDefaultNodePackageName ( selectValue : number ) : string {
149+ switch ( selectValue ) {
150+ case TYPE_OF_APP . REACT :
151+ return "flow-react-ts"
152+ case TYPE_OF_APP . NEXT :
153+ return "flow-next-ts"
154+ default :
155+ invalidProgramInput ( )
156+ }
157+ }
158+
145159function selectTheNameOfTheApp ( ) {
146160 appList . on ( "select" , async ( options ) => {
147161 const isStyle = await isWantStyle ( )
@@ -157,7 +171,8 @@ function selectTheNameOfTheApp() {
157171 return process . exit ( 0 )
158172 }
159173 const gitURL = getGitURL ( options [ 0 ] . value , style )
160- createApp ( gitURL , nameOfApp )
174+ const defaultNodePackageName = getDefaultNodePackageName ( options [ 0 ] . value )
175+ createApp ( gitURL , nameOfApp , defaultNodePackageName )
161176 } )
162177}
163178
0 commit comments