@@ -369,6 +369,8 @@ async function init() {
369369
370370 const cancel = ( ) => prompts . cancel ( 'Operation cancelled' ) ;
371371
372+ prompts . intro ( `${ blueBright ( 'Vite+' ) } The Unified Toolchain for the Web` ) ;
373+
372374 // --app and --lib should inside monorepo
373375 if ( isCreateAppOrLib ) {
374376 const monorepoRoot = findMonorepoRoot ( ) ;
@@ -525,37 +527,63 @@ async function init() {
525527 const rawRoot = path . join ( cwd , rawTargetDir ) ;
526528 const cdProjectName = path . relative ( cwd , rawRoot ) ;
527529 const appOrLibName = path . relative ( cwd , root ) ;
528- prompts . log . step ( `Scaffolding project in ${ appOrLibName } ...` ) ;
530+ const isMonorepo = argCreateMonorepo ?? isCreateAppOrLib ;
529531
530532 // 5. Create project
531533 if ( argCreateLib ) {
534+ prompts . log . step ( `Scaffolding library in ${ appOrLibName } ...` ) ;
532535 // create a library project
533536 initMonorepoLib ( root , packageName ) ;
534537 } else {
538+ prompts . log . step ( `Scaffolding project with ${ template } in ${ appOrLibName } ...` ) ;
535539 // use create-vite to create a app project
536540 const createViteBin = fileURLToPath ( import . meta. resolve ( 'create-vite/index.js' ) ) ;
537- const { status, stderr, stdout } = spawn . sync ( 'node' , [
538- createViteBin ,
539- '--template' ,
540- template ! ,
541- targetDir ,
542- ] , {
543- // stdio: 'inherit',
544- stdio : 'pipe' ,
545- } ) ;
546- if ( status && status > 0 ) {
547- console . error ( stderr . toString ( ) ) ;
548- console . error ( stdout . toString ( ) ) ;
549- process . exit ( status ) ;
541+ const { customCommand } = FRAMEWORKS . flatMap ( ( f ) => f . variants ) . find ( ( v ) => v . name === template ) ?? { } ;
542+ if ( customCommand ) {
543+ // print the custom command
544+ prompts . log . info ( customCommand . replace ( 'TARGET_DIR' , appOrLibName ) + ' ...' ) ;
545+ const cwd = path . dirname ( root ) ;
546+ // fs.mkdirSync(cwd, { recursive: true });
547+ const appName = isMonorepo ? path . basename ( targetDir ) : targetDir ;
548+ const createViteArgs = [
549+ createViteBin ,
550+ '--overwrite' ,
551+ '--template' ,
552+ template ! ,
553+ appName ,
554+ ] ;
555+ const { status } = spawn . sync ( 'node' , createViteArgs , {
556+ stdio : 'inherit' ,
557+ cwd,
558+ } ) ;
559+ if ( status && status > 0 ) {
560+ process . exit ( status ) ;
561+ }
562+ } else {
563+ const createViteArgs = [
564+ createViteBin ,
565+ '--overwrite' ,
566+ '--template' ,
567+ template ! ,
568+ targetDir ,
569+ ] ;
570+ const { status, stderr, stdout } = spawn . sync ( 'node' , createViteArgs , {
571+ stdio : 'pipe' ,
572+ } ) ;
573+ if ( status && status > 0 ) {
574+ prompts . log . error ( stderr . toString ( ) ) ;
575+ prompts . log . error ( stdout . toString ( ) ) ;
576+ process . exit ( status ) ;
577+ }
550578 }
551579
552- await fixPackageJsonForVitePlus ( root , selectedPackageManager , argCreateMonorepo ?? isCreateAppOrLib ) ;
580+ await fixPackageJsonForVitePlus ( root , selectedPackageManager , isMonorepo ) ;
553581 }
554582
555583 // first init, ask user to init git
556584 if ( ! isCreateAppOrLib ) {
557585 const initGit = typeof argGit === 'boolean' ? argGit : await prompts . confirm ( {
558- message : `Init git? (git init ${ cdProjectName } )` ,
586+ message : `Initialize git repository ? (git init ${ cdProjectName } )` ,
559587 initialValue : true ,
560588 } ) ;
561589 if ( prompts . isCancel ( initGit ) ) return cancel ( ) ;
@@ -738,6 +766,10 @@ async function fixPackageJsonForVitePlus(projectDir: string, selectedPackageMana
738766 if ( ! pkg . scripts ?. ready ) {
739767 pkg . scripts . ready = 'vite lint --type-aware && vite run build && vite test --passWithNoTests' ;
740768 }
769+ // fix empty pkg.name
770+ if ( ! pkg . name ) {
771+ pkg . name = path . basename ( projectDir ) ;
772+ }
741773 return JSON . stringify ( pkg , null , 2 ) + '\n' ;
742774 } ) ;
743775
@@ -750,6 +782,11 @@ async function fixPackageJsonForVitePlus(projectDir: string, selectedPackageMana
750782 copy ( path . join ( pkgRoot , 'templates/config/.npmrc' ) , path . join ( projectDir , '.npmrc' ) ) ;
751783 }
752784 }
785+
786+ // remove package-lock.json when package manager is not npm
787+ if ( selectedPackageManager !== 'npm' ) {
788+ fs . rmSync ( path . join ( projectDir , 'package-lock.json' ) , { force : true } ) ;
789+ }
753790}
754791
755792async function setPackageManager ( projectDir : string , packageManager : string ) {
0 commit comments