diff --git a/builder/builder.go b/builder/builder.go index 8a5d49a..06a15dc 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -11,12 +11,34 @@ import ( "strings" "github.com/rose-pine/rose-pine-bloom/color" - "github.com/rose-pine/rose-pine-bloom/config" ) +// Options contains configuration for building themes from templates. +type Options struct { + Template string + Output string + Prefix string + Format string + Plain bool + Commas bool + Spaces bool +} + +// TemplateOptions contains configuration for creating templates from existing theme files. +type TemplateOptions struct { + Input string + Output string + Variant string + Prefix string + Format string + Plain bool + Commas bool + Spaces bool +} + var variantValueRegex = regexp.MustCompile(`\$\((.*?)\|(.*?)\|(.*?)\)`) -func BuildTemplate(cfg *config.BuildTemplateConfig) error { +func BuildTemplate(cfg *TemplateOptions) error { if err := os.MkdirAll(cfg.Output, 0755); err != nil { return fmt.Errorf("failed to create output directory: %w", err) } @@ -24,7 +46,7 @@ func BuildTemplate(cfg *config.BuildTemplateConfig) error { return createTemplates(cfg) } -func Build(cfg *config.BuildConfig) error { +func Build(cfg *Options) error { if err := os.MkdirAll(cfg.Output, 0755); err != nil { return fmt.Errorf("failed to create output directory: %w", err) } @@ -32,7 +54,7 @@ func Build(cfg *config.BuildConfig) error { return generateThemes(cfg) } -func generateThemes(cfg *config.BuildConfig) error { +func generateThemes(cfg *Options) error { templates, err := getTemplateFiles(cfg.Template) if err != nil { return err @@ -64,7 +86,7 @@ func generateThemes(cfg *config.BuildConfig) error { return nil } -func generateThemeFile(cfg *config.BuildConfig, templatePath string, content []byte, variant color.VariantMeta, accent string) error { +func generateThemeFile(cfg *Options, templatePath string, content []byte, variant color.VariantMeta, accent string) error { result := processTemplate(string(content), cfg, variant, accent) if filepath.Ext(templatePath) == ".json" { @@ -79,7 +101,7 @@ func generateThemeFile(cfg *config.BuildConfig, templatePath string, content []b return writeFile(outputPath, []byte(result)) } -func createTemplates(cfg *config.BuildTemplateConfig) error { +func createTemplates(cfg *TemplateOptions) error { files, err := getTemplateFiles(cfg.Input) if err != nil { return err @@ -134,7 +156,7 @@ func createTemplates(cfg *config.BuildTemplateConfig) error { return nil } -func processTemplate(content string, cfg *config.BuildConfig, variant color.VariantMeta, accent string) string { +func processTemplate(content string, cfg *Options, variant color.VariantMeta, accent string) string { result := content // Replace metadata @@ -242,7 +264,7 @@ func writeFile(outputPath string, content []byte) error { return os.WriteFile(outputPath, content, 0644) } -func buildOutputPath(cfg *config.BuildConfig, templatePath string, variant color.VariantMeta, accent string) string { +func buildOutputPath(cfg *Options, templatePath string, variant color.VariantMeta, accent string) string { ext := filepath.Ext(templatePath) var outputFile, outputDir string diff --git a/builder/builder_test.go b/builder/builder_test.go index 76a6ac6..7d5801f 100644 --- a/builder/builder_test.go +++ b/builder/builder_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/rose-pine/rose-pine-bloom/color" - "github.com/rose-pine/rose-pine-bloom/config" ) func setupTest(t *testing.T) string { @@ -24,7 +23,7 @@ func setupTest(t *testing.T) string { return tmpDir } -func buildFromTemplate(t *testing.T, template string, cfg *config.BuildConfig) { +func buildFromTemplate(t *testing.T, template string, cfg *Options) { templatePath := filepath.Join(cfg.Output, "template.json") if err := os.WriteFile(templatePath, []byte(template), 0644); err != nil { t.Fatal(err) @@ -58,7 +57,7 @@ func assertJSONField(t *testing.T, result map[string]any, field, want string) { } // testConfig provides standard config -var testConfig = config.BuildConfig{ +var testConfig = Options{ Template: "", Output: "", Prefix: "$", @@ -68,7 +67,7 @@ var testConfig = config.BuildConfig{ Spaces: true, } -var testBuildTemplateConfig = config.BuildTemplateConfig{ +var testBuildTemplateConfig = TemplateOptions{ Input: "", Output: "", Variant: "moon", diff --git a/cmd/build.go b/cmd/build.go index ff1d751..fd0f69d 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -8,7 +8,6 @@ import ( "github.com/rose-pine/rose-pine-bloom/builder" "github.com/rose-pine/rose-pine-bloom/color" - "github.com/rose-pine/rose-pine-bloom/config" "github.com/spf13/cobra" ) @@ -33,7 +32,7 @@ var buildCmd = &cobra.Command{ fmt.Printf("Building themes from %s...\n", template) - err := builder.Build(&config.BuildConfig{ + err := builder.Build(&builder.Options{ Template: template, Output: outputDir, Prefix: prefix, diff --git a/cmd/init.go b/cmd/init.go index e4f0a51..f562edc 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -10,7 +10,6 @@ import ( "time" "github.com/rose-pine/rose-pine-bloom/builder" - "github.com/rose-pine/rose-pine-bloom/config" "github.com/spf13/cobra" ) @@ -48,7 +47,7 @@ var initCmd = &cobra.Command{ themeFile := args[0] fmt.Printf("Creating template from %s...\n", themeFile) - err := builder.BuildTemplate(&config.BuildTemplateConfig{ + err := builder.BuildTemplate(&builder.TemplateOptions{ Input: themeFile, Output: output, Variant: variant, diff --git a/config/config.go b/config/config.go deleted file mode 100644 index 99b39e6..0000000 --- a/config/config.go +++ /dev/null @@ -1,22 +0,0 @@ -package config - -type BuildConfig struct { - Template string - Output string - Prefix string - Format string - Plain bool - Commas bool - Spaces bool -} - -type BuildTemplateConfig struct { - Input string - Output string - Variant string - Prefix string - Format string - Plain bool - Commas bool - Spaces bool -}