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

fixed various fixer issues #161

Merged
merged 3 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
45 changes: 43 additions & 2 deletions internal/cmd/fix/fix_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// +build integration
// +build linux
//go:build integration && linux
// +build integration,linux

package fix_test

Expand All @@ -16,6 +16,47 @@ import (

// The tests here are quite slow, so we only run them on linux.

func TestFix_Self(t *testing.T) {
r := require.New(t)
r.NoError(testhelpers.EnsureBuffaloCMD(t))

tt := []struct {
newargs []string
appname string
}{
{
newargs: []string{"new", "api", "-f", "--api", "--vcs", "none"},
appname: "api",
},
{
newargs: []string{"new", "web", "-f", "--vcs", "none"},
appname: "web",
},
}

for _, tc := range tt {
t.Run(tc.appname, func(t *testing.T) {
testhelpers.RunWithinTempFolder(t, func(t *testing.T) {
r := require.New(t)

out, err := testhelpers.RunBuffaloCMD(t, tc.newargs)
t.Log(out)
r.NoError(err)

r.NoError(os.Chdir(tc.appname))

out, err = testhelpers.RunBuffaloCMD(t, []string{"fix", "-y"})
t.Log(out)
r.NoError(err)

out, err = testhelpers.RunBuffaloCMD(t, []string{"build"})
t.Log(out)
r.NoError(err)
})
})
}
}

func TestFix_v0_18_0(t *testing.T) {
r := require.New(t)
r.NoError(testhelpers.EnsureBuffaloCMD(t))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const configurator = {
mode: env,
entry: configurator.entries(),
output: {
filename: "[name].[contenthash].js",
filename: "[name].[contenthash].js",
path: `${__dirname}/public/assets`,
clean: true,
},
Expand Down
6 changes: 4 additions & 2 deletions internal/genny/docker/templates/Dockerfile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ WORKDIR /src/{{.opts.App.PackagePkg}}
# this will cache the npm install step, unless package.json changes
ADD package.json .
{{if .opts.App.WithYarn -}}
ADD yarn.lock .
RUN yarn install --no-progress
ADD yarn.lock .yarnrc.yml ./
RUN mkdir .yarn
COPY .yarn .yarn
RUN yarn install
{{else -}}
RUN npm install --no-progress
{{end -}}
Expand Down
2 changes: 1 addition & 1 deletion internal/genny/fix/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
func DeprecationsCheck(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
fmt.Println("~~~ Checking for deprecations ~~~")
f, err := r.FindFile("main.go")
f, err := r.FindFile("cmd/app/main.go")
if err != nil {
return err
}
Expand Down
11 changes: 7 additions & 4 deletions internal/genny/fix/depreciations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
)

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

tt := []struct {
Expand Down Expand Up @@ -43,21 +43,22 @@ func Test_Depreciations_mainGo(t *testing.T) {
opts := &Options{
App: meta.Named("coke", "."),
}
run.WithRun(MoveMain(opts)) // structural test should go first
g := DeprecationsCheck(opts)
run.WithRun(g)

r.NoError(run.Run())

results := run.Results()
_, err = results.Find("main.go")
_, err = results.Find("cmd/app/main.go")
r.NoError(err)

r.ElementsMatch(opts.warnings, tc.warnings)
})
}
}

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

tt := []struct {
Expand Down Expand Up @@ -117,6 +118,7 @@ func Test_Depreciations_ReplacePackr(t *testing.T) {
opts := &Options{
App: meta.Named("coke", "."),
}
run.WithRun(MoveMain(opts)) // structural test should go first
g := DeprecationsCheck(opts)
run.WithRun(g)

Expand Down Expand Up @@ -154,7 +156,7 @@ func Test_Depreciations_ReplacePackr(t *testing.T) {
}
}

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

tt := []struct {
Expand Down Expand Up @@ -214,6 +216,7 @@ func Test_Depreciations_ReplaceSuite(t *testing.T) {
opts := &Options{
App: meta.Named("coke", "."),
}
run.WithRun(MoveMain(opts)) // structural test should go first
g := DeprecationsCheck(opts)
run.WithRun(g)

Expand Down
9 changes: 5 additions & 4 deletions internal/genny/fix/fix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func ask(q string) bool {
fmt.Printf("? %s [y/n]\n", q)
fmt.Printf("? %s [y/n] ", q)

reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
Expand Down Expand Up @@ -71,6 +71,10 @@ func New(opts *Options) (*genny.Generator, error) {
return nil, err
}

// structural fixes go first so the others can use the expected structure.
g.RunFn(MoveMain(opts))
g.RunFn(Refresh(opts))

// replace old imports with new ones
g.RunFn(ReplaceOldImports(opts))
g.Command(tidyCmd())
Expand Down Expand Up @@ -103,9 +107,6 @@ func New(opts *Options) (*genny.Generator, error) {
// update plush templates
g.RunFn(UpdatePlushTemplates(opts))

g.RunFn(MoveMain(opts))
g.RunFn(Refresh(opts))

// print all warnings that were captured
g.RunFn(printWarnings(opts))

Expand Down
43 changes: 43 additions & 0 deletions internal/genny/fix/movemain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package fix

import (
"fmt"
"io"

"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/refresh/refresh"
"gopkg.in/yaml.v2"
)

// MoveMain will move the main.go from the root folder into
Expand Down Expand Up @@ -34,3 +37,43 @@ func MoveMain(opts *Options) genny.RunFn {
return r.File(nf)
}
}

// Refresh will update the buffalo.dev.yml to build
// the main at ./cmd/app instead of the root folder.
func Refresh(opts *Options) genny.RunFn {
return func(r *genny.Runner) error {
fmt.Println("~~~ Checking for .buffalo.dev.yml ~~~")
f, err := r.FindFile(".buffalo.dev.yml")
if err != nil {
return err
}

data, err := io.ReadAll(f)
if err != nil {
return err
}

c := refresh.Configuration{}
err = yaml.Unmarshal(data, &c)
if err != nil {
return err
}

if c.BuildTargetPath != "" {
return nil
}

c.BuildTargetPath = "./cmd/app"
data, err = yaml.Marshal(&c)
if err != nil {
return err
}

_, err = f.Write(data)
if err != nil {
return err
}

return r.File(f)
}
}
2 changes: 1 addition & 1 deletion internal/genny/fix/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func PackageJSONCheck(opts *Options) genny.RunFn {
}

if opts.App.WithYarn {
return r.Exec(exec.Command("yarnpkg", "install", "--no-progress", "--save"))
return r.Exec(exec.Command("yarn", "install"))
}

return r.Exec(exec.Command("npm", "install"))
Expand Down
2 changes: 1 addition & 1 deletion internal/genny/fix/npm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func Test_PackageJSONCheck_UpdatingFileAndClearNodeModules(t *testing.T) {
{
Name: "WithYarn",
WithYarn: true,
Command: "yarnpkg install --no-progress --save",
Command: "yarn install",
},
{
Name: "WithoutYarn",
Expand Down
50 changes: 0 additions & 50 deletions internal/genny/fix/refresh.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/runtime/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runtime

// Version is the current version of the buffalo binary
var Version = "v0.18.4"
var Version = "v0.18.6"