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

added fixer for app once (#229, #230) #235

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ require (
github.com/gobuffalo/clara/v2 v2.0.8
github.com/gobuffalo/envy v1.10.1
github.com/gobuffalo/events v1.4.2
github.com/gobuffalo/flect v0.2.5
github.com/gobuffalo/genny/v2 v2.0.12
github.com/gobuffalo/flect v0.3.0
github.com/gobuffalo/genny/v2 v2.1.0
github.com/gobuffalo/grift v1.5.1
github.com/gobuffalo/logger v1.0.6
github.com/gobuffalo/logger v1.0.7
github.com/gobuffalo/meta v0.3.2
github.com/gobuffalo/packd v1.0.1
github.com/gobuffalo/plush/v4 v4.1.14
github.com/gobuffalo/packd v1.0.2
github.com/gobuffalo/plush/v4 v4.1.16
github.com/gobuffalo/pop/v6 v6.0.6
github.com/gobuffalo/refresh v1.13.1
github.com/google/go-cmp v0.5.9
Expand All @@ -27,7 +27,7 @@ require (
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.0
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0
golang.org/x/tools v0.1.12
gopkg.in/yaml.v2 v2.4.0
)
44 changes: 29 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -162,38 +162,46 @@ github.com/gobuffalo/events v1.4.2 h1:9X4nBKGXOU/N/3AFRO0SxYvpL88lws8M7f5FODbWCm
github.com/gobuffalo/events v1.4.2/go.mod h1:GI0w4OrQDQP/tIIC9FPl04qWs4dTx52DLCCcwVg7Ltc=
github.com/gobuffalo/fizz v1.14.2 h1:t02ZX47tLq5P9NzxbsNkpvXqqBXsYDk02O2xhw5C2Po=
github.com/gobuffalo/fizz v1.14.2/go.mod h1:pZp2NZYEiPRoylV3lKIz0XZOOupizz+SnKq9wb1idxE=
github.com/gobuffalo/flect v0.2.5 h1:H6vvsv2an0lalEaCDRThvtBfmg44W/QHXBCYUXf/6S4=
github.com/gobuffalo/flect v0.2.5/go.mod h1:1ZyCLIbg0YD7sDkzvFdPoOydPtD8y9JQnrOROolUcM8=
github.com/gobuffalo/genny/v2 v2.0.12 h1:drZc+LTGk/WtpFqj4CTfQFWPT7VLNggR4e4G7gdWakE=
github.com/gobuffalo/flect v0.3.0 h1:erfPWM+K1rFNIQeRPdeEXxo8yFr/PO17lhRnS8FUrtk=
github.com/gobuffalo/flect v0.3.0/go.mod h1:5pf3aGnsvqvCj50AVni7mJJF8ICxGZ8HomberC3pXLE=
github.com/gobuffalo/genny/v2 v2.0.12/go.mod h1:KtMtTcR/U2kHbQxhjCVA16ph6rjBnhw39f6aaxl4hMk=
github.com/gobuffalo/github_flavored_markdown v1.1.1 h1:kUf8ginyBOTRXcKSTPsPAqlA25vQ80+xAspLIYaxmTU=
github.com/gobuffalo/genny/v2 v2.1.0 h1:cCRBbqzo3GfNvj3UetD16zRgUvWFEyyl0qTqquuIqOM=
github.com/gobuffalo/genny/v2 v2.1.0/go.mod h1:4yoTNk4bYuP3BMM6uQKYPvtP6WsXFGm2w2EFYZdRls8=
github.com/gobuffalo/github_flavored_markdown v1.1.1/go.mod h1:yU32Pen+eorS58oxh/bNZx76zUOCJwmvyV5FBrvzOKQ=
github.com/gobuffalo/github_flavored_markdown v1.1.3 h1:rSMPtx9ePkFB22vJ+dH+m/EUBS8doQ3S8LeEXcdwZHk=
github.com/gobuffalo/github_flavored_markdown v1.1.3/go.mod h1:IzgO5xS6hqkDmUh91BW/+Qxo/qYnvfzoz3A7uLkg77I=
github.com/gobuffalo/grift v1.5.1 h1:UFlckhvmNKT80uRsG7lRdeYUWJw6ji4RK1CKrj9fFBE=
github.com/gobuffalo/grift v1.5.1/go.mod h1:2/FfgeX2YoFJs6aP/2NsuQMYZU+P9jUtDpaNsXAclIc=
github.com/gobuffalo/helpers v0.6.5 h1:Quf1KAUae97sdDmm/QP5V9P/0XYpK+HrhnYXU+nf65M=
github.com/gobuffalo/helpers v0.6.5/go.mod h1:LA4zcc89tkZsfKpJIWsXLibiqTgZQ4EvDszfxdqr9ZA=
github.com/gobuffalo/helpers v0.6.7 h1:C9CedoRSfgWg2ZoIkVXgjI5kgmSpL34Z3qdnzpfNVd8=
github.com/gobuffalo/helpers v0.6.7/go.mod h1:j0u1iC1VqlCaJEEVkZN8Ia3TEzfj/zoXANqyJExTMTA=
github.com/gobuffalo/here v0.6.6 h1:/o+jfSwe36pKQ577grsXGoMYql/zheiGwg1XFo3CBJU=
github.com/gobuffalo/here v0.6.6/go.mod h1:C4JZL5PsXWKzP/CAchaIzuUWlaae6CaAiMYQ0ieY62M=
github.com/gobuffalo/httptest v1.5.1/go.mod h1:uEeEFF2BRyTMNAATqFQAKYvpHrWWPNoJbIB3YPuANNM=
github.com/gobuffalo/logger v1.0.6 h1:nnZNpxYo0zx+Aj9RfMPBm+x9zAU2OayFh/xrAWi34HU=
github.com/gobuffalo/logger v1.0.6/go.mod h1:J31TBEHR1QLV2683OXTAItYIg8pv2JMHnF/quuAbMjs=
github.com/gobuffalo/logger v1.0.7 h1:LTLwWelETXDYyqF/ASf0nxaIcdEOIJNxRokPcfI/xbU=
github.com/gobuffalo/logger v1.0.7/go.mod h1:u40u6Bq3VVvaMcy5sRBclD8SXhBYPS0Qk95ubt+1xJM=
github.com/gobuffalo/meta v0.3.2 h1:KA8PXNHZ+maS6SrE/om1UVyKbV0SjytQw0mAUGsiK1k=
github.com/gobuffalo/meta v0.3.2/go.mod h1:qTZ/9n499kXeJ49PHHoSQr63R+kWNpQKiYD62C+AtHI=
github.com/gobuffalo/nulls v0.4.1 h1:k7QVCJfMplv9VRQQLb4N1d8tXUdGvcdMNfp4BfMnG2M=
github.com/gobuffalo/nulls v0.4.1/go.mod h1:pp8e1hWTRJZFpMl4fj/CVbSMlaxjeGKkFq4RuBZi3w8=
github.com/gobuffalo/packd v1.0.1 h1:U2wXfRr4E9DH8IdsDLlRFwTZTK7hLfq9qT/QHXGVe/0=
github.com/gobuffalo/packd v1.0.1/go.mod h1:PP2POP3p3RXGz7Jh6eYEf93S7vA2za6xM7QT85L4+VY=
github.com/gobuffalo/packd v1.0.2 h1:Yg523YqnOxGIWCp69W12yYBKsoChwI7mtu6ceM9Bwfw=
github.com/gobuffalo/packd v1.0.2/go.mod h1:sUc61tDqGMXON80zpKGp92lDb86Km28jfvX7IAyxFT8=
github.com/gobuffalo/plush/v4 v4.1.13/go.mod h1:s3hUyj/JlwEiJ039OBJevojq9xT40D1pgekw0o88CVU=
github.com/gobuffalo/plush/v4 v4.1.14 h1:F3IRVRHVBVJZA4g//zbq0lyF+QBjNtZIGC6e/2k86L8=
github.com/gobuffalo/plush/v4 v4.1.14/go.mod h1:s3hUyj/JlwEiJ039OBJevojq9xT40D1pgekw0o88CVU=
github.com/gobuffalo/plush/v4 v4.1.16 h1:Y6jVVTLdg1BxRXDIbTJz+J8QRzEAtv5ZwYpGdIFR7VU=
github.com/gobuffalo/plush/v4 v4.1.16/go.mod h1:6t7swVsarJ8qSLw1qyAH/KbrcSTwdun2ASEQkOznakg=
github.com/gobuffalo/pop/v6 v6.0.6 h1:M/CJ9RLibCTN0OtsgASmVtKqyEXJAreF8oamZrHscc4=
github.com/gobuffalo/pop/v6 v6.0.6/go.mod h1:toTxNJnsSuSlyK6w0yGb4YXSNIHsi2chQYC2CjBF9Ac=
github.com/gobuffalo/refresh v1.13.1 h1:P5/F+aGusF2Jg829tVf/SSGBmMyaFQekYGFG+0t90Xw=
github.com/gobuffalo/refresh v1.13.1/go.mod h1:9kiOSpIPMKq67avFt3bkPHYIdzZSAsKwDr6TH5/etNk=
github.com/gobuffalo/tags/v3 v3.1.3 h1:yhq9gudiEngYtPzH1KtMUknxffQBqwNfkHKP6i4l4NE=
github.com/gobuffalo/tags/v3 v3.1.3/go.mod h1:WAAjKdskZUmdi6EkNjP2SXBwBwRovHsjJsPJbBiPlKc=
github.com/gobuffalo/validate/v3 v3.3.2 h1:GZdJlDy6zDRXF5BnEiY+pGvGDFx95atMIWd3N3MMseE=
github.com/gobuffalo/tags/v3 v3.1.4 h1:X/ydLLPhgXV4h04Hp2xlbI2oc5MDaa7eub6zw8oHjsM=
github.com/gobuffalo/tags/v3 v3.1.4/go.mod h1:ArRNo3ErlHO8BtdA0REaZxijuWnWzF6PUXngmMXd2I0=
github.com/gobuffalo/validate/v3 v3.3.2/go.mod h1:jiEEw+N7KbAP2aInFxGnfitI0g7HjXqcp5hDD6TaQDU=
github.com/gobuffalo/validate/v3 v3.3.3 h1:o7wkIGSvZBYBd6ChQoLxkz2y1pfmhbI4jNJYh6PuNJ4=
github.com/gobuffalo/validate/v3 v3.3.3/go.mod h1:YC7FsbJ/9hW/VjQdmXPvFqvRis4vrRYFxr69WiNZw6g=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.1.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
Expand Down Expand Up @@ -435,8 +443,9 @@ github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A
github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/microcosm-cc/bluemonday v1.0.16 h1:kHmAq2t7WPWLjiGvzKa5o3HzSfahUKiOq7fAPUiMNIc=
github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
github.com/microcosm-cc/bluemonday v1.0.20 h1:flpzsq4KU3QIYAYGV/szUat7H+GPOXR0B2JU5A1Wp8Y=
github.com/microcosm-cc/bluemonday v1.0.20/go.mod h1:yfBmMi8mxvaZut3Yytv+jTXRY8mxyjJ0/kQBTElld50=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
Expand Down Expand Up @@ -690,8 +699,10 @@ golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su
golang.org/x/net v0.0.0-20220412020605-290c469a71a5/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b h1:6e93nYa3hNqAvLr0pD4PN1fFS+gKzp2zAXqrnTCstqU=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -725,8 +736,9 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0 h1:cu5kTvlzcw1Q5S9f5ip1/cpiB4nXvw1XYzFPGgzLUOY=
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -809,12 +821,14 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
42 changes: 42 additions & 0 deletions internal/genny/fix/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package fix

import (
"fmt"
"strings"

"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/genny/v2/gogen"
)

// ReplaceOldImports walks all the .go files in an application
sio4 marked this conversation as resolved.
Show resolved Hide resolved
// It will then attempt to convert any old import paths to any new import paths
// used by this version Buffalo.
func ReplaceAppOnce(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
fmt.Println("~~~ Apply AppOnce ~~~")

file, err := r.FindFile("actions/app.go")
if err != nil {
return err
}

if !strings.Contains(file.String(), "appOnce.Do") {
file, err = gogen.ReplaceBlock(file, "if app == nil {", "}", "appOnce.Do(func() {", "})")
if err != nil {
return err
}

file, err = gogen.AddGlobal(file, "appOnce sync.Once")
if err != nil {
return err
}

file, err = gogen.AddImport(file, "sync")
if err != nil {
return err
}
}

return r.File(file)
}
}
50 changes: 50 additions & 0 deletions internal/genny/fix/action_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fix

import (
"os"
"path/filepath"
"testing"

"github.com/gobuffalo/genny/v2/gentest"
"github.com/gobuffalo/meta"
"github.com/stretchr/testify/require"
)

func Test_ReplaceAppOnce(t *testing.T) {
r := require.New(t)

tt := []struct {
Name string
OK bool
}{
{"buffalo0_11", false},
{"buffaloPre0_18api", true},
{"buffaloPre0_18web", true},
}

for _, tc := range tt {
t.Run(tc.Name, func(t *testing.T) {
run := gentest.NewRunner()

err := run.Disk.AddFS(os.DirFS(filepath.Join("_fixtures", tc.Name)))
r.NoError(err)

opts := &Options{
App: meta.Named("coke", "."),
}
g := ReplaceAppOnce(opts)
run.WithRun(g)

if tc.OK {
r.NoError(run.Run())
f, err := run.FindFile("actions/app.go")
r.NoError(err)

//fmt.Println("XXX =====", f.String())
r.Contains(f.String(), "appOnce", "files in vendor directory should not be changed")
} else {
r.Error(run.Run())
}
})
}
}
4 changes: 3 additions & 1 deletion internal/genny/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ func New(opts *Options) (*genny.Generator, error) {
g.RunFn(MoveMain(opts))
g.RunFn(Refresh(opts))

g.RunFn(ReplaceAppOnce(opts))

// replace old imports with new ones
g.RunFn(ReplaceOldImports(opts))
g.RunFn(RewriteImports(opts))
g.Command(tidyCmd())

// check webpack.config.json and package.json for updates
Expand Down
8 changes: 4 additions & 4 deletions internal/genny/fix/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ var replace = map[string]string{
"github.com/shurcooL/github_flavored_markdown": "github.com/gobuffalo/github_flavored_markdown",
}

// ReplaceOldImports walks all the .go files in an application
// RewriteImports walks all the .go files in an application
// It will then attempt to convert any old import paths to any new import paths
// used by this version Buffalo.
func ReplaceOldImports(opts *Options) genny.RunFn {
func RewriteImports(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
fmt.Println("~~~ Rewriting Imports ~~~")
return walkDisk(r.Disk, ".", func(path string, info os.FileInfo, err error) error {
Expand All @@ -64,15 +64,15 @@ func ReplaceOldImports(opts *Options) genny.RunFn {
if err != nil {
return err
}
if err := rewriteFile(f); err != nil {
if err := rewriteImports(f); err != nil {
return err
}
return r.File(f)
})
}
}

func rewriteFile(file genny.File) error {
func rewriteImports(file genny.File) error {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, file.Name(), file.String(), parser.ParseComments)
if err != nil {
Expand Down
20 changes: 7 additions & 13 deletions internal/genny/fix/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ func Test_Imports(t *testing.T) {
tt := []struct {
Name string
}{
{
Name: "buffalo0_11",
},
{
Name: "buffaloPre0_18api",
},
{
Name: "buffaloPre0_18web",
},
{"buffalo0_11"},
{"buffaloPre0_18api"},
{"buffaloPre0_18web"},
}

for _, tc := range tt {
Expand All @@ -40,7 +34,7 @@ func Test_Imports(t *testing.T) {
opts := &Options{
App: meta.Named("coke", "."),
}
g := ReplaceOldImports(opts)
g := RewriteImports(opts)
run.WithRun(g)

r.NoError(run.Run())
Expand Down Expand Up @@ -76,7 +70,7 @@ import "github.com/markbates/grift"
r.NoError(err)
r.NotNil(file)

err = rewriteFile(file)
err = rewriteImports(file)
r.NoError(err)
r.Equal(`package main

Expand All @@ -96,7 +90,7 @@ import gr "github.com/markbates/grift"
r.NoError(err)
r.NotNil(file)

err = rewriteFile(file)
err = rewriteImports(file)
r.NoError(err)
r.Equal(`package main

Expand All @@ -116,7 +110,7 @@ import . "github.com/markbates/grift"
r.NoError(err)
r.NotNil(file)

err = rewriteFile(file)
err = rewriteImports(file)
r.NoError(err)
r.Equal(`package main

Expand Down