@@ -512,33 +512,47 @@ func initCommandE(cmd *cobra.Command, args []string, noSkill bool, flagSkillsDir
512512
513513 fmt .Fprintf (out , "\n Project structure:\n \n " ) //nolint:errcheck
514514
515+ // Handle directories first
516+ for _ , item := range items {
517+ if item .isDir {
518+ if err := os .MkdirAll (item .path , 0o755 ); err != nil {
519+ return fmt .Errorf ("failed to create %s: %w" , item .path , err )
520+ }
521+ }
522+ }
523+
524+ // Prepare file entries for FileWriter
525+ var fileEntries []scaffold.FileEntry
526+ for _ , item := range items {
527+ if ! item .isDir && item .content != "" {
528+ fileEntries = append (fileEntries , scaffold.FileEntry {
529+ Path : item .path ,
530+ Content : item .content ,
531+ Label : item .label ,
532+ })
533+ }
534+ }
535+
536+ // Write files using FileWriter
537+ writer := scaffold .NewFileWriter (fileEntries )
538+ fileInventory , err := writer .Write ()
539+ if err != nil {
540+ return err
541+ }
542+
543+ // Build outcome map for files
544+ fileOutcomes := make (map [string ]scaffold.FileOutcome )
545+ for _ , inv := range fileInventory {
546+ fileOutcomes [inv .Path ] = inv .Outcome
547+ }
548+
549+ // Display inventory
515550 var buf2 bytes.Buffer
516551 tw2 := tabwriter .NewWriter (& buf2 , 0 , 0 , 2 , ' ' , 0 )
517552 created := 0
553+
518554 for _ , item := range items {
519555 var indicator string
520- var existed bool
521-
522- if item .isDir {
523- if info , err := os .Stat (item .path ); err == nil && info .IsDir () {
524- existed = true
525- } else {
526- if err := os .MkdirAll (item .path , 0o755 ); err != nil {
527- return fmt .Errorf ("failed to create %s: %w" , item .path , err )
528- }
529- }
530- } else {
531- if _ , err := os .Stat (item .path ); err == nil {
532- existed = true
533- } else if item .content != "" {
534- if err := os .MkdirAll (filepath .Dir (item .path ), 0o755 ); err != nil {
535- return fmt .Errorf ("failed to create directory for %s: %w" , item .path , err )
536- }
537- if err := os .WriteFile (item .path , []byte (item .content ), 0o644 ); err != nil {
538- return fmt .Errorf ("failed to write %s: %w" , item .path , err )
539- }
540- }
541- }
542556
543557 // Relative path for display
544558 relPath := item .path
@@ -549,11 +563,19 @@ func initCommandE(cmd *cobra.Command, args []string, noSkill bool, flagSkillsDir
549563 relPath += string (filepath .Separator )
550564 }
551565
552- if existed {
566+ if item .isDir {
567+ // Directories always show as existing (we created them if needed above)
553568 indicator = "{exist}"
554- } else {
555- indicator = "{new}"
556- created ++
569+ } else if item .content != "" {
570+ // File - check outcome from FileWriter
571+ if outcome , ok := fileOutcomes [item .path ]; ok {
572+ if outcome == scaffold .FileCreated {
573+ indicator = "{new}"
574+ created ++
575+ } else {
576+ indicator = "{exist}"
577+ }
578+ }
557579 }
558580
559581 fmt .Fprintf (tw2 , " %s\t %s\t %s\n " , indicator , relPath , item .label ) //nolint:errcheck
@@ -568,7 +590,7 @@ func initCommandE(cmd *cobra.Command, args []string, noSkill bool, flagSkillsDir
568590 fmt .Fprintln (out ) //nolint:errcheck
569591 if created == 0 {
570592 fmt .Fprintf (out , "✅ Project up to date.\n " ) //nolint:errcheck
571- } else if created == len (items ) {
593+ } else if created == len (fileEntries ) {
572594 fmt .Fprintf (out , "✅ Project created — %d items set up.\n " , created ) //nolint:errcheck
573595 } else {
574596 fmt .Fprintf (out , "✅ Repaired — %d item(s) added.\n " , created ) //nolint:errcheck
0 commit comments