Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
continue: to be compatible with old versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sio4 committed Oct 1, 2022
1 parent ed7590d commit 0e3b085
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 12 additions & 1 deletion internal/genny/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func updateApp(pres *presenter) genny.RunFn {
if err != nil {
return err
}

var lines []string
body := f.String()
for _, a := range pres.Actions {
Expand All @@ -76,9 +77,19 @@ func updateApp(pres *presenter) genny.RunFn {
lines = append(lines, e)
}
}

f, err = gogen.AddInsideBlock(f, "appOnce.Do(func() {", strings.Join(lines, "\n\t\t"))
if err != nil {
return err
if strings.Contains(err.Error(), "could not find desired block") {
f, err = gogen.AddInsideBlock(f, "if app == nil {", strings.Join(lines, "\n\t\t"))
if err != nil {
return err
} else {
r.Logger.Warnf("This app was built with CLI v0.18.8 or older. See https://gobuffalo.io/documentation/known-issues/#cli-v0.18.8")
}
} else {
return err
}
}
return r.File(f)
}
Expand Down
14 changes: 13 additions & 1 deletion internal/genny/resource/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resource

import (
"fmt"
"strings"

"github.com/gobuffalo/flect/name"
"github.com/gobuffalo/genny/v2"
Expand All @@ -14,11 +15,22 @@ func addResource(pres presenter) genny.RunFn {
if err != nil {
return err
}

stmt := fmt.Sprintf("app.Resource(\"/%s\", %sResource{})", pres.Name.URL(), pres.Name.Resource())
f, err = gogen.AddInsideBlock(f, "appOnce.Do(func() {", stmt)
if err != nil {
return err
if strings.Contains(err.Error(), "could not find desired block") {
f, err = gogen.AddInsideBlock(f, "if app == nil {", stmt)
if err != nil {
return err
} else {
r.Logger.Warnf("This app was built with CLI v0.18.8 or older. See https://gobuffalo.io/documentation/known-issues/#cli-v0.18.8")
}
} else {
return err
}
}

return r.File(f)
}
}
Expand Down

0 comments on commit 0e3b085

Please sign in to comment.