Skip to content

Commit

Permalink
feat(gno.land/cmd): auto load and sort pkgs from examples (#763)
Browse files Browse the repository at this point in the history
* feat: add gno.mod to each package

* feat: add logic to load and sort gno pkgs

* feat(gno.land/cmd): auto load pkgs from examples

* fix failing tests

* Use more concise if statement

* Move pkg loading and sorting logic to gnomod

* Fix review comments

* Fix gno.mod files

* Extract visit() as named func

* Skip draft or depends on draft

* s/v0.0.0/v0.0.0-latest

* Fix `ListPkgs()`

* Test `ListPkgs()`

* oversight: remove print statement

* Export `Pkg` and add field `draft`

* Refactor and improvements

* make fmt

* ListPkgs(): don't skip nested pkgs

* Add gno.mod files to `tests/subtests`

* No need to subtests manually
  • Loading branch information
harry-hov committed Jun 19, 2023
1 parent 3ec10a9 commit 24770d5
Show file tree
Hide file tree
Showing 49 changed files with 661 additions and 43 deletions.
6 changes: 6 additions & 0 deletions examples/gno.land/p/demo/acl/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/p/demo/acl

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/testutils" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/avl/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/avl
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/bank/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/bank
6 changes: 6 additions & 0 deletions examples/gno.land/p/demo/blog/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/p/demo/blog

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
)
5 changes: 5 additions & 0 deletions examples/gno.land/p/demo/dom/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/p/demo/dom

require (
"gno.land/p/demo/avl" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/flow/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module "gno.land/p/demo/flow"
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/gnode/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module "gno.land/p/demo/gnode"
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/grc/exts/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/grc/exts
7 changes: 7 additions & 0 deletions examples/gno.land/p/demo/grc/grc1155/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/p/demo/grc/grc1155

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
)
7 changes: 7 additions & 0 deletions examples/gno.land/p/demo/grc/grc20/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/p/demo/grc/grc20

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
"gno.land/p/demo/grc/exts" v0.0.0-latest
)
7 changes: 7 additions & 0 deletions examples/gno.land/p/demo/grc/grc721/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/p/demo/grc/grc721

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
)
5 changes: 5 additions & 0 deletions examples/gno.land/p/demo/grc/grc777/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/p/demo/grc/grc777

require (
"gno.land/p/demo/grc/exts" v0.0.0-latest
)
7 changes: 7 additions & 0 deletions examples/gno.land/p/demo/groups/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/p/demo/groups

require (
"gno.land/r/demo/boards" v0.0.0-latest
"gno.land/p/demo/maths" v0.0.0-latest
"gno.land/p/demo/testutils" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/maths/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/maths
3 changes: 3 additions & 0 deletions examples/gno.land/p/demo/rand/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Draft

module gno.land/p/demo/rand
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/releases/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/releases
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/stack/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/stack
6 changes: 6 additions & 0 deletions examples/gno.land/p/demo/tests/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/p/demo/tests

require (
"gno.land/p/demo/tests/subtests" v0.0.0-latest
"gno.land/r/demo/tests" v0.0.0-latest
)
4 changes: 4 additions & 0 deletions examples/gno.land/p/demo/tests/subtests/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module gno.land/p/demo/tests/subtests

// TODO: this file should not exist.
// This is a temporary workaround. Until https://github.com/gnolang/gno/issues/852
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/testutils/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/testutils
1 change: 1 addition & 0 deletions examples/gno.land/p/demo/ufmt/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/p/demo/ufmt
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/art/gnoface/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/art/gnoface

require (
"gno.land/p/demo/rand" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
)
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/art/millipede/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/r/demo/art/millipede

require (
"gno.land/p/demo/ufmt" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/banktest/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/banktest
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/boards/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/boards

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/deep/very/deep/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/deep/very/deep
7 changes: 7 additions & 0 deletions examples/gno.land/r/demo/foo1155/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/r/demo/foo1155

require (
"gno.land/p/demo/ufmt" v0.0.0-latest
"gno.land/p/demo/grc/grc1155" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
)
7 changes: 7 additions & 0 deletions examples/gno.land/r/demo/foo20/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/r/demo/foo20

require (
"gno.land/p/demo/ufmt" v0.0.0-latest
"gno.land/p/demo/grc/grc20" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
)
7 changes: 7 additions & 0 deletions examples/gno.land/r/demo/foo721/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/r/demo/foo721

require (
"gno.land/p/demo/ufmt" v0.0.0-latest
"gno.land/p/demo/grc/grc721" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
)
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/groups/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/groups

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/r/demo/users" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/r/demo/markdown_test/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/demo/markdown_test
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/nft/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/nft

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/grc/grc721" v0.0.0-latest
)
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/releases_example/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/r/demo/releases_example

require (
"gno.land/p/demo/releases" v0.0.0-latest
)
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/tests/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/tests

require (
"gno.land/p/demo/testutils" v0.0.0-latest
"gno.land/r/demo/tests/subtests" v0.0.0-latest
)
4 changes: 4 additions & 0 deletions examples/gno.land/r/demo/tests/subtests/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module gno.land/r/demo/tests/subtests

// TODO: this file should not exist.
// This is a temporary workaround. Until https://github.com/gnolang/gno/issues/852
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/tests_foo/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/r/demo/tests_foo

require (
"gno.land/r/demo/tests" v0.0.0-latest
)
5 changes: 5 additions & 0 deletions examples/gno.land/r/demo/types/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/r/demo/types

require (
"gno.land/p/demo/avl" v0.0.0-latest
)
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/users/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/users

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/testutils" v0.0.0-latest
)
6 changes: 6 additions & 0 deletions examples/gno.land/r/demo/x/outfmt/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/demo/x/outfmt

require (
"gno.land/p/demo/rand" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
)
3 changes: 3 additions & 0 deletions examples/gno.land/r/demo/x/upgrade/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Draft

module gno.land/r/demo/x/upgrade
6 changes: 6 additions & 0 deletions examples/gno.land/r/gnoland/blog/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module gno.land/r/gnoland/blog

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/blog" v0.0.0-latest
)
7 changes: 7 additions & 0 deletions examples/gno.land/r/gnoland/faucet/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module gno.land/r/gnoland/faucet

require (
"gno.land/p/demo/avl" v0.0.0-latest
"gno.land/p/demo/testutils" v0.0.0-latest
"gno.land/p/demo/ufmt" v0.0.0-latest
)
5 changes: 5 additions & 0 deletions examples/gno.land/r/system/names/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module gno.land/r/system/names

require (
"gno.land/p/demo/avl" v0.0.0-latest
)
1 change: 1 addition & 0 deletions examples/gno.land/r/system/rewards/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/system/rewards
1 change: 1 addition & 0 deletions examples/gno.land/r/system/validators/gno.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module gno.land/r/system/validators
45 changes: 19 additions & 26 deletions gno.land/cmd/gnoland/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/gnolang/gno/gno.land/pkg/gnoland"
gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/pkg/gnomod"
"github.com/gnolang/gno/tm2/pkg/amino"
abci "github.com/gnolang/gno/tm2/pkg/bft/abci/types"
"github.com/gnolang/gno/tm2/pkg/bft/config"
Expand Down Expand Up @@ -228,33 +229,25 @@ func makeGenesisDoc(
// Load initial packages from examples.
test1 := crypto.MustAddressFromString("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
txs := []std.Tx{}
for _, path := range []string{
"p/demo/ufmt",
"p/demo/avl",
"p/demo/grc/exts",
"p/demo/grc/grc20",
"p/demo/grc/grc721",
"p/demo/grc/grc1155",
"p/demo/maths",
"p/demo/blog",
"r/demo/users",
"r/demo/foo20",
"r/demo/foo1155",
"r/demo/boards",
"r/demo/banktest",
"r/demo/types",
"r/demo/markdown_test",
"r/gnoland/blog",
"r/gnoland/faucet",
"r/system/validators",
"r/system/names",
"r/system/rewards",
"r/demo/deep/very/deep",
} {

// List initial packages to load from examples.
pkgs, err := gnomod.ListPkgs(filepath.Join("..", "examples"))
if err != nil {
panic(fmt.Errorf("listing gno packages: %w", err))
}

// Sort packages by dependencies.
sortedPkgs, err := pkgs.Sort()
if err != nil {
panic(fmt.Errorf("sorting packages: %w", err))
}

// Filter out draft packages.
nonDraftPkgs := sortedPkgs.GetNonDraftPkgs()

for _, pkg := range nonDraftPkgs {
// open files in directory as MemPackage.
fsPath := filepath.Join("..", "examples", "gno.land", path)
importPath := "gno.land/" + path
memPkg := gno.ReadMemPackage(fsPath, importPath)
memPkg := gno.ReadMemPackage(pkg.Path(), pkg.Name())
var tx std.Tx
tx.Msgs = []std.Msg{
vmm.MsgAddPackage{
Expand Down
Loading

0 comments on commit 24770d5

Please sign in to comment.