generate.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package commands
  2. import (
  3. "fmt"
  4. "strings"
  5. "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/common"
  6. "git.eugeniocarvalho.dev/eugeniucarvalho/apicodegen/flag"
  7. )
  8. const (
  9. // ComponentNameInput = 1
  10. )
  11. var ()
  12. func generateEntity() (err error) {
  13. var meta = flag.GenerateEntityControl
  14. entity := common.Entity{
  15. ID: strings.ToLower(meta.Name),
  16. Type: meta.Type,
  17. }
  18. for _, property := range strings.Split(meta.Properties, ",") {
  19. property = strings.Trim(property, " ")
  20. property = common.LcFirst(property)
  21. if property != "" {
  22. entity.Properties = append(entity.Properties, &common.Propertie{
  23. ID: property,
  24. })
  25. }
  26. }
  27. filename := normalizePath(meta.Name)
  28. if err = common.WriteToJson(
  29. basePathWithComplement(fmt.Sprintf("%s/%s.json", EntitiesPath, filename)),
  30. entity,
  31. ); err != nil {
  32. return
  33. }
  34. return
  35. }
  36. func generateResource() (err error) {
  37. var meta = flag.GenerateResourceControl
  38. resource := common.Resource{
  39. ID: strings.ToLower(meta.Name),
  40. Entity: meta.Entity,
  41. }
  42. for _, id := range strings.Split(meta.Methods, ",") {
  43. id = strings.Trim(id, " ")
  44. id = common.LcFirst(id)
  45. if id != "" {
  46. resource.Methods = append(resource.Methods, &common.Method{
  47. ID: id,
  48. })
  49. }
  50. }
  51. filename := normalizePath(meta.Name)
  52. if err = common.WriteToJson(
  53. basePathWithComplement(fmt.Sprintf("%s/%s.json", ResourcesPath, filename)),
  54. resource,
  55. ); err != nil {
  56. return
  57. }
  58. return
  59. }