mukan-ignite/ignite/pkg/cosmosgen/generate_go.go
Mukan Erkin Törük 26b204bd04
Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

53 lines
1.2 KiB
Go

package cosmosgen
import (
"context"
"os"
"path/filepath"
"github.com/otiai10/copy"
"github.com/ignite/cli/v29/ignite/pkg/errors"
)
func (g *generator) gogoTemplate() string {
return filepath.Join(g.appPath, g.protoDir, "buf.gen.gogo.yaml")
}
func (g *generator) protoPath() string {
return filepath.Join(g.appPath, g.protoDir)
}
func (g *generator) generateGoGo(ctx context.Context) error {
// create a temporary dir to locate generated code under which later only some of them will be moved to the
// app's source code. this also prevents having leftover files in the app's source code or its parent dir - when
// command executed directly there - in case of an interrupt.
tmp, err := os.MkdirTemp("", "")
if err != nil {
return err
}
defer os.RemoveAll(tmp)
// code generate for each module.
if err := g.buf.Generate(
ctx,
g.protoPath(),
tmp,
g.gogoTemplate(),
); err != nil {
return err
}
// move generated code for the app under the relative locations in its source code.
path := filepath.Join(tmp, g.goModPath)
if _, err := os.Stat(path); err == nil {
err = copy.Copy(path, g.appPath)
if err != nil {
return errors.Wrap(err, "cannot copy path")
}
} else if !os.IsNotExist(err) {
return err
}
return nil
}