Skip to content

Commit

Permalink
feat: dashboard in cli (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Apr 26, 2024
1 parent 5ae64c2 commit e8e3859
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 78 deletions.
28 changes: 22 additions & 6 deletions cli/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,26 @@ import (
)

var (
ROOT_DIR, _ = utils.GetRootDir()
FRONTEND_DIR = filepath.Join(ROOT_DIR, "/frontend")
BACKEND_DIR = filepath.Join(ROOT_DIR, "/backend")
CONFIG = filepath.Join(ROOT_DIR, "/config")
MIGRATIONS = filepath.Join(BACKEND_DIR, "/migrations")
MOCK_FILE = filepath.Join(BACKEND_DIR, "/mock/data.sql")
ROOT_DIR, _ = utils.GetRootDir()
FRONTEND_DIR = filepath.Join(ROOT_DIR, "/frontend")
MOBILE_DIR = filepath.Join(FRONTEND_DIR, "/mobile")
DASHBOARD_DIR = filepath.Join(FRONTEND_DIR, "/dashboard")
LIB_DIR = filepath.Join(FRONTEND_DIR, "/lib")
WEB_DIR = filepath.Join(FRONTEND_DIR, "/web")
BACKEND_DIR = filepath.Join(ROOT_DIR, "/backend")
CONFIG = filepath.Join(ROOT_DIR, "/config")
MIGRATIONS = filepath.Join(BACKEND_DIR, "/migrations")
MOCK_FILE = filepath.Join(BACKEND_DIR, "/mock/data.sql")
)

var (
FRONTEND_RUN_TARGETS = []string{"web", "mobile", "dashboard"}
FRONTEND_CI_TARGETS = []string{"web", "mobile", "dashboard", "lib"}
)

var TARGET_DIRS = map[string]string{
"web": WEB_DIR,
"mobile": MOBILE_DIR,
"dashboard": DASHBOARD_DIR,
"lib": LIB_DIR,
}
48 changes: 20 additions & 28 deletions cli/commands/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"slices"

"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -33,8 +34,8 @@ func FormatCommand() *cli.Command {
}

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

err := FormatFrontend(target)
Expand Down Expand Up @@ -69,14 +70,24 @@ func FormatCommand() *cli.Command {
}

func FormatFrontend(target string) error {
switch target {
case "web":
return FormatWeb()
case "mobile":
return FormatMobile()
default:
return FormatMobile()
dir, ok := TARGET_DIRS[target]
if !ok {
return cli.Exit("Invalid frontend type", 1)
}

cmd := exec.Command("yarn", "run", "format")

cmd.Dir = dir

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

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

return nil
}

func FormatBackend() error {
Expand All @@ -93,22 +104,3 @@ func FormatBackend() error {
fmt.Println("Backend formatted")
return nil
}

func FormatWeb() error {
return nil
}

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

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

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

return nil
}
36 changes: 32 additions & 4 deletions cli/commands/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"os"
"os/exec"
"slices"

"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -31,9 +32,8 @@ func FrontendCommand() *cli.Command {
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)
if !slices.Contains(FRONTEND_RUN_TARGETS, c.String("target")) {
return cli.Exit("Invalid frontend type: must be 'web', 'mobile', or 'dashboard'", 1)
}

err := RunFE(c.String("type"), c.String("platform"))
Expand All @@ -54,14 +54,16 @@ func RunFE(feType string, platform string) error {
return RunMobileFE(platform)
case "web":
return RunWebFE()
case "dashboard":
return RunDashboardFE()
default:
return RunMobileFE(platform)
}
}

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

mobileCmd.Stdout = os.Stdout
mobileCmd.Stderr = os.Stderr
Expand All @@ -75,5 +77,31 @@ func RunMobileFE(platform string) error {
}

func RunWebFE() error {
webCmd := exec.Command("yarn", "run")
webCmd.Dir = WEB_DIR

webCmd.Stdout = os.Stdout
webCmd.Stderr = os.Stderr
webCmd.Stdin = os.Stdin

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

return nil
}

func RunDashboardFE() error {
dashboardCmd := exec.Command("yarn", "run")
dashboardCmd.Dir = DASHBOARD_DIR

dashboardCmd.Stdout = os.Stdout
dashboardCmd.Stderr = os.Stderr
dashboardCmd.Stdin = os.Stdin

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

return nil
}
59 changes: 22 additions & 37 deletions cli/commands/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/exec"
"slices"

"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -38,13 +39,11 @@ func LintCommand() *cli.Command {
}

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

fix := c.Bool("fix")

err := LintFrontend(target, fix)
err := LintFrontend(target)
if err != nil {
return cli.Exit(err.Error(), 1)
}
Expand Down Expand Up @@ -75,15 +74,25 @@ func LintCommand() *cli.Command {
return &command
}

func LintFrontend(target string, fix bool) error {
switch target {
case "web":
return LintWeb(fix)
case "mobile":
return LintMobile(fix)
default:
return LintMobile(fix)
func LintFrontend(target string) error {
dir, ok := TARGET_DIRS[target]
if !ok {
return cli.Exit("Invalid frontend type", 1)
}

cmd := exec.Command("yarn", "run", "lint")

cmd.Dir = dir

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin

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

return nil
}

func LintBackend() error {
Expand All @@ -101,27 +110,3 @@ func LintBackend() error {

return nil
}

func LintWeb(fix bool) error {
return nil
}

func LintMobile(fix bool) error {
var mobileCmd *exec.Cmd
if fix {
mobileCmd = exec.Command("yarn", "run", "lint", "--fix")
} else {
mobileCmd = exec.Command("yarn", "run", "lint")
}
mobileCmd.Dir = FRONTEND_DIR + "/mobile"

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

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

return nil
}
1 change: 0 additions & 1 deletion frontend/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
"format": "prettier --write .",
"test": "echo \"Woah there, we have no frontend tests as of right now. Let's just say we're passing.\" && exit 0"
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.1.0",
"scripts": {
"test": "echo \"Woah there, we have no frontend tests as of right now. Let's just say we're passing.\" && exit 0",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
"format": "prettier --write ."
},
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ios": "expo run:ios",
"web": "expo start --web",
"test": "echo \"Woah there, we have no frontend tests as of right now. Let's just say we're passing.\" && exit 0",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
"format": "prettier --write ."
},
"jest": {
Expand Down

0 comments on commit e8e3859

Please sign in to comment.