Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(scaffolding): add --path for all scaffold, generate and chain commands #1518

Merged
merged 50 commits into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
58129cc
add appPath flag for all scaffold, generate and chain commands
Pantani Aug 27, 2021
7c6a8c4
use app path flag as a constant
Pantani Aug 27, 2021
7ba7b21
fix the wrong proto path
Pantani Aug 28, 2021
56f39f2
add dynamic path for box templates
Pantani Aug 29, 2021
a8b15d5
add aPath parameter to AddGenesisTest method
Pantani Aug 29, 2021
3def3f3
fix box walk path
Pantani Aug 29, 2021
9ffe49b
fix new chain path
Pantani Aug 29, 2021
2f8c9e4
fix protoc generation
Pantani Aug 29, 2021
1345225
improva code readbility
Pantani Aug 30, 2021
4dbcd6a
fix import sort for run.go
Pantani Aug 30, 2021
cd70713
add dynamic search for go module in the parent directories
Pantani Aug 30, 2021
2ad6a47
fix TestParse method
Pantani Aug 31, 2021
ffe5bc8
Merge branch 'develop' into feat/standardize-app-path-flag
Pantani Aug 31, 2021
22430e2
check if the the cosmos-sdk and the tendermint packages are imported
Pantani Aug 31, 2021
1636e5e
print the relative scaffold paths
Pantani Aug 31, 2021
498aa1d
Merge remote-tracking branch 'origin/develop' into feat/standardize-a…
Pantani Aug 31, 2021
6ec2bf6
Merge branch 'develop' into feat/standardize-app-path-flag
Pantani Sep 1, 2021
7d4e6cb
apply comment suggestions from PR
Pantani Sep 2, 2021
f9e165e
don't use Path structure to path the appPath var
Pantani Sep 3, 2021
f12e814
Merge branch 'develop' into feat/standardize-app-path-flag
Pantani Sep 3, 2021
f171e08
Apply suggestions from code review
ilgooz Sep 3, 2021
d184d03
fix some relative paths and remove unused method context
Pantani Sep 3, 2021
2379a74
move ValidateGoModule method
Pantani Sep 3, 2021
ad0acc5
Merge remote-tracking branch 'origin/develop' into feat/standardize-a…
Pantani Sep 3, 2021
f259ca2
fix lint
Pantani Sep 3, 2021
888673a
fix appPath for scaffold wasm
Pantani Sep 3, 2021
f115a81
Merge branch 'develop' into feat/standardize-app-path-flag
Pantani Sep 6, 2021
6958c48
Merge remote-tracking branch 'origin/develop' into feat/standardize-a…
Pantani Sep 7, 2021
c20c11a
remove global app path
Pantani Sep 7, 2021
6019145
fix merge conflicts
Pantani Sep 7, 2021
75bf2ee
move ValidateGoMod method to cosmosanalysis package
Pantani Sep 7, 2021
bac137d
fix missing path flag
Pantani Sep 7, 2021
2e76b72
Merge remote-tracking branch 'origin/develop' into feat/standardize-a…
Pantani Sep 7, 2021
b21194b
remove unused error return
Pantani Sep 7, 2021
ddd4995
fix path for genesis types test modifiers
Pantani Sep 7, 2021
cfd3d6c
improve app path description and removed unused flag
Pantani Sep 7, 2021
69a2aa8
change AppPath flag to Path
Pantani Sep 7, 2021
cec4db6
Merge remote-tracking branch 'origin/develop' into feat/standardize-a…
Pantani Sep 7, 2021
5c95e07
Merge branch 'develop' into feat/standardize-app-path-flag
Pantani Sep 8, 2021
ed52bc3
avoid generic path flag
Pantani Sep 8, 2021
9d09510
remove gomodulepath import from the cosmosanalysis pkg
Pantani Sep 8, 2021
4d09fa0
fix wrong app path
Pantani Sep 8, 2021
56212a2
remove unecessary conversion to absPath
Pantani Sep 8, 2021
53856f9
add integration test cases for custom app path
Pantani Sep 8, 2021
828f6a8
move relative path method to cmd
Pantani Sep 9, 2021
bcdb2af
create ValidateApp extension method for Scaffolder object and remove …
Pantani Sep 9, 2021
0b2224d
fix wrong method call
Pantani Sep 9, 2021
c79f118
add test path with a folder inside the project
Pantani Sep 10, 2021
30b8c5b
Merge branch 'develop' into feat/standardize-app-path-flag
Pantani Sep 10, 2021
2687bd8
refactor(scaffolder): w/ --path (#1568)
ilgooz Sep 13, 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
1 change: 1 addition & 0 deletions starport/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func NewChain() *cobra.Command {
Args: cobra.ExactArgs(1),
}

flagSetAppPath(c)
c.AddCommand(NewChainServe())
c.AddCommand(NewChainBuild())
c.AddCommand(NewChainInit())
Expand Down
3 changes: 2 additions & 1 deletion starport/cmd/chain_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ Sample usages:
Args: cobra.ExactArgs(0),
RunE: chainBuildHandler,
}

c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetProto3rdParty("Available only without the --release flag"))
c.Flags().StringVarP(&appPath, "path", "p", ".", "path of the app")
c.Flags().Bool(flagRelease, false, "build for a release")
c.Flags().StringSliceP(flagReleaseTargets, "t", []string{}, "release targets. Available only with --release flag")
c.Flags().String(flagReleasePrefix, "", "tarball prefix for each release target. Available only with --release flag")
c.Flags().BoolP("verbose", "v", false, "Verbose output")

return c
}

Expand Down
3 changes: 2 additions & 1 deletion starport/cmd/chain_faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ func NewChainFaucet() *cobra.Command {
Args: cobra.ExactArgs(2),
RunE: chainFaucetHandler,
}

c.Flags().AddFlagSet(flagSetHome())
c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")
c.Flags().BoolP("verbose", "v", false, "Verbose output")

return c
}

Expand Down
1 change: 0 additions & 1 deletion starport/cmd/chain_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func NewChainInit() *cobra.Command {
}

c.Flags().AddFlagSet(flagSetHome())
c.Flags().StringVarP(&appPath, "path", "p", "", "Path of the app")

return c
}
Expand Down
12 changes: 6 additions & 6 deletions starport/cmd/chain_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"github.com/tendermint/starport/starport/services/chain"
)

const flagForceReset = "force-reset"
const flagResetOnce = "reset-once"
const flagConfig = "config"

var appPath string
const (
flagForceReset = "force-reset"
flagResetOnce = "reset-once"
flagConfig = "config"
)

// NewChainServe creates a new serve command to serve a blockchain.
func NewChainServe() *cobra.Command {
Expand All @@ -20,9 +20,9 @@ func NewChainServe() *cobra.Command {
Args: cobra.ExactArgs(0),
RunE: chainServeHandler,
}

c.Flags().AddFlagSet(flagSetHome())
c.Flags().AddFlagSet(flagSetProto3rdParty(""))
c.Flags().StringVarP(&appPath, "path", "p", "", "Path of the app")
c.Flags().BoolP("verbose", "v", false, "Verbose output")
c.Flags().BoolP(flagForceReset, "f", false, "Force reset of the app state on start and every source change")
c.Flags().BoolP(flagResetOnce, "r", false, "Reset of the app state on first start")
Expand Down
11 changes: 9 additions & 2 deletions starport/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ import (
)

const (
flagAppPath = "path"
flagHome = "home"
flagProto3rdParty = "proto-all-modules"
)

const checkVersionTimeout = time.Millisecond * 600
checkVersionTimeout = time.Millisecond * 600
)

var (
appPath string
Pantani marked this conversation as resolved.
Show resolved Hide resolved

infoColor = color.New(color.FgYellow).SprintFunc()
)

Expand Down Expand Up @@ -89,6 +92,10 @@ func printEvents(bus events.Bus, s *clispinner.Spinner) {
}
}

func flagSetAppPath(cmd *cobra.Command) {
cmd.PersistentFlags().StringVarP(&appPath, flagAppPath, "p", ".", "path of the app")
Pantani marked this conversation as resolved.
Show resolved Hide resolved
}

func flagSetHome() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(flagHome, "", "Home directory used for blockchains")
Expand Down
1 change: 1 addition & 0 deletions starport/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Produced source code can be regenerated by running a command again and is not me
Args: cobra.ExactArgs(1),
}

flagSetAppPath(c)
c.AddCommand(NewGenerateGo())
c.AddCommand(NewGenerateVuex())
c.AddCommand(NewGenerateDart())
Expand Down
1 change: 1 addition & 0 deletions starport/cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CRUD stands for "create, read, update, delete".`,
Args: cobra.ExactArgs(1),
}

flagSetAppPath(c)
c.AddCommand(NewScaffoldChain())
c.AddCommand(NewScaffoldModule())
c.AddCommand(NewScaffoldList())
Expand Down
5 changes: 3 additions & 2 deletions starport/cmd/scaffold_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ func scaffoldChainHandler(cmd *cobra.Command, args []string) error {
noDefaultModule, _ = cmd.Flags().GetBool(flagNoDefaultModule)
)

sc, err := scaffolder.New("",
sc, err := scaffolder.New(
appPath,
scaffolder.AddressPrefix(addressPrefix),
)
if err != nil {
return err
}

appdir, err := sc.Init(placeholder.New(), name, noDefaultModule)
appdir, err := sc.Init(placeholder.New(), name, appPath, noDefaultModule)
Pantani marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion starport/cmd/scaffold_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func NewScaffoldList() *cobra.Command {
RunE: scaffoldListHandler,
}

c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")
c.Flags().AddFlagSet(flagSetScaffoldType())

return c
Expand Down
1 change: 0 additions & 1 deletion starport/cmd/scaffold_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func NewScaffoldMap() *cobra.Command {
RunE: scaffoldMapHandler,
}

c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")
c.Flags().AddFlagSet(flagSetScaffoldType())
c.Flags().StringSlice(FlagIndexes, []string{"index"}, "fields that index the value")

Expand Down
2 changes: 1 addition & 1 deletion starport/cmd/scaffold_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewScaffoldMessage() *cobra.Command {
Args: cobra.MinimumNArgs(1),
RunE: messageHandler,
}
c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")

c.Flags().String(flagModule, "", "Module to add the message into. Default: app's main module")
c.Flags().StringSliceP(flagResponse, "r", []string{}, "Response fields")
c.Flags().StringP(flagDescription, "d", "", "Description of the command")
Expand Down
2 changes: 1 addition & 1 deletion starport/cmd/scaffold_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewScaffoldQuery() *cobra.Command {
Args: cobra.MinimumNArgs(1),
RunE: queryHandler,
}
c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")

c.Flags().String(flagModule, "", "Module to add the query into. Default: app's main module")
c.Flags().StringSliceP(flagResponse, "r", []string{}, "Response fields")
c.Flags().StringP(flagDescription, "d", "", "Description of the command")
Expand Down
1 change: 0 additions & 1 deletion starport/cmd/scaffold_single.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func NewScaffoldSingle() *cobra.Command {
RunE: scaffoldSingleHandler,
}

c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")
c.Flags().AddFlagSet(flagSetScaffoldType())

return c
Expand Down
1 change: 0 additions & 1 deletion starport/cmd/scaffold_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func NewScaffoldType() *cobra.Command {
RunE: scaffoldTypeHandler,
}

c.Flags().StringVarP(&appPath, "path", "p", "", "path of the app")
c.Flags().AddFlagSet(flagSetScaffoldType())

return c
Expand Down
17 changes: 13 additions & 4 deletions starport/pkg/xgenny/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"os"
"path/filepath"

"github.com/gobuffalo/genny"
"github.com/gobuffalo/logger"
Expand Down Expand Up @@ -36,7 +37,10 @@ func RunWithValidation(
) (sm SourceModification, err error) {
// run executes the provided runner with the provided generator
run := func(runner *genny.Runner, gen *genny.Generator) error {
runner.With(gen)
err := runner.With(gen)
if err != nil {
return err
}
return runner.Run()
}
for _, gen := range gens {
Expand All @@ -55,17 +59,22 @@ func RunWithValidation(
// fetch the source modification
sm = NewSourceModification()
for _, file := range dryRunner.Results().Files {
_, err := os.Stat(file.Name())
fileName := file.Name()
if !filepath.IsAbs(fileName) {
fileName = filepath.Join(dryRunner.Root, fileName)
}

_, err := os.Stat(fileName)

// nolint:gocritic
if os.IsNotExist(err) {
// if the file doesn't exist in the source, it means it has been created by the runner
sm.AppendCreatedFiles(file.Name())
sm.AppendCreatedFiles(fileName)
} else if err != nil {
return sm, err
} else {
// the file has been modified by the runner
sm.AppendModifiedFiles(file.Name())
sm.AppendModifiedFiles(fileName)
}
}

Expand Down
7 changes: 4 additions & 3 deletions starport/pkg/xgenny/xgenny.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
type Walker struct {
fs embed.FS
trimPrefix string
path string
}

// NewEmbedWalker returns a new Walker for fs.
// trimPrefix is used to trim parent paths from the paths of found files.
func NewEmbedWalker(fs embed.FS, trimPrefix string) Walker {
return Walker{fs, trimPrefix}
func NewEmbedWalker(fs embed.FS, trimPrefix, path string) Walker {
return Walker{fs: fs, trimPrefix: trimPrefix, path: path}
}

// Walk implements packd.Walker.
Expand Down Expand Up @@ -46,7 +47,7 @@ func (w Walker) walkDir(wl packd.WalkFunc, path string) error {
}

ppath := strings.TrimPrefix(path, w.trimPrefix)

ppath = filepath.Join(w.path, ppath)
f, err := packd.NewFile(ppath, bytes.NewReader(data))
if err != nil {
return err
Expand Down
27 changes: 22 additions & 5 deletions starport/services/scaffolder/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,26 @@ var (

// Init initializes a new app with name and given options.
// path is the relative path to the scaffoled app.
func (s *Scaffolder) Init(tracer *placeholder.Tracer, name string, noDefaultModule bool) (path string, err error) {
func (s *Scaffolder) Init(tracer *placeholder.Tracer, name, appPath string, noDefaultModule bool) (path string, err error) {
pathInfo, err := gomodulepath.Parse(name)
if err != nil {
return "", err
}

pwd, err := os.Getwd()
if err != nil {
return "", err
}
absRoot := filepath.Join(pwd, pathInfo.Root)
// if the path is not set, use the current directory
if appPath == "" {
appPath = pwd
} else {
appPath, err = filepath.Abs(appPath)
if err != nil {
return "", err
}
}
absRoot := filepath.Join(appPath, pathInfo.Root)

// create the project
if err := s.generate(tracer, pathInfo, absRoot, noDefaultModule); err != nil {
Expand All @@ -51,10 +61,16 @@ func (s *Scaffolder) Init(tracer *placeholder.Tracer, name string, noDefaultModu
}

// initialize git repository and perform the first commit
if err := initGit(pathInfo.Root); err != nil {
if err := initGit(absRoot); err != nil {
return "", err
}

// get the relative app path from the current directory
relativePath, err := filepath.Rel(pwd, appPath)
Pantani marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return "", err
}
return pathInfo.Root, nil
return filepath.Join(relativePath, pathInfo.Root), nil
}

//nolint:interfacer
Expand All @@ -73,7 +89,7 @@ func (s *Scaffolder) generate(
// generate application template
ModulePath: pathInfo.RawPath,
AppName: pathInfo.Package,
AppPath: s.path,
AppPath: absRoot,
OwnerName: owner(pathInfo.RawPath),
OwnerAndRepoName: gu.UserAndRepo(),
BinaryNamePrefix: pathInfo.Root,
Expand All @@ -98,6 +114,7 @@ func (s *Scaffolder) generate(
ModuleName: pathInfo.Package, // App name
ModulePath: pathInfo.RawPath,
AppName: pathInfo.Package,
AppPath: absRoot,
OwnerName: owner(pathInfo.RawPath),
IsIBC: false,
}
Expand Down
9 changes: 3 additions & 6 deletions starport/services/scaffolder/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scaffolder

import (
"fmt"
"os"

"github.com/gobuffalo/genny"
"github.com/tendermint/starport/starport/pkg/field"
Expand Down Expand Up @@ -103,6 +102,7 @@ func (s *Scaffolder) AddMessage(
g *genny.Generator
opts = &message.Options{
AppName: path.Package,
AppPath: s.path,
ModulePath: path.RawPath,
ModuleName: moduleName,
OwnerName: owner(path.RawPath),
Expand All @@ -124,6 +124,7 @@ func (s *Scaffolder) AddMessage(
ModuleName: opts.ModuleName,
ModulePath: opts.ModulePath,
AppName: opts.AppName,
AppPath: opts.AppPath,
OwnerName: opts.OwnerName,
},
)
Expand All @@ -141,11 +142,7 @@ func (s *Scaffolder) AddMessage(
if err != nil {
return sm, err
}
pwd, err := os.Getwd()
if err != nil {
return sm, err
}
return sm, s.finish(pwd, path.RawPath)
return sm, s.finish(opts.AppPath, path.RawPath)
}

// checkForbiddenMessageField returns true if the name is forbidden as a message name
Expand Down
Loading