From fca1422104dd49d524e50f4f3d278ca8b4264f89 Mon Sep 17 00:00:00 2001 From: "Arik Jones (aider)" Date: Thu, 19 Sep 2024 12:08:34 -0500 Subject: [PATCH] refactor: improve generate command and use config package --- cmd/generate.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cmd/generate.go b/cmd/generate.go index 8c966ff..a872753 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -2,12 +2,13 @@ package cmd import ( "fmt" - "io/ioutil" "os" "path/filepath" + "sort" "strings" "github.com/spf13/cobra" + "github.com/tnypxl/rollup/internal/config" "gopkg.in/yaml.v2" ) @@ -36,26 +37,30 @@ func runGenerate(cmd *cobra.Command, args []string) error { return fmt.Errorf("error walking the path: %v", err) } - config := config.Config{ + cfg := config.Config{ FileTypes: make([]string, 0, len(fileTypes)), Ignore: []string{"node_modules/**", "vendor/**", ".git/**"}, } for ext := range fileTypes { - config.FileTypes = append(config.FileTypes, ext) + cfg.FileTypes = append(cfg.FileTypes, ext) } - yamlData, err := yaml.Marshal(&config) + // Sort file types for consistency + sort.Strings(cfg.FileTypes) + + yamlData, err := yaml.Marshal(&cfg) if err != nil { return fmt.Errorf("error marshaling config: %v", err) } - err = ioutil.WriteFile("rollup.yml", yamlData, 0644) + outputPath := config.DefaultConfigPath() + err = os.WriteFile(outputPath, yamlData, 0644) if err != nil { return fmt.Errorf("error writing config file: %v", err) } - fmt.Println("Generated rollup.yml file successfully.") + fmt.Printf("Generated %s file successfully.\n", outputPath) return nil }