@@ -15,6 +15,15 @@ import (
1515	"github.com/spf13/cobra" 
1616)
1717
18+ func  init () {
19+ 	rootCmd .AddCommand (createCmd )
20+ 	createCmd .Flags ().BoolVarP (
21+ 		& useCustomTemplate ,
22+ 		"template" , "t" , false ,
23+ 		"enables to use custom backend and frontend templates" ,
24+ 	)
25+ }
26+ 
1827// createCmd represents the `create` command. 
1928var  createCmd  =  & cobra.Command {
2029	Use :     "create" ,
@@ -29,21 +38,46 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
2938	// Start message. 
3039	cgapp .ShowMessage (
3140		"" ,
32- 		fmt .Sprintf ("Create a new project via Create Go App CLI v%v..." , registry .CLIVersion ),
41+ 		fmt .Sprintf (
42+ 			"Create a new project via Create Go App CLI v%v..." ,
43+ 			registry .CLIVersion ,
44+ 		),
3345		true , true ,
3446	)
3547
3648	// Start survey. 
37- 	if  err  :=  survey .Ask (
38- 		registry .CreateQuestions , & createAnswers , survey .WithIcons (surveyIconsConfig ),
39- 	); err  !=  nil  {
40- 		return  cgapp .ShowError (err .Error ())
41- 	}
49+ 	if  useCustomTemplate  {
50+ 		// Custom survey. 
51+ 		if  err  :=  survey .Ask (
52+ 			registry .CustomCreateQuestions ,
53+ 			& customCreateAnswers ,
54+ 			survey .WithIcons (surveyIconsConfig ),
55+ 		); err  !=  nil  {
56+ 			return  cgapp .ShowError (err .Error ())
57+ 		}
4258
43- 	// Define variables for better display. 
44- 	backend  =  strings .Replace (createAnswers .Backend , "/" , "_" , - 1 )
45- 	frontend  =  createAnswers .Frontend 
46- 	proxy  =  createAnswers .Proxy 
59+ 		// Define variables for better display. 
60+ 		backend  =  customCreateAnswers .Backend 
61+ 		frontend  =  customCreateAnswers .Frontend 
62+ 		proxy  =  customCreateAnswers .Proxy 
63+ 	} else  {
64+ 		// Default survey. 
65+ 		if  err  :=  survey .Ask (
66+ 			registry .CreateQuestions ,
67+ 			& createAnswers ,
68+ 			survey .WithIcons (surveyIconsConfig ),
69+ 		); err  !=  nil  {
70+ 			return  cgapp .ShowError (err .Error ())
71+ 		}
72+ 
73+ 		// Define variables for better display. 
74+ 		backend  =  fmt .Sprintf (
75+ 			"github.com/create-go-app/%v-go-template" ,
76+ 			strings .Replace (createAnswers .Backend , "/" , "_" , - 1 ),
77+ 		)
78+ 		frontend  =  createAnswers .Frontend 
79+ 		proxy  =  createAnswers .Proxy 
80+ 	}
4781
4882	// Start timer. 
4983	startTimer  :=  time .Now ()
@@ -53,10 +87,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
5387	*/ 
5488
5589	// Clone backend files from git repository. 
56- 	if  err  :=  cgapp .GitClone (
57- 		"backend" ,
58- 		fmt .Sprintf ("github.com/create-go-app/%v-go-template" , backend ),
59- 	); err  !=  nil  {
90+ 	if  err  :=  cgapp .GitClone ("backend" , backend ); err  !=  nil  {
6091		return  cgapp .ShowError (err .Error ())
6192	}
6293
@@ -72,13 +103,21 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
72103	*/ 
73104
74105	if  frontend  !=  "none"  {
75- 		// Create frontend files. 
76- 		if  err  :=  cgapp .ExecCommand (
77- 			"npm" ,
78- 			[]string {"init" , "@vitejs/app" , "frontend" , "--" , "--template" , frontend },
79- 			true ,
80- 		); err  !=  nil  {
81- 			return  cgapp .ShowError (err .Error ())
106+ 		// Checking, if use custom templates. 
107+ 		if  useCustomTemplate  {
108+ 			// Clone frontend files from git repository. 
109+ 			if  err  :=  cgapp .GitClone ("frontend" , frontend ); err  !=  nil  {
110+ 				return  cgapp .ShowError (err .Error ())
111+ 			}
112+ 		} else  {
113+ 			// Create a default frontend template from Vite.js. 
114+ 			if  err  :=  cgapp .ExecCommand (
115+ 				"npm" ,
116+ 				[]string {"init" , "@vitejs/app" , "frontend" , "--" , "--template" , frontend },
117+ 				true ,
118+ 			); err  !=  nil  {
119+ 				return  cgapp .ShowError (err .Error ())
120+ 			}
82121		}
83122
84123		// Show success report. 
@@ -119,11 +158,13 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
119158	}
120159
121160	// Show success report. 
122- 	cgapp .ShowMessage (
123- 		"success" ,
124- 		fmt .Sprintf ("Web/Proxy server configuration for `%v` was created!" , proxy ),
125- 		false , false ,
126- 	)
161+ 	if  proxy  !=  "none"  {
162+ 		cgapp .ShowMessage (
163+ 			"success" ,
164+ 			fmt .Sprintf ("Web/Proxy server configuration for `%v` was created!" , proxy ),
165+ 			false , false ,
166+ 		)
167+ 	}
127168
128169	/* 
129170		The project's Ansible roles part creation. 
@@ -143,7 +184,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
143184	// Show success report. 
144185	cgapp .ShowMessage (
145186		"success" ,
146- 		"Ansible inventory, playbook and roles for deploying was created!" ,
187+ 		"Ansible inventory, playbook and roles for deploying your project  was created!" ,
147188		false , false ,
148189	)
149190
@@ -175,9 +216,10 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
175216		proxyList  =  []string {"traefik" , "nginx" }
176217	}
177218
178- 	// Delete unused roles  and backend  files. 
219+ 	// Delete unused roles, backend  and frontend  files. 
179220	cgapp .RemoveFolders ("roles" , proxyList )
180221	cgapp .RemoveFolders ("backend" , []string {".git" , ".github" })
222+ 	cgapp .RemoveFolders ("frontend" , []string {".git" , ".github" })
181223
182224	// Stop timer. 
183225	stopTimer  :=  cgapp .CalculateDurationTime (startTimer )
@@ -193,7 +235,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
193235		"* Please put credentials into the Ansible inventory file (`hosts.ini`) before you start deploying a project!" ,
194236		false , false ,
195237	)
196- 	if  frontend  !=  "none"  {
238+ 	if  ! useCustomTemplate   &&   frontend  !=  "none"  {
197239		cgapp .ShowMessage (
198240			"" ,
199241			fmt .Sprintf ("* Visit https://vitejs.dev/guide/ for more info about using the `%v` frontend template!" , frontend ),
@@ -202,7 +244,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
202244	}
203245	cgapp .ShowMessage (
204246		"" ,
205- 		"* A helpful documentation and next steps with your project is here https://create-go.app/" ,
247+ 		"* A helpful documentation and next steps with your project is here https://create-go.app/wiki " ,
206248		false , true ,
207249	)
208250	cgapp .ShowMessage (
@@ -213,7 +255,3 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
213255
214256	return  nil 
215257}
216- 
217- func  init () {
218- 	rootCmd .AddCommand (createCmd )
219- }
0 commit comments