diff --git a/README.md b/README.md index d1751788..7aa61c12 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,19 @@ To get a list of all available packaging formats run: hover build --help ``` +### Flavors + +Hover supports different application flavors via `--flavor MY_FLAVOR` command. +If you wish to create a new flavor for you application, +simply copy `go/hover.yaml` into `go/hover-MY_FLAVOR.yaml` and modify contents as needed. +If no flavor is specified, Hover will always default to `hover.yaml` + +``` +hover run --flavor develop || hover build --flavor develop +// hover-develop.yaml +``` + + ## Issues Please report issues at the [go-flutter issue tracker](https://github.com/go-flutter-desktop/go-flutter/issues/). diff --git a/cmd/build.go b/cmd/build.go index e213869e..3a5b85ac 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -33,6 +33,7 @@ var ( buildOrRunCachePath string buildOrRunOpenGlVersion string buildOrRunEngineVersion string + buildOrRunHoverFlavor string buildOrRunDocker bool buildOrRunDebug bool buildOrRunRelease bool @@ -48,6 +49,7 @@ func initCompileFlags(cmd *cobra.Command) { cmd.PersistentFlags().StringVar(&buildOrRunCachePath, "cache-path", enginecache.DefaultCachePath(), "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll") cmd.PersistentFlags().StringVar(&buildOrRunOpenGlVersion, "opengl", config.BuildOpenGlVersionDefault, "The OpenGL version specified here is only relevant for external texture plugin (i.e. video_plugin).\nIf 'none' is provided, texture won't be supported. Note: the Flutter Engine still needs a OpenGL compatible context.") cmd.PersistentFlags().StringVar(&buildOrRunEngineVersion, "engine-version", config.BuildEngineDefault, "The flutter engine version to use.") + cmd.PersistentFlags().StringVar(&buildOrRunHoverFlavor, "flavor", "", "The flavor to use, defaults to 'hover.yaml'.") cmd.PersistentFlags().BoolVar(&buildOrRunDocker, "docker", false, "Execute the go build and packaging in a docker container. The Flutter build is always run locally") cmd.PersistentFlags().BoolVar(&buildOrRunDebug, "debug", false, "Build a debug version of the app.") cmd.PersistentFlags().BoolVar(&buildOrRunRelease, "release", false, "Build a release version of the app. Currently very experimental") @@ -261,6 +263,13 @@ func initBuildParameters(targetOS string, defaultBuildOrRunMode build.Mode) { os.Exit(1) } + // hover.yaml file needs to be set before accessing config.GetConfig() + if buildOrRunHoverFlavor == "" { + config.SetDefaultHoverYamlFile() + } else { + config.SetHoverFlavor(buildOrRunHoverFlavor) + } + if buildOrRunEngineVersion == config.BuildEngineDefault && config.GetConfig().Engine != "" { log.Warnf("changing the engine version can lead to undesirable behavior") buildOrRunEngineVersion = config.GetConfig().Engine @@ -326,6 +335,9 @@ func commonFlags() []string { if buildOrRunOpenGlVersion != config.BuildOpenGlVersionDefault { f = append(f, "--opengl", buildOrRunOpenGlVersion) } + if buildOrRunHoverFlavor != "" { + f = append(f, "--flavor", buildOrRunHoverFlavor) + } return f } diff --git a/internal/config/config.go b/internal/config/config.go index 56d5bd43..b4a25eee 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -73,7 +73,8 @@ var ( func GetConfig() Config { configLoadOnce.Do(func() { var err error - config, err = ReadConfigFile(filepath.Join(build.BuildPath, "hover.yaml")) + hoverYaml := GetHoverFlavorYaml() + config, err = ReadConfigFile(filepath.Join(build.BuildPath, hoverYaml)) if err != nil { if os.IsNotExist(errors.Cause(err)) { // TODO: Add a solution for the user. Perhaps we can let `hover diff --git a/internal/config/flavor.go b/internal/config/flavor.go new file mode 100644 index 00000000..05cf8db5 --- /dev/null +++ b/internal/config/flavor.go @@ -0,0 +1,42 @@ +package config + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/go-flutter-desktop/hover/internal/build" + "github.com/go-flutter-desktop/hover/internal/log" +) + +var hoverYaml string + +// GetHoverFlavorYaml returns the Hover yaml file +func GetHoverFlavorYaml() string { + return hoverYaml +} + +// SetDefaultFlavorFile sets the default hover.yaml +func SetDefaultHoverYamlFile() { + hoverYaml = "hover.yaml" +} + +// SetHoverFlavor sets the user defined hover flavor. +// eg. hover-develop.yaml, hover-staging.yaml, etc. +func SetHoverFlavor(flavor string) { + hoverYaml = fmt.Sprintf("hover-%s.yaml", flavor) + assertYamlFileExists(hoverYaml) +} + +// assertYamlFileExists checks to see if the user defined yaml file exists +func assertYamlFileExists(yamlFile string) { + _, err := os.Stat(filepath.Join(build.BuildPath, yamlFile)) + if os.IsNotExist(err) { + log.Warnf("Hover Yaml file \"%s\" not found.", yamlFile) + os.Exit(1) + } + if err != nil { + log.Errorf("Failed to stat %s: %v\n", yamlFile, err) + os.Exit(1) + } +}