Skip to content

Commit

Permalink
Make 'web' the default output for fyne serve with added messaging t…
Browse files Browse the repository at this point in the history
…o install gopherjs if necessary.
  • Loading branch information
Cedric BAIL committed May 19, 2022
1 parent d0a1e67 commit 66c196e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/fyne/internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ func (b *Builder) build() error {
versionConstraint = version.NewConstrainGroupFromString(">=1.17")
env = append(env, "GOARCH=wasm")
env = append(env, "GOOS=js")
} else if goos == "gopherjs" {
_, err := b.runner.runOutput("version")
if err != nil {
fmt.Fprintf(os.Stderr, "Can not execute `gopherjs version`. Please do `go install github.com/gopherjs/gopherjs@latest`.\n")
return err
}
}

if err := checkGoVersion(b.runner, versionConstraint); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions cmd/fyne/internal/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ func Test_BuildWasmReleaseVersion(t *testing.T) {

func Test_BuildGopherJSReleaseVersion(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{
args: []string{"version"},
osEnv: true,
},
mockReturn: mockReturn{
ret: []byte(""),
err: nil,
},
},
{
expectedValue: expectedValue{
args: []string{"build", "--tags", "release"},
Expand Down
40 changes: 40 additions & 0 deletions cmd/fyne/internal/commands/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ func Test_PackageWasm(t *testing.T) {

func Test_buildPackageGopherJS(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{
args: []string{"version"},
osEnv: true,
},
mockReturn: mockReturn{
ret: []byte(""),
err: nil,
},
},
{
expectedValue: expectedValue{
args: []string{"build", "-o", "myTest.js", "--tags", "release"},
Expand Down Expand Up @@ -230,6 +240,16 @@ func Test_buildPackageGopherJS(t *testing.T) {

func Test_PackageGopherJS(t *testing.T) {
expected := []mockRunner{
{
expectedValue: expectedValue{
args: []string{"version"},
osEnv: true,
},
mockReturn: mockReturn{
ret: []byte(""),
err: nil,
},
},
{
expectedValue: expectedValue{
args: []string{"build",
Expand Down Expand Up @@ -327,6 +347,16 @@ func Test_BuildPackageWeb(t *testing.T) {
ret: []byte(""),
},
},
{
expectedValue: expectedValue{
args: []string{"version"},
osEnv: true,
},
mockReturn: mockReturn{
ret: []byte(""),
err: nil,
},
},
{
expectedValue: expectedValue{
args: []string{"build", "-o", "myTest.js", "--tags", "release"},
Expand Down Expand Up @@ -374,6 +404,16 @@ func Test_PackageWeb(t *testing.T) {
ret: []byte(""),
},
},
{
expectedValue: expectedValue{
args: []string{"version"},
osEnv: true,
},
mockReturn: mockReturn{
ret: []byte(""),
err: nil,
},
},
{
expectedValue: expectedValue{
args: []string{"build",
Expand Down
2 changes: 1 addition & 1 deletion cmd/fyne/internal/commands/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Serve() *cli.Command {
Name: "target",
Aliases: []string{"os"},
Usage: "The web runtime to target (wasm, gopherjs, web).",
Value: "wasm",
Value: "web",
Destination: &s.os,
},
},
Expand Down

0 comments on commit 66c196e

Please sign in to comment.