-
Notifications
You must be signed in to change notification settings - Fork 547
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve app scaffolding (#3839)
* Add new structure for app scaffolding * Fix some minor issues * Fix integration test plush * Add go mod tidy and fmt to scaffolding apps * Add changelog * Fix tests * Fix integration test package name * New app.ignite.yml format * Add AppYML * Add go.work.sum to app scaffold .gitignore * Upgrade app scaffold go.mod * Rename AppYML to AppsConfig * Add additional test for app scaffolding * Fix changelog * Improve app testing * Fix app_test.go * Move to cobra independent arch for app scaffolding * Fix plugin test * Fix changelog * Increase app scaffold integration test time * Update ignite/services/plugin/template/cmd/hello.go.plush Co-authored-by: Julien Robert <[email protected]> * Update ignite/services/plugin/template/integration/app_test.go.plush Co-authored-by: Danny <[email protected]> * Update ignite/services/plugin/template/cmd/cmd.go.plush Co-authored-by: Danny <[email protected]> * Update ignite/services/plugin/template/app.ignite.yml.plush Co-authored-by: Danny <[email protected]> * Update ignite/services/plugin/template/.gitignore.plush Co-authored-by: Danny <[email protected]> --------- Co-authored-by: Danilo Pantani <[email protected]> Co-authored-by: Julien Robert <[email protected]> Co-authored-by: Danny <[email protected]>
- Loading branch information
1 parent
2900024
commit 86ebb55
Showing
13 changed files
with
215 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package plugin | ||
|
||
// AppsConfig is the structure of app.ignite.yml file. | ||
type AppsConfig struct { | ||
Version uint `yaml:"version"` | ||
Apps map[string]AppInfo `yaml:"apps"` | ||
} | ||
|
||
// AppInfo is the structure of app info in app.ignite.yml file which only holds | ||
// the description and the relative path of the app. | ||
type AppInfo struct { | ||
Description string `yaml:"description"` | ||
Path string `yaml:"path"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
*.ign | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
go.work.sum | ||
|
||
# App | ||
<%= Name %>* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
version: 1 | ||
apps: | ||
<%= Name %>: | ||
description: <%= Name %> is an awesome Ignite application! | ||
path: ./ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import "github.com/ignite/cli/v28/ignite/services/plugin" | ||
|
||
// GetCommands returns the list of <%= Name %> app commands. | ||
func GetCommands() []*plugin.Command { | ||
return []*plugin.Command{ | ||
{ | ||
Use: "<%= Name %> [command]", | ||
Short: "<%= Name %> is an awesome Ignite application!", | ||
Commands: []*plugin.Command{ | ||
{ | ||
Use: "hello", | ||
Short: "Say hello to the world of ignite!", | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ignite/cli/v28/ignite/services/plugin" | ||
) | ||
|
||
// ExecuteHello executes the hello subcommand. | ||
func ExecuteHello(ctx context.Context, cmd *plugin.ExecutedCommand) error { | ||
fmt.Println("Hello, world!") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
ignite/services/plugin/template/integration/app_test.go.plush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package integration_test | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
pluginsconfig "github.com/ignite/cli/v28/ignite/config/plugins" | ||
"github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step" | ||
"github.com/ignite/cli/v28/ignite/services/plugin" | ||
envtest "github.com/ignite/cli/v28/integration" | ||
) | ||
|
||
func Test<%= Title %>(t *testing.T) { | ||
var ( | ||
require = require.New(t) | ||
env = envtest.New(t) | ||
app = env.Scaffold("github.com/test/test") | ||
) | ||
|
||
dir, err := os.Getwd() | ||
require.NoError(err) | ||
pluginPath := filepath.Join(filepath.Dir(filepath.Dir(dir)), "<%= Name %>") | ||
|
||
env.Must(env.Exec("install <%= Name %> app locally", | ||
step.NewSteps(step.New( | ||
step.Exec(envtest.IgniteApp, "app", "install", pluginPath), | ||
step.Workdir(app.SourcePath()), | ||
)), | ||
)) | ||
|
||
// One local plugin expected | ||
assertLocalPlugins(t, app, []pluginsconfig.Plugin{ | ||
{ | ||
Path: pluginPath, | ||
}, | ||
}) | ||
assertGlobalPlugins(t, app, nil) | ||
|
||
buf := &bytes.Buffer{} | ||
env.Must(env.Exec("run <%= Name %>", | ||
step.NewSteps(step.New( | ||
step.Exec( | ||
envtest.IgniteApp, | ||
"<%= Name %>", | ||
"hello", | ||
), | ||
step.Workdir(app.SourcePath()), | ||
step.Stdout(buf), | ||
)), | ||
)) | ||
require.Equal("Hello, world!\n", buf.String()) | ||
} | ||
|
||
func assertLocalPlugins(t *testing.T, app envtest.App, expectedPlugins []pluginsconfig.Plugin) { | ||
cfg, err := pluginsconfig.ParseDir(app.SourcePath()) | ||
require.NoError(t, err) | ||
require.ElementsMatch(t, expectedPlugins, cfg.Apps, "unexpected local apps") | ||
} | ||
|
||
func assertGlobalPlugins(t *testing.T, app envtest.App, expectedPlugins []pluginsconfig.Plugin) { | ||
cfgPath, err := plugin.PluginsPath() | ||
require.NoError(t, err) | ||
cfg, err := pluginsconfig.ParseDir(cfgPath) | ||
require.NoError(t, err) | ||
require.ElementsMatch(t, expectedPlugins, cfg.Apps, "unexpected global apps") | ||
} |
Oops, something went wrong.