11import { execSync } from 'child_process' ;
2+ import os from 'os' ;
23import path from 'path' ;
34import { exit } from 'process' ;
45
@@ -148,9 +149,8 @@ export async function checkAndUpdatePackage(
148149 spinner . text = t ( 'template_updating' ) . d (
149150 'Updating templates to latest...'
150151 ) ;
151- execSync ( `rm -rf node_modules/${ packageName } ` , {
152- cwd : packageJsonPath
153- } ) ;
152+ // Cross-platform: use fs-extra.removeSync instead of rm -rf
153+ fs . removeSync ( path . join ( packageJsonPath , 'node_modules' , packageName ) ) ;
154154 execSync ( `npm install ${ packageName } @latest` , {
155155 cwd : packageJsonPath ,
156156 stdio : 'inherit'
@@ -196,12 +196,9 @@ export async function checkAndUpdatePackage(
196196 spinner . start (
197197 t ( 'template_updating' ) . d ( 'Updating templates to latest...' )
198198 ) ;
199- execSync ( `rm -rf node_modules/${ packageName } ` , {
200- cwd : packageJsonPath
201- } ) ;
202- execSync ( `rm -rf package-lock.json` , {
203- cwd : packageJsonPath
204- } ) ;
199+ // Cross-platform: use fs-extra.removeSync instead of rm -rf
200+ fs . removeSync ( path . join ( packageJsonPath , 'node_modules' , packageName ) ) ;
201+ fs . removeSync ( path . join ( packageJsonPath , 'package-lock.json' ) ) ;
205202 execSync ( `npm install ${ packageName } @latest` , {
206203 cwd : packageJsonPath ,
207204 stdio : 'inherit'
@@ -277,6 +274,7 @@ export function getInitParamsFromArgv(argv: ArgumentsCamelCase): initParams {
277274 params . framework = undefined ;
278275 params . language = undefined ;
279276 params . yes = true ;
277+ params . installEsaCli = false ;
280278 }
281279
282280 if ( typeof a . name === 'string' ) params . name = a . name ;
@@ -298,6 +296,8 @@ export function getInitParamsFromArgv(argv: ArgumentsCamelCase): initParams {
298296 }
299297 if ( typeof a . git === 'boolean' ) params . git = Boolean ( a . git ) ;
300298 if ( typeof a . deploy === 'boolean' ) params . deploy = Boolean ( a . deploy ) ;
299+ if ( typeof a [ 'install-esa-cli' ] === 'boolean' )
300+ params . installEsaCli = Boolean ( a [ 'install-esa-cli' ] ) ;
301301
302302 return params ;
303303}
@@ -593,6 +593,20 @@ export const applyFileEdits = async (
593593} ;
594594
595595export const installESACli = async ( initParams : initParams ) => {
596+ if ( ! initParams . installEsaCli ) {
597+ const install = ( await promptParameter < boolean > ( {
598+ type : 'confirm' ,
599+ question : 'Do you want to install esa-cli as a dev dependency?' ,
600+ label : 'Install ESA CLI' ,
601+ defaultValue : false
602+ } ) ) as boolean ;
603+ initParams . installEsaCli = install ;
604+ }
605+
606+ if ( ! initParams . installEsaCli ) {
607+ return ;
608+ }
609+
596610 const targetPath = path . join ( process . cwd ( ) , initParams . name ) ;
597611 const res = await execCommand ( [ 'npm' , 'install' , '-D' , 'esa-cli' ] , {
598612 cwd : targetPath ,
@@ -859,6 +873,9 @@ export async function initializeProject(
859873
860874 const targetPath = path . join ( process . cwd ( ) , name ) ;
861875 if ( fs . existsSync ( targetPath ) ) {
876+ // Cross-platform delete command hint
877+ const isWindows = os . platform ( ) === 'win32' ;
878+ const deleteCmd = isWindows ? `rmdir /s /q "${ name } "` : `rm -rf "${ name } "` ;
862879 logger . block ( ) ;
863880 logger . tree ( [
864881 `${ chalk . bgRed ( ' ERROR ' ) } ${ chalk . bold . red (
@@ -871,7 +888,7 @@ export async function initializeProject(
871888 chalk . gray ( t ( 'try' ) . d ( 'Try one of the following:' ) ) ,
872889 `- ${ chalk . white ( t ( 'try_diff_name' ) . d ( 'Choose a different project name' ) ) } ` ,
873890 `- ${ chalk . white ( t ( 'try_remove' ) . d ( 'Remove the directory:' ) ) } ${ chalk . yellow (
874- `rm -rf " ${ name } ”`
891+ deleteCmd
875892 ) } `,
876893 `- ${ chalk . white (
877894 t ( 'try_another_dir' ) . d ( 'Run the command in another directory' )
0 commit comments