@@ -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" ,
@@ -34,16 +43,34 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
34
43
)
35
44
36
45
// Start survey.
37
- if err := survey .Ask (
38
- registry .CreateQuestions , & createAnswers , survey .WithIcons (surveyIconsConfig ),
39
- ); err != nil {
40
- return cgapp .ShowError (err .Error ())
41
- }
46
+ if useCustomTemplate {
47
+ // Custom survey.
48
+ if err := survey .Ask (
49
+ registry .CustomCreateQuestions , & customCreateAnswers , survey .WithIcons (surveyIconsConfig ),
50
+ ); err != nil {
51
+ return cgapp .ShowError (err .Error ())
52
+ }
42
53
43
- // Define variables for better display.
44
- backend = strings .Replace (createAnswers .Backend , "/" , "_" , - 1 )
45
- frontend = createAnswers .Frontend
46
- proxy = createAnswers .Proxy
54
+ // Define variables for better display.
55
+ backend = customCreateAnswers .Backend
56
+ frontend = customCreateAnswers .Frontend
57
+ proxy = customCreateAnswers .Proxy
58
+ } else {
59
+ // Default survey.
60
+ if err := survey .Ask (
61
+ registry .CreateQuestions , & createAnswers , survey .WithIcons (surveyIconsConfig ),
62
+ ); err != nil {
63
+ return cgapp .ShowError (err .Error ())
64
+ }
65
+
66
+ // Define variables for better display.
67
+ backend = fmt .Sprintf (
68
+ "github.com/create-go-app/%v-go-template" ,
69
+ strings .Replace (createAnswers .Backend , "/" , "_" , - 1 ),
70
+ )
71
+ frontend = createAnswers .Frontend
72
+ proxy = createAnswers .Proxy
73
+ }
47
74
48
75
// Start timer.
49
76
startTimer := time .Now ()
@@ -53,10 +80,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
53
80
*/
54
81
55
82
// 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 {
83
+ if err := cgapp .GitClone ("backend" , backend ); err != nil {
60
84
return cgapp .ShowError (err .Error ())
61
85
}
62
86
@@ -72,13 +96,21 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
72
96
*/
73
97
74
98
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 ())
99
+ // Checking, if use custom templates.
100
+ if useCustomTemplate {
101
+ // Clone frontend files from git repository.
102
+ if err := cgapp .GitClone ("frontend" , frontend ); err != nil {
103
+ return cgapp .ShowError (err .Error ())
104
+ }
105
+ } else {
106
+ // Create a default frontend template from Vite.js.
107
+ if err := cgapp .ExecCommand (
108
+ "npm" ,
109
+ []string {"init" , "@vitejs/app" , "frontend" , "--" , "--template" , frontend },
110
+ true ,
111
+ ); err != nil {
112
+ return cgapp .ShowError (err .Error ())
113
+ }
82
114
}
83
115
84
116
// Show success report.
@@ -119,11 +151,13 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
119
151
}
120
152
121
153
// Show success report.
122
- cgapp .ShowMessage (
123
- "success" ,
124
- fmt .Sprintf ("Web/Proxy server configuration for `%v` was created!" , proxy ),
125
- false , false ,
126
- )
154
+ if proxy != "none" {
155
+ cgapp .ShowMessage (
156
+ "success" ,
157
+ fmt .Sprintf ("Web/Proxy server configuration for `%v` was created!" , proxy ),
158
+ false , false ,
159
+ )
160
+ }
127
161
128
162
/*
129
163
The project's Ansible roles part creation.
@@ -143,7 +177,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
143
177
// Show success report.
144
178
cgapp .ShowMessage (
145
179
"success" ,
146
- "Ansible inventory, playbook and roles for deploying was created!" ,
180
+ "Ansible inventory, playbook and roles for deploying your project was created!" ,
147
181
false , false ,
148
182
)
149
183
@@ -175,9 +209,10 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
175
209
proxyList = []string {"traefik" , "nginx" }
176
210
}
177
211
178
- // Delete unused roles and backend files.
212
+ // Delete unused roles, backend and frontend files.
179
213
cgapp .RemoveFolders ("roles" , proxyList )
180
214
cgapp .RemoveFolders ("backend" , []string {".git" , ".github" })
215
+ cgapp .RemoveFolders ("frontend" , []string {".git" , ".github" })
181
216
182
217
// Stop timer.
183
218
stopTimer := cgapp .CalculateDurationTime (startTimer )
@@ -193,7 +228,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
193
228
"* Please put credentials into the Ansible inventory file (`hosts.ini`) before you start deploying a project!" ,
194
229
false , false ,
195
230
)
196
- if frontend != "none" {
231
+ if ! useCustomTemplate && frontend != "none" {
197
232
cgapp .ShowMessage (
198
233
"" ,
199
234
fmt .Sprintf ("* Visit https://vitejs.dev/guide/ for more info about using the `%v` frontend template!" , frontend ),
@@ -202,7 +237,7 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
202
237
}
203
238
cgapp .ShowMessage (
204
239
"" ,
205
- "* A helpful documentation and next steps with your project is here https://create-go.app/" ,
240
+ "* A helpful documentation and next steps with your project is here https://create-go.app/wiki " ,
206
241
false , true ,
207
242
)
208
243
cgapp .ShowMessage (
@@ -213,7 +248,3 @@ func runCreateCmd(cmd *cobra.Command, args []string) error {
213
248
214
249
return nil
215
250
}
216
-
217
- func init () {
218
- rootCmd .AddCommand (createCmd )
219
- }
0 commit comments