@@ -50,14 +50,13 @@ const (
5050 StepDone
5151)
5252
53- // Args holds the arguments required for the website project creation
5453type Args struct {
5554 WebsiteName string
5655 WebsitePath string
5756 ToolName string
5857}
5958
60- var packageManagers = []string {"npm" , "yarn" , "pnpm" } // We will filter this based on what's installed
59+ var packageManagers = []string {"npm" , "yarn" , "pnpm" }
6160
6261type configUpdatedResultMsg struct {
6362 err error
@@ -89,41 +88,33 @@ func New(fs afero.Fs, args Args) (Model, error) {
8988 config , err := project .ConfigurationFromFile (fs , "" )
9089 tui .CheckErr (err )
9190
92- // collect existing website names
9391 existingNames := []string {}
9492 for _ , website := range config .Websites {
9593 existingNames = append (existingNames , website .Basedir )
9694 }
9795
98- // If website name is provided in args, validate it first
9996 if args .WebsiteName != "" {
100- // Normalize the provided name
10197 normalizedName := strings .TrimPrefix (args .WebsiteName , "./" )
10298
103- // Check if it's a duplicate
10499 for _ , name := range existingNames {
105100 existingName := strings .TrimPrefix (name , "./" )
106101 if existingName == normalizedName {
107102 return Model {}, fmt .Errorf ("website name '%s' already exists" , normalizedName )
108103 }
109104 }
110105
111- // Validate the format
112106 if ! WebsiteNameRegex .MatchString (normalizedName ) {
113107 return Model {}, fmt .Errorf ("website name can only contain letters, numbers, underscores and hyphens" )
114108 }
115109
116- // Check if name starts with a valid character
117110 if ! WebsiteNameStartRegex .MatchString (normalizedName ) {
118111 return Model {}, fmt .Errorf ("website name must start with a letter or number" )
119112 }
120113
121- // Check if name ends with a valid character
122114 if ! WebsiteNameEndRegex .MatchString (normalizedName ) {
123115 return Model {}, fmt .Errorf ("website name cannot end with a hyphen" )
124116 }
125117
126- // Check if directory already exists
127118 if _ , err := fs .Stat (normalizedName ); err == nil {
128119 return Model {}, fmt .Errorf ("website directory '%s' already exists" , normalizedName )
129120 } else if ! os .IsNotExist (err ) {
@@ -142,7 +133,6 @@ func New(fs afero.Fs, args Args) (Model, error) {
142133 InFlightValidator : nameInFlightValidator ,
143134 })
144135
145- // collect existing paths
146136 existingPaths := []string {}
147137
148138 for _ , website := range config .Websites {
@@ -187,7 +177,6 @@ func New(fs afero.Fs, args Args) (Model, error) {
187177 if pathInUse {
188178 return Model {}, fmt .Errorf ("path %s is already in use" , args .WebsitePath )
189179 }
190- // check if the path is valid
191180 if err := pathValidator (args .WebsitePath ); err != nil {
192181 return Model {}, fmt .Errorf ("path %s is invalid: %w" , args .WebsitePath , err )
193182 }
@@ -286,7 +275,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
286275 m .packagePrompt .SetMaxDisplayedItems (m .windowSize .Height - 1 )
287276 } else {
288277 m .toolPrompt .SetMinimized (false )
289- maxItems := ((m .windowSize .Height - 3 ) / 3 ) // make room for the exit message
278+ maxItems := ((m .windowSize .Height - 3 ) / 3 )
290279 m .toolPrompt .SetMaxDisplayedItems (maxItems )
291280 m .packagePrompt .SetMinimized (false )
292281 m .packagePrompt .SetMaxDisplayedItems (maxItems )
@@ -315,7 +304,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
315304 m .portPrompt .Blur ()
316305 m .step = StepRunningToolCommand
317306
318- // Run the command directly
319307 return m , m .runCommand ()
320308 }
321309
@@ -339,7 +327,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
339327 return m , teax .Quit
340328 }
341329
342- // Command completed successfully, update config
343330 return m , m .updateConfig ()
344331 }
345332
@@ -359,7 +346,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
359346 return m , teax .Quit
360347 }
361348
362- // if the tool is not package manager based, we need to run the command
363349 if tool .SkipPackageManagerPrompt {
364350 m .packagePrompt .SetChoice (tool .Value )
365351 m .step = StepPort
@@ -467,7 +453,6 @@ func (m Model) View() string {
467453 return v .Render ()
468454}
469455
470- // help to get the selected tool
471456func (m Model ) getSelectedTool () (Tool , error ) {
472457 tool , ok := lo .Find (tools , func (f Tool ) bool {
473458 return f .Name == m .toolPrompt .Choice ()
@@ -486,7 +471,6 @@ func (m Model) runCommand() tea.Cmd {
486471 return teax .Quit
487472 }
488473
489- // if the tool has skip package manager prompt, check the tool exists and print the install guide
490474 if tool .SkipPackageManagerPrompt {
491475 if _ , err := exec .LookPath (tool .Value ); err != nil {
492476 return func () tea.Msg {
@@ -505,14 +489,11 @@ func (m Model) runCommand() tea.Cmd {
505489
506490 c := exec .Command (command , args ... )
507491
508- // Return a command that will execute the process
509492 return tea .ExecProcess (c , func (err error ) tea.Msg {
510- // If there was an error running the command
511493 if err != nil {
512494 return commandResultMsg {err : fmt .Errorf ("failed to run website command: %w" , err ), msg : "Failed to create website" }
513495 }
514496
515- // Check if the website directory was created
516497 websiteDir := m .namePrompt .Value ()
517498 if _ , err := m .fs .Stat (websiteDir ); err != nil {
518499 if os .IsNotExist (err ) {
@@ -522,12 +503,10 @@ func (m Model) runCommand() tea.Cmd {
522503 return commandResultMsg {err : fmt .Errorf ("failed to check website directory: %w" , err ), msg : "Failed to verify website creation" }
523504 }
524505
525- // If we get here, the website was created successfully
526506 return commandResultMsg {msg : "Website created successfully" }
527507 })
528508}
529509
530- // update the nitric.yaml config file with website
531510func (m Model ) updateConfig () tea.Cmd {
532511 return func () tea.Msg {
533512 var tool Tool
@@ -563,7 +542,6 @@ func (m Model) updateConfig() tea.Cmd {
563542 }
564543}
565544
566- // getAvailablePackageManagers filters package managers that exist on the system
567545func getAvailablePackageManagers () []string {
568546 available := []string {}
569547
0 commit comments