@@ -10,8 +10,8 @@ const replaceAppNameInFiles = ['package.json', 'index.html'];
1010
1111type InitViteOptions = {
1212 dest : string ;
13+ templateReference : string ; // Git branch name or path to a local template folder
1314 appName : string ;
14- branch : string ;
1515} ;
1616
1717const downloadTemplateRepository = (
@@ -23,7 +23,7 @@ const downloadTemplateRepository = (
2323 {
2424 gitHubAccount : TEMPLATE_OWNER ,
2525 repositoryName : TEMPLATE_REPO ,
26- branch : options . branch ,
26+ branch : options . templateReference ,
2727 } ,
2828 options . appName ,
2929 options . dest ,
@@ -40,9 +40,20 @@ const extractViteTemplateFolder = (options: InitViteOptions): Promise<void> => {
4040 ) ;
4141} ;
4242
43+ const copyTemplateFiles = ( options : InitViteOptions ) : Promise < void > => {
44+ CliUx . ux . info ( 'Copying template source files...' ) ;
45+ const branchPath = options . templateReference . replace ( '/' , '-' ) ;
46+
47+ return runCommand (
48+ 'cp' ,
49+ [ '-r' , `${ TEMPLATE_REPO } -${ branchPath } /vite-template/` , options . appName ] ,
50+ options . dest ,
51+ ) ;
52+ } ;
53+
4354const renameFolder = ( options : InitViteOptions ) : Promise < void > => {
4455 CliUx . ux . info ( 'Rename your app folder...' ) ;
45- const branchPath = options . branch . replace ( '/' , '-' ) ;
56+ const branchPath = options . templateReference . replace ( '/' , '-' ) ;
4657
4758 return runCommand (
4859 'mv' ,
@@ -69,7 +80,7 @@ const npmInstall = (options: InitViteOptions): Promise<void> => {
6980
7081const cleanTemporaryFiles = ( options : InitViteOptions ) : Promise < void > => {
7182 CliUx . ux . info ( 'Remove zip and unwanted files...' ) ;
72- const branchPath = options . branch . replace ( '/' , '-' ) ;
83+ const branchPath = options . templateReference . replace ( '/' , '-' ) ;
7384
7485 // Remove the archive
7586 return runCommand ( 'rm' , [ `${ options . appName } .gz` ] , options . dest ) . then ( ( ) => {
@@ -83,8 +94,10 @@ const cleanTemporaryFiles = (options: InitViteOptions): Promise<void> => {
8394} ;
8495
8596const initializeViteApp = async ( options : InitViteOptions ) : Promise < void > => {
86- return downloadTemplateRepository ( options )
87- . then ( ( ) => extractViteTemplateFolder ( options ) )
97+ // If given a branch name, use
98+ // return downloadTemplateRepository(options)
99+ // .then(()=> extractViteTemplateFolder(options))
100+ return copyTemplateFiles ( options )
88101 . then ( ( ) => renameFolder ( options ) )
89102 . then ( ( ) => replaceAppName ( options ) )
90103 . then ( ( ) => npmInstall ( options ) )
0 commit comments