Skip to content

Commit

Permalink
initalized frontend w/ login, contains persistance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DOOduneye committed Feb 12, 2024
1 parent 6917300 commit 8e14cb9
Show file tree
Hide file tree
Showing 29 changed files with 724 additions and 476 deletions.
1 change: 1 addition & 0 deletions cli/commands/be.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func RunBackendCommand() *cli.Command {
command := cli.Command{
Name: "be",
Usage: "Run the backend",
Category: "Development",
Action: func(c *cli.Context) error {
if c.Args().Len() > 0 {
return cli.Exit("Invalid arguments", 1)
Expand Down
81 changes: 81 additions & 0 deletions cli/commands/fe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package commands

import (
"os"
"os/exec"

_ "github.com/lib/pq"
"github.com/urfave/cli/v2"
)

func RunFrontendCommand() *cli.Command {
command := cli.Command{
Name: "fe",
Usage: "Run the frontend",
Category: "Development",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "target",
Aliases: []string{"t"},
Value: "mobile",
Usage: "Run a specific frontend type (web or mobile)",
},
&cli.StringFlag{
Name: "platform",
Aliases: []string{"p"},
Usage: "Run a specific platform for mobile frontend",
Value: "ios",
},
},
Action: func(c *cli.Context) error {
if c.Args().Len() > 0 {
return cli.Exit("Invalid arguments", 1)
}

target := c.String("target")
if target != "web" && target != "mobile" {
return cli.Exit("Invalid frontend type: must be 'web' or 'mobile'", 1)
}


err := RunFE(c.String("type"), c.String("platform"))
if err != nil {
return cli.Exit(err.Error(), 1)
}

return nil
},
}

return &command
}

func RunFE(feType string, platform string) error {
switch feType {
case "mobile":
return RunMobileFE(platform)
case "web":
return RunWebFE()
default:
return RunMobileFE(platform)
}
}

func RunMobileFE(platform string) error {
mobileCmd := exec.Command("yarn", "run", platform)
mobileCmd.Dir = FRONTEND_DIR + "/sac-mobile"

mobileCmd.Stdout = os.Stdout
mobileCmd.Stderr = os.Stderr
mobileCmd.Stdin = os.Stdin

if err := mobileCmd.Run(); err != nil {
return err
}

return nil
}

func RunWebFE() error {
return nil
}
131 changes: 75 additions & 56 deletions cli/commands/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,84 @@ package commands

import (
"fmt"
"os"
"os/exec"
"sync"

"github.com/urfave/cli/v2"
)

func FormatCommand() *cli.Command {
command := cli.Command{
Name: "format",
Usage: "Runs formatting tools",
Aliases: []string{"f"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "frontend",
command := cli.Command{
Name: "format",
Aliases: []string{"f"},
Usage: "Runs formatting tools",
Category: "CI",
Subcommands: []*cli.Command{
{
Name: "frontend",
Usage: "Format the frontend",
Aliases: []string{"f"},
Value: "",
Usage: "Formats a specific frontend folder",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "target",
Aliases: []string{"t"},
Value: "mobile",
Usage: "Format a specific frontend type (web or mobile)",
},
},
Action: func(c *cli.Context) error {
if c.Args().Len() > 0 {
return cli.Exit("Invalid arguments", 1)
}

target := c.String("target")
if target != "web" && target != "mobile" {
return cli.Exit("Invalid frontend type: must be 'web' or 'mobile'", 1)
}

err := FormatFrontend(target)
if err != nil {
return cli.Exit(err.Error(), 1)
}

return nil
},
},
&cli.BoolFlag{
Name: "backend",
{
Name: "backend",
Usage: "Format the backend",
Aliases: []string{"b"},
Usage: "Formats the backend",
Action: func(c *cli.Context) error {
if c.Args().Len() > 0 {
return cli.Exit("Invalid arguments", 1)
}

err := FormatBackend()
if err != nil {
return cli.Exit(err.Error(), 1)
}

return nil
},
},
},
Action: func(c *cli.Context) error {
if c.Args().Len() > 0 {
return cli.Exit("Invalid arguments", 1)
}

if c.String("frontend") == "" && !c.Bool("backend") {
return cli.Exit("Must specify frontend or backend", 1)
}

folder := c.String("frontend")
runFrontend := folder != ""
runBackend := c.Bool("backend")

Format(folder, runFrontend, runBackend)

return nil
},
}

return &command
}

func Format(folder string, runFrontend bool, runBackend bool) error {
var wg sync.WaitGroup

// Start the backend if specified
if runBackend {
wg.Add(1)
go func() {
defer wg.Done()
BackendFormat()
}()
}

// Start the frontend if specified
if runFrontend {
wg.Add(1)
go func() {
defer wg.Done()
FrontendFormat(folder)
}()
func FormatFrontend(target string) error {
switch target {
case "web":
return FormatWeb()
case "mobile":
return FormatMobile()
default:
return FormatMobile()
}

wg.Wait()

return nil
}

func BackendFormat() error {
func FormatBackend() error {
fmt.Println("Formatting backend")

cmd := exec.Command("gofumpt", "-l", "-w", ".")
Expand All @@ -89,7 +94,21 @@ func BackendFormat() error {
return nil
}

func FrontendFormat(folder string) error {
fmt.Println("UNIMPLEMENTED")
func FormatWeb() error {
return nil
}

func FormatMobile() error {
mobileCmd := exec.Command("yarn", "run", "format")
mobileCmd.Dir = FRONTEND_DIR + "/sac-mobile"

mobileCmd.Stdout = os.Stdout
mobileCmd.Stderr = os.Stderr
mobileCmd.Stdin = os.Stdin

if err := mobileCmd.Run(); err != nil {
return err
}

return nil
}
Loading

0 comments on commit 8e14cb9

Please sign in to comment.