@@ -10,8 +10,8 @@ const replaceAppNameInFiles = ['package.json', 'index.html'];
10
10
11
11
type InitViteOptions = {
12
12
dest : string ;
13
+ templateReference : string ; // Git branch name or path to a local template folder
13
14
appName : string ;
14
- branch : string ;
15
15
} ;
16
16
17
17
const downloadTemplateRepository = (
@@ -23,7 +23,7 @@ const downloadTemplateRepository = (
23
23
{
24
24
gitHubAccount : TEMPLATE_OWNER ,
25
25
repositoryName : TEMPLATE_REPO ,
26
- branch : options . branch ,
26
+ branch : options . templateReference ,
27
27
} ,
28
28
options . appName ,
29
29
options . dest ,
@@ -40,9 +40,20 @@ const extractViteTemplateFolder = (options: InitViteOptions): Promise<void> => {
40
40
) ;
41
41
} ;
42
42
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
+
43
54
const renameFolder = ( options : InitViteOptions ) : Promise < void > => {
44
55
CliUx . ux . info ( 'Rename your app folder...' ) ;
45
- const branchPath = options . branch . replace ( '/' , '-' ) ;
56
+ const branchPath = options . templateReference . replace ( '/' , '-' ) ;
46
57
47
58
return runCommand (
48
59
'mv' ,
@@ -69,7 +80,7 @@ const npmInstall = (options: InitViteOptions): Promise<void> => {
69
80
70
81
const cleanTemporaryFiles = ( options : InitViteOptions ) : Promise < void > => {
71
82
CliUx . ux . info ( 'Remove zip and unwanted files...' ) ;
72
- const branchPath = options . branch . replace ( '/' , '-' ) ;
83
+ const branchPath = options . templateReference . replace ( '/' , '-' ) ;
73
84
74
85
// Remove the archive
75
86
return runCommand ( 'rm' , [ `${ options . appName } .gz` ] , options . dest ) . then ( ( ) => {
@@ -83,8 +94,10 @@ const cleanTemporaryFiles = (options: InitViteOptions): Promise<void> => {
83
94
} ;
84
95
85
96
const 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 )
88
101
. then ( ( ) => renameFolder ( options ) )
89
102
. then ( ( ) => replaceAppName ( options ) )
90
103
. then ( ( ) => npmInstall ( options ) )
0 commit comments