@@ -15,6 +15,15 @@ import (
15
15
"github.com/spf13/cobra"
16
16
)
17
17
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
+
18
27
// createCmd represents the `create` command.
19
28
var createCmd = & cobra.Command {
20
29
Use : "create" ,
@@ -29,21 +38,46 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
29
38
// Start message.
30
39
cgapp .ShowMessage (
31
40
"" ,
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
+ ),
33
45
true , true ,
34
46
)
35
47
36
48
// 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
+ }
42
58
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
+ }
47
81
48
82
// Start timer.
49
83
startTimer := time .Now ()
@@ -53,10 +87,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
53
87
*/
54
88
55
89
// 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 {
60
91
return cgapp .ShowError (err .Error ())
61
92
}
62
93
@@ -72,13 +103,21 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
72
103
*/
73
104
74
105
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
+ }
82
121
}
83
122
84
123
// Show success report.
@@ -119,11 +158,13 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
119
158
}
120
159
121
160
// 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
+ }
127
168
128
169
/*
129
170
The project's Ansible roles part creation.
@@ -143,7 +184,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
143
184
// Show success report.
144
185
cgapp .ShowMessage (
145
186
"success" ,
146
- "Ansible inventory, playbook and roles for deploying was created!" ,
187
+ "Ansible inventory, playbook and roles for deploying your project was created!" ,
147
188
false , false ,
148
189
)
149
190
@@ -175,9 +216,10 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
175
216
proxyList = []string {"traefik" , "nginx" }
176
217
}
177
218
178
- // Delete unused roles and backend files.
219
+ // Delete unused roles, backend and frontend files.
179
220
cgapp .RemoveFolders ("roles" , proxyList )
180
221
cgapp .RemoveFolders ("backend" , []string {".git" , ".github" })
222
+ cgapp .RemoveFolders ("frontend" , []string {".git" , ".github" })
181
223
182
224
// Stop timer.
183
225
stopTimer := cgapp .CalculateDurationTime (startTimer )
@@ -193,7 +235,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
193
235
"* Please put credentials into the Ansible inventory file (`hosts.ini`) before you start deploying a project!" ,
194
236
false , false ,
195
237
)
196
- if frontend != "none" {
238
+ if ! useCustomTemplate && frontend != "none" {
197
239
cgapp .ShowMessage (
198
240
"" ,
199
241
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 {
202
244
}
203
245
cgapp .ShowMessage (
204
246
"" ,
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 " ,
206
248
false , true ,
207
249
)
208
250
cgapp .ShowMessage (
@@ -213,7 +255,3 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
213
255
214
256
return nil
215
257
}
216
-
217
- func init () {
218
- rootCmd .AddCommand (createCmd )
219
- }
0 commit comments