@@ -6,27 +6,34 @@ const repoName = process.argv[2]
66const gitCheckoutCommand = `git clone --depth 1 git@github.com:rahadkc/nextjs-typescript-redux-jest-cypress-starter.git ${ repoName } `
77const installDepsCommand = `cd ${ repoName } && npm install`
88
9- console . log ( `Cloning the repository ... ${ repoName } ` )
10- const checkedOut = runCommand ( gitCheckoutCommand )
11- if ( ! checkedOut ) exitProcess ( - 1 )
12-
13- console . log ( `Installing dependencies for ${ repoName } ` )
14- const installDeps = runCommand ( installDepsCommand )
15- if ( ! installDeps ) exitProcess ( - 1 )
9+ function colorizeText ( text , colorCode ) {
10+ return `\x1b[${ colorCode } m${ text } \x1b[0m`
11+ }
1612
17- console . log ( 'Congratulations! you are ready. Follow the following command to start' )
18- console . log ( `cd ${ repoName } && npm run dev `)
13+ function runCommandWithLoading ( command , loadingMessage , colorCode ) {
14+ process . stdout . write ( ` ${ colorizeText ( loadingMessage , colorCode ) } ... `)
1915
20- function runCommand ( command ) {
2116 try {
22- execSync ( `${ command } ` , { studio : 'inherit' } )
17+ execSync ( `${ command } ` , { stdio : 'inherit' } )
18+ process . stdout . write ( colorizeText ( ' Done\n' , '32' ) ) // Green color for success
2319 } catch ( error ) {
24- console . log ( `Failed to execute command - ${ command } ` , error )
25- return false
20+ process . stdout . write ( colorizeText ( ' Failed\n' , '31' ) ) // Red color for failure
21+ console . error ( `Failed to execute command - ${ command } ` , error )
22+ exitProcess ( - 1 )
2623 }
27- return true
2824}
2925
26+ console . log ( colorizeText ( `Cloning the repository ... ${ repoName } ` , '34' ) ) // Blue color for cloning
27+ runCommandWithLoading ( gitCheckoutCommand , 'Cloning the repository' , '34' )
28+
29+ console . log ( colorizeText ( `Installing dependencies for ${ repoName } ` , '36' ) ) // Cyan color for installing
30+ runCommandWithLoading ( installDepsCommand , 'Installing dependencies' , '36' )
31+
32+ console . log ( colorizeText ( 'Congratulations! You are ready to go.' , '32' ) ) // Green color for success
33+ console . log ( 'To start the project, run the following commands:' )
34+ console . log ( `cd ${ repoName } && npm run dev` )
35+ console . log ( colorizeText ( 'Your project will be available at http://localhost:3050' , '33' ) ) // Yellow color for info
36+
3037function exitProcess ( code ) {
3138 process . exit ( code )
3239}
0 commit comments