gen.go 894 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package tsgen
  2. import (
  3. "errors"
  4. "fmt"
  5. "git.i2edu.net/i2/go-zero/core/logx"
  6. "git.i2edu.net/i2/go-zero/tools/goctl/api/parser"
  7. "git.i2edu.net/i2/go-zero/tools/goctl/util"
  8. "github.com/logrusorgru/aurora"
  9. "github.com/urfave/cli"
  10. )
  11. // TsCommand provides the entry to generate typescript codes
  12. func TsCommand(c *cli.Context) error {
  13. apiFile := c.String("api")
  14. dir := c.String("dir")
  15. webAPI := c.String("webapi")
  16. caller := c.String("caller")
  17. unwrapAPI := c.Bool("unwrap")
  18. if len(apiFile) == 0 {
  19. return errors.New("missing -api")
  20. }
  21. if len(dir) == 0 {
  22. return errors.New("missing -dir")
  23. }
  24. api, err := parser.Parse(apiFile)
  25. if err != nil {
  26. fmt.Println(aurora.Red("Failed"))
  27. return err
  28. }
  29. logx.Must(util.MkdirIfNotExist(dir))
  30. logx.Must(genHandler(dir, webAPI, caller, api, unwrapAPI))
  31. logx.Must(genComponents(dir, api))
  32. fmt.Println(aurora.Green("Done."))
  33. return nil
  34. }