Skip to content

Commit 34808d3

Browse files
committed
Add config block to pubspec.yaml
1 parent e1014a0 commit 34808d3

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ The hot-reload is manual because you'll need to press 'r' in the terminal to hot
7777

7878
By default, hover uses the file `lib/main_desktop.dart` as entrypoint. You may specify a different endpoint by using the `--target` flag.
7979

80+
You can also use the configuration in the pubspec.yaml (this is the default configuration):
81+
```yaml
82+
name: ...
83+
description: ...
84+
version: ...
85+
86+
dependencies: ...
87+
88+
flutter: ...
89+
90+
go-flutter:
91+
target: lib/main_desktop.dart
92+
branch: "@master"
93+
cache-path: "/home/YOURUSERNAME/.cache/"
94+
opengl: "3.3"
95+
docker: false
96+
```
97+
8098
If you want to integrate go-flutter with VSCode, read this [issue](https://github.com/go-flutter-desktop/go-flutter/issues/129#issuecomment-513590141).
8199
82100
### Build standalone application

cmd/build.go

+24-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ const clangBinName = "o32-clang"
4343
var crossCompile = false
4444
var engineCachePath string
4545

46+
var buildTargetDefault = "lib/main_desktop.dart"
47+
var buildBranchDefault = ""
48+
var buildCachePathDefault = ""
49+
var buildOpenGlVersionDefault = "3.3"
50+
4651
func init() {
47-
buildCmd.PersistentFlags().StringVarP(&buildTarget, "target", "t", "lib/main_desktop.dart", "The main entry-point file of the application.")
48-
buildCmd.PersistentFlags().StringVarP(&buildBranch, "branch", "b", "", "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
52+
buildCmd.PersistentFlags().StringVarP(&buildTarget, "target", "t", buildTargetDefault, "The main entry-point file of the application.")
53+
buildCmd.PersistentFlags().StringVarP(&buildBranch, "branch", "b", buildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
4954
buildCmd.PersistentFlags().BoolVar(&buildDebug, "debug", false, "Build a debug version of the app.")
50-
buildCmd.PersistentFlags().StringVarP(&buildCachePath, "cache-path", "", "", "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
51-
buildCmd.PersistentFlags().StringVar(&buildOpenGlVersion, "opengl", "3.3", "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.")
55+
buildCmd.PersistentFlags().StringVarP(&buildCachePath, "cache-path", "", buildCachePathDefault, "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
56+
buildCmd.PersistentFlags().StringVar(&buildOpenGlVersion, "opengl", 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.")
5257
buildCmd.PersistentFlags().BoolVar(&buildDocker, "docker", false, "Compile in Docker container only. No need to install go")
5358
buildCmd.AddCommand(buildLinuxCmd)
5459
buildCmd.AddCommand(buildLinuxSnapCmd)
@@ -304,6 +309,21 @@ func buildInDocker(targetOS string, vmArguments []string) {
304309
}
305310

306311
func buildNormal(targetOS string, vmArguments []string) {
312+
if buildTarget == buildTargetDefault && pubspec.GetPubSpec().GoFlutter.Target != "" {
313+
buildTarget = pubspec.GetPubSpec().GoFlutter.Target
314+
}
315+
if buildBranch == buildBranchDefault && pubspec.GetPubSpec().GoFlutter.Branch != "" {
316+
buildBranch = pubspec.GetPubSpec().GoFlutter.Branch
317+
}
318+
if buildCachePath == buildCachePathDefault && pubspec.GetPubSpec().GoFlutter.CachePath != "" {
319+
buildCachePath = pubspec.GetPubSpec().GoFlutter.CachePath
320+
}
321+
if buildOpenGlVersion == buildOpenGlVersionDefault && pubspec.GetPubSpec().GoFlutter.OpenGL != "" {
322+
buildOpenGlVersion = pubspec.GetPubSpec().GoFlutter.OpenGL
323+
}
324+
if !buildDocker && pubspec.GetPubSpec().GoFlutter.Docker {
325+
buildDocker = pubspec.GetPubSpec().GoFlutter.Docker
326+
}
307327
checkForMainDesktop()
308328
crossCompile = targetOS != runtime.GOOS
309329
buildDocker = crossCompile || buildDocker

cmd/run.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
var runObservatoryPort string
2121

2222
func init() {
23-
runCmd.Flags().StringVarP(&buildTarget, "target", "t", "lib/main_desktop.dart", "The main entry-point file of the application.")
24-
runCmd.Flags().StringVarP(&buildBranch, "branch", "b", "", "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
25-
runCmd.Flags().StringVarP(&buildCachePath, "cache-path", "", "", "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
26-
runCmd.Flags().StringVar(&buildOpenGlVersion, "opengl", "3.3", "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.")
23+
runCmd.Flags().StringVarP(&buildTarget, "target", "t", buildTargetDefault, "The main entry-point file of the application.")
24+
runCmd.Flags().StringVarP(&buildBranch, "branch", "b", buildBranchDefault, "The 'go-flutter' version to use. (@master or @v0.20.0 for example)")
25+
runCmd.Flags().StringVarP(&buildCachePath, "cache-path", "", buildCachePathDefault, "The path that hover uses to cache dependencies such as the Flutter engine .so/.dll (defaults to the standard user cache directory)")
26+
runCmd.Flags().StringVar(&buildOpenGlVersion, "opengl", 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.")
2727
runCmd.Flags().StringVarP(&runObservatoryPort, "observatory-port", "", "50300", "The observatory port used to connect hover to VM services (hot-reload/debug/..)")
2828
runCmd.Flags().BoolVar(&buildOmitEmbedder, "omit-embedder", false, "Don't (re)compile 'go-flutter' source code, useful when only working with Dart code")
2929
runCmd.Flags().BoolVar(&buildOmitFlutterBundle, "omit-flutter", false, "Don't (re)compile the current Flutter project, useful when only working with Golang code (plugin)")

internal/pubspec/pubspec.go

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ type PubSpec struct {
1818
Author string
1919
Dependencies map[string]interface{}
2020
Flutter map[string]interface{}
21+
GoFlutter struct {
22+
Target string
23+
Branch string
24+
CachePath string `yaml:"cache-path"`
25+
OpenGL string
26+
Docker bool
27+
} `yaml:"go-flutter"`
2128
}
2229

2330
var pubspec = PubSpec{}

0 commit comments

Comments
 (0)