@@ -28,6 +28,11 @@ type StackConfig struct {
2828 // UI Library is pre-made styled libs like Preline.
2929 UILibrary string
3030
31+ // RenderingStrategy defines how HTML is rendered.
32+ // Eg. templates, templ, seperate client.
33+ RenderingStrategy string
34+
35+ // Flags Only
3136 // Extras are extra add-ons like css lib, HTMX etc.
3237 ExtraOpts []string
3338}
@@ -54,70 +59,74 @@ type GitHubReleaseResponse struct {
5459
5560// GetStackConfig will give a series of prompts
5661// to the user to configure their project stack.
57- func GetStackConfig () (* StackConfig , error ) {
58- var cfg StackConfig
59-
62+ func GetStackConfig (cfg * StackConfig ) error {
6063 // Framework options
61- frameworkPrompt := promptui.Select {
62- Label : "Choose a web framework" ,
63- Items : config .WebFrameworkOpts ,
64- }
65- _ , framework , err := frameworkPrompt .Run ()
66- if err != nil {
67- return nil , fmt .Errorf ("failed to select web framework" )
68- }
69- cfg .WebFramework = framework
70-
71- // CSS Strategy
72- extraPrompt := promptui.Select {
73- Label : "Choose a CSS Strategy" ,
74- Items : config .CssStrategyOpts ,
75- }
76- _ , css , err := extraPrompt .Run ()
77- if err != nil {
78- return nil , fmt .Errorf ("failed to select CSS Strategy" )
64+ if len (cfg .WebFramework ) == 0 {
65+ frameworkPrompt := promptui.Select {
66+ Label : "Choose a web framework" ,
67+ Items : config .WebFrameworkOpts ,
68+ }
69+ _ , framework , err := frameworkPrompt .Run ()
70+ if err != nil {
71+ return fmt .Errorf ("failed to select web framework" )
72+ }
73+ cfg .WebFramework = framework
7974 }
80- cfg .CssStrategy = css
81-
82- // UI Library Options
83- // Filtering the opts for UI Libs based on the css strategy chosen.
84- filteredOpts := make ([]string , 0 )
85- for lib , deps := range config .UILibraryOpts {
86- if len (deps ) == 0 {
87- filteredOpts = append (filteredOpts , lib )
88- continue
75+ // Rendering Strategy Options
76+ if len (cfg .RenderingStrategy ) == 0 {
77+ renderingStratPrompt := promptui.Select {
78+ Label : "Choose a Rendering Strategy" ,
79+ Items : config .RenderingStrategy ,
8980 }
90- if contains (deps , cfg .CssStrategy ) {
91- filteredOpts = append (filteredOpts , lib )
81+ _ , opts , err := renderingStratPrompt .Run ()
82+ if err != nil {
83+ return fmt .Errorf ("failed to select Rendering Strategy" )
9284 }
85+ cfg .RenderingStrategy = opts
9386 }
94- // Only ask anything if we have a compatible UI Lib for
95- // the chosen CSS Strategy.
96- if len (filteredOpts ) != 0 {
97- // Asking for UI Lib if we've any filtered opts.
98- uiLibPrompt := promptui.Select {
99- Label : "Choose a UI Library" ,
100- Items : filteredOpts ,
87+ // CSS Strategy
88+ if len (cfg .CssStrategy ) == 0 && cfg .RenderingStrategy == "Templates" {
89+ extraPrompt := promptui.Select {
90+ Label : "Choose a CSS Strategy" ,
91+ Items : config .CssStrategyOpts ,
10192 }
102- _ , uiLib , err := uiLibPrompt .Run ()
93+ _ , css , err := extraPrompt .Run ()
10394 if err != nil {
104- return nil , fmt .Errorf ("failed to select UI Library " )
95+ return fmt .Errorf ("failed to select CSS Strategy " )
10596 }
106- cfg .UILibrary = uiLib
97+ cfg .CssStrategy = css
10798 }
99+ // UI Library Options
100+ if len (cfg .UILibrary ) == 0 && cfg .RenderingStrategy == "Templates" {
101+ // Filtering the opts for UI Libs based on the css strategy chosen.
102+ filteredOpts := make ([]string , 0 )
103+ for lib , deps := range config .UILibraryOpts {
104+ if len (deps ) == 0 {
105+ filteredOpts = append (filteredOpts , lib )
106+ continue
107+ }
108+ if contains (deps , cfg .CssStrategy ) {
109+ filteredOpts = append (filteredOpts , lib )
110+ }
111+ }
108112
109- // Extra Add-Ons
110- extraOptsPrompt := ui.MultiSelect {
111- Label : "Choose one or many extra options" ,
112- Items : config .ExtraOpts ,
113- }
114- opts , err := extraOptsPrompt .Run ()
115- if err != nil {
116- return nil , fmt .Errorf ("failed to select extra options" )
113+ // Only ask anything if we have a compatible UI Lib for
114+ // the chosen CSS Strategy.
115+ if len (filteredOpts ) != 0 {
116+ // Asking for UI Lib if we've any filtered opts.
117+ uiLibPrompt := promptui.Select {
118+ Label : "Choose a UI Library" ,
119+ Items : filteredOpts ,
120+ }
121+ _ , uiLib , err := uiLibPrompt .Run ()
122+ if err != nil {
123+ return fmt .Errorf ("failed to select UI Library" )
124+ }
125+ cfg .UILibrary = uiLib
126+ }
117127 }
118- cfg .ExtraOpts = opts
119128
120- return & cfg , nil
129+ return nil
121130}
122131
123132// GetGoModulePath will give a input prompt to the user
0 commit comments