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

task: moving docker to be only multi #51

Merged
merged 22 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
95e4b8f
task: moving docker to be only multi
paganotoni Nov 20, 2021
b64abe0
task: making the command actually skip the Docker files generator
paganotoni Nov 20, 2021
aae6116
Merge branch 'development' of https://github.com/gobuffalo/cli into t…
paganotoni Nov 20, 2021
bbfae2d
Merge pull request #50 from gobuffalo/development
paganotoni Nov 25, 2021
bdbd528
Bump actions/stale from 3 to 4
dependabot[bot] Nov 25, 2021
219aa93
adding test for dockerfile
paganotoni Nov 25, 2021
1166f0a
Merge pull request #53 from gobuffalo/dependabot/github_actions/actio…
paganotoni Nov 25, 2021
9db3b51
Merge branch 'main' of https://github.com/gobuffalo/cli into task-sin…
paganotoni Nov 25, 2021
a89dc3b
fixing broken tests
paganotoni Nov 25, 2021
747690d
adding none as the VCS for the new command tests
paganotoni Nov 25, 2021
bf8eb00
adding go mod download to the new command
paganotoni Nov 25, 2021
f59bf65
removing debugging line
paganotoni Nov 26, 2021
e623473
moving to require
paganotoni Nov 26, 2021
92b51d9
adding integration tests next to the new command
paganotoni Nov 26, 2021
f92aab9
adding a bit more of documentation
paganotoni Nov 26, 2021
4ec1033
changing cli detection a bit
paganotoni Nov 26, 2021
b56057b
adding build integration tests
paganotoni Nov 26, 2021
dc3d695
changing the signature for the method that runs buffalo commands for …
paganotoni Nov 26, 2021
8856964
reverting to old signature of the helper
paganotoni Nov 26, 2021
d1a813b
fixing it back
paganotoni Nov 26, 2021
a8aba5e
adding -f and renaming just in case
paganotoni Nov 26, 2021
a9f6721
adding -p 1 on integration tests
paganotoni Nov 26, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
- uses: actions/stale@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days."
Expand Down
Binary file added buffalo
Binary file not shown.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/markbates/refresh v1.12.0
github.com/markbates/safe v1.0.1
github.com/markbates/sigtx v1.0.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
paganotoni marked this conversation as resolved.
Show resolved Hide resolved
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,9 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.9 h1:10HX2Td0ocZpYEjhilsuo6WWtUqttj2Kb0KtD86/KYA=
github.com/mattn/go-sqlite3 v1.14.9/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/microcosm-cc/bluemonday v1.0.16 h1:kHmAq2t7WPWLjiGvzKa5o3HzSfahUKiOq7fAPUiMNIc=
github.com/microcosm-cc/bluemonday v1.0.16/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2K7e/u082ZUpDRRqM=
Expand Down
347 changes: 3 additions & 344 deletions internal/cmd/new.go
Original file line number Diff line number Diff line change
@@ -1,350 +1,9 @@
package cmd

import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"

pop "github.com/gobuffalo/buffalo-pop/v3/genny/newapp"
"github.com/gobuffalo/cli/internal/genny/assets/standard"
"github.com/gobuffalo/cli/internal/genny/assets/webpack"
"github.com/gobuffalo/cli/internal/genny/ci"
"github.com/gobuffalo/cli/internal/genny/docker"
"github.com/gobuffalo/cli/internal/genny/newapp/api"
"github.com/gobuffalo/cli/internal/genny/newapp/core"
"github.com/gobuffalo/cli/internal/genny/newapp/web"
"github.com/gobuffalo/cli/internal/genny/refresh"
"github.com/gobuffalo/cli/internal/genny/vcs"
"github.com/gobuffalo/envy"
fname "github.com/gobuffalo/flect/name"
"github.com/gobuffalo/genny/v2"
"github.com/gobuffalo/genny/v2/gogen"
"github.com/gobuffalo/logger"
"github.com/gobuffalo/meta"
"github.com/gobuffalo/plush/v4"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

type newAppOptions struct {
Options *core.Options
Module string
Force bool
Verbose bool
DryRun bool
}

func parseNewOptions(args []string) (newAppOptions, error) {
nopts := newAppOptions{
Force: viper.GetBool("force"),
Verbose: viper.GetBool("verbose"),
DryRun: viper.GetBool("dry-run"),
Module: viper.GetString("module"),
}

if len(args) == 0 {
return nopts, fmt.Errorf("you must enter a name for your new application")
}
if configError != nil {
return nopts, configError
}

pwd, err := os.Getwd()
if err != nil {
return nopts, err
}
app := meta.New(pwd)
app.WithGrifts = true
app.Name = fname.New(args[0])
app.Bin = filepath.Join("bin", app.Name.String())

if app.Name.String() == "." {
app.Name = fname.New(filepath.Base(app.Root))
} else {
app.Root = filepath.Join(app.Root, app.Name.File().String())
}

if len(nopts.Module) == 0 {
aa := meta.New(app.Root)
app.PackageRoot(aa.PackagePkg)
} else {
app.PackageRoot(nopts.Module)
}

app.AsAPI = viper.GetBool("api")
app.VCS = viper.GetString("vcs")

app.WithPop = !viper.GetBool("skip-pop")
app.WithWebpack = !viper.GetBool("skip-webpack")
app.WithYarn = !viper.GetBool("skip-yarn")
app.WithNodeJs = app.WithWebpack
app.AsWeb = !app.AsAPI

if app.AsAPI {
app.WithWebpack = false
app.WithYarn = false
app.WithNodeJs = false
}

opts := &core.Options{}

x := viper.GetString("docker")
if len(x) > 0 && x != "none" {
opts.Docker = &docker.Options{
Style: x,
}
app.WithDocker = true
}

x = viper.GetString("ci-provider")
if len(x) > 0 && x != "none" {
opts.CI = &ci.Options{
Provider: x,
DBType: viper.GetString("db-type"),
}
}

if len(app.VCS) > 0 && app.VCS != "none" {
opts.VCS = &vcs.Options{
Provider: app.VCS,
}
}

if app.WithPop {
d := viper.GetString("db-type")
if d == "sqlite3" {
app.WithSQLite = true
}

opts.Pop = &pop.Options{
Prefix: app.Name.File().String(),
Dialect: d,
}
}

opts.Refresh = &refresh.Options{}

opts.App = app
nopts.Options = opts
return nopts, nil
}

var configError error

var newCmd = &cobra.Command{
Use: "new [name]",
Short: "Creates a new Buffalo application",
RunE: func(cmd *cobra.Command, args []string) error {
// Restore default values after usage (useful for testing)
defer func() {
cmd.Flags().Visit(func(f *pflag.Flag) {
if err := f.Value.Set(f.DefValue); err != nil {
log.Fatalf("failed to restore default value: %s", err)
}
})
if err := viper.BindPFlags(cmd.Flags()); err != nil {
log.Fatalf("failed to bind flags: %s", err)
}
}()

nopts, err := parseNewOptions(args)
if err != nil {
return err
}

opts := nopts.Options
app := opts.App

ctx := context.Background()

run := genny.WetRunner(ctx)
lg := logger.New(logger.DebugLevel)
run.Logger = lg

if nopts.DryRun {
run = genny.DryRunner(ctx)
}
run.Root = app.Root
if nopts.Force {
os.RemoveAll(app.Root)
}

var gg *genny.Group

if app.AsAPI {
gg, err = api.New(&api.Options{
Options: opts,
})
} else {
wo := &web.Options{
Options: opts,
}
if app.WithWebpack {
wo.Webpack = &webpack.Options{}
} else {
wo.Standard = &standard.Options{}
}
gg, err = web.New(wo)
}
if err != nil {
if errors.Is(err, core.ErrNotInGoPath) {
return notInGoPath(app)
}
return err
}

g := genny.New()
g.Command(exec.Command("go", "mod", "tidy"))
gg.Add(g)

g = genny.New()
g.RunFn(func(r *genny.Runner) error {
deps, err := exec.Command("go", "list", "-f", "{{if not (or .Main .Indirect)}}{{.Path}}{{end}}", "-m", "all").Output()
if err != nil {
return err
}

scanner := bufio.NewScanner(bytes.NewReader(deps))
for scanner.Scan() {
if err := exec.Command("go", "get", scanner.Text()).Run(); err != nil {
return err
}
}

if err := scanner.Err(); err != nil {
return err
}

return nil
})
gg.Add(g)

g = genny.New()
g.Command(exec.Command("go", "mod", "tidy"))
gg.Add(g)

run.WithGroup(gg)

if err := run.WithNew(gogen.Fmt(app.Root)); err != nil {
return err
}

// setup VCS last
if opts.VCS != nil {
// add the VCS generator
if err := run.WithNew(vcs.New(opts.VCS)); err != nil {
return err
}
}

if err := run.Run(); err != nil {
return err
}

run.Logger.Infof("Congratulations! Your application, %s, has been successfully built!", app.Name)
run.Logger.Infof("You can find your new application at: %v", app.Root)
run.Logger.Info("Please read the README.md file in your new application for next steps on running your application.")
return nil
},
}

func currentUser() (string, error) {
if _, err := exec.LookPath("git"); err == nil {
if b, err := exec.Command("git", "config", "github.user").Output(); err == nil {
return string(b), nil
}
}
u, err := user.Current()
if err != nil {
return "", err
}
username := u.Username
if t := strings.Split(username, `\`); len(t) > 0 {
username = t[len(t)-1]
}
return username, nil
}

func notInGoPath(app meta.App) error {
username, err := currentUser()
if err != nil {
return err
}
pwd, _ := os.Getwd()
t, err := plush.Render(notInGoWorkspace, plush.NewContextWith(map[string]interface{}{
"name": app.Name,
"gopath": envy.GoPath(),
"current": pwd,
"username": username,
}))
if err != nil {
return err
}
logrus.Error(t)
os.Exit(-1)
return nil
}
import "github.com/gobuffalo/cli/internal/cmd/new"

func init() {
decorate("new", newCmd)
RootCmd.AddCommand(newCmd)
newCmd.Flags().Bool("api", false, "skip all front-end code and configure for an API server")
newCmd.Flags().BoolP("force", "f", false, "delete and remake if the app already exists")
newCmd.Flags().BoolP("dry-run", "d", false, "dry run")
newCmd.Flags().BoolP("verbose", "v", false, "verbosely print out the go get commands")
newCmd.Flags().Bool("skip-pop", false, "skips adding pop/soda to your app")
newCmd.Flags().Bool("skip-webpack", false, "skips adding Webpack to your app")
newCmd.Flags().Bool("skip-yarn", false, "use npm instead of yarn for frontend dependencies management")
newCmd.Flags().String("db-type", "postgres", fmt.Sprintf("specify the type of database you want to use [%s]", strings.Join(pop.AvailableDialects, ", ")))
newCmd.Flags().String("docker", "multi", "specify the type of Docker file to generate [none, multi, standard]")
newCmd.Flags().String("ci-provider", "none", "specify the type of ci file you would like buffalo to generate [none, travis, gitlab-ci, circleci]")
newCmd.Flags().String("vcs", "git", "specify the Version control system you would like to use [none, git, bzr]")
newCmd.Flags().String("module", "", "specify the root module (package) name. [defaults to 'automatic']")
viper.BindPFlags(newCmd.Flags())
cfgFile := newCmd.PersistentFlags().String("config", "", "config file (default is $HOME/.buffalo.yaml)")
skipConfig := newCmd.Flags().Bool("skip-config", false, "skips using the config file")
cobra.OnInitialize(initConfig(skipConfig, cfgFile))
}

func initConfig(skipConfig *bool, cfgFile *string) func() {
return func() {
if *skipConfig {
return
}
decorate("new", new.Cmd)

// enable ability to specify config file via flag
if *cfgFile != "" {
viper.SetConfigFile(*cfgFile)
// Will error only if the --config flag is used
if err := viper.ReadInConfig(); err != nil {
configError = err
}
return
}

viper.SetConfigName(".buffalo") // name of config file (without extension)
viper.AddConfigPath("$HOME") // adding home directory as first search path
viper.AutomaticEnv() // read in environment variables that match
viper.ReadInConfig()
}
RootCmd.AddCommand(new.Cmd)
}

const notInGoWorkspace = `Oops! It would appear that you are not in your Go Workspace.

Your $GOPATH is set to "<%= gopath %>".

You are currently in "<%= current %>".

The standard location for putting Go projects is something along the lines of "$GOPATH/src/github.com/<%= username %>/<%= name %>" (adjust accordingly).

We recommend you go to "$GOPATH/src/github.com/<%= username %>/" and try "buffalo new <%= name %>" again.`
Loading