diff --git a/cli/commands/config.go b/cli/commands/config.go index 904fadbd9..8a94d521d 100644 --- a/cli/commands/config.go +++ b/cli/commands/config.go @@ -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, +} diff --git a/cli/commands/format.go b/cli/commands/format.go index be02f2b7c..abcd9673e 100644 --- a/cli/commands/format.go +++ b/cli/commands/format.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/exec" + "slices" "github.com/urfave/cli/v2" ) @@ -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) @@ -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 { @@ -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 -} diff --git a/cli/commands/frontend.go b/cli/commands/frontend.go index 256ada89d..01c294b11 100644 --- a/cli/commands/frontend.go +++ b/cli/commands/frontend.go @@ -3,6 +3,7 @@ package commands import ( "os" "os/exec" + "slices" "github.com/urfave/cli/v2" ) @@ -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")) @@ -54,6 +54,8 @@ func RunFE(feType string, platform string) error { return RunMobileFE(platform) case "web": return RunWebFE() + case "dashboard": + return RunDashboardFE() default: return RunMobileFE(platform) } @@ -61,7 +63,7 @@ func RunFE(feType string, platform string) error { 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 @@ -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 } diff --git a/cli/commands/lint.go b/cli/commands/lint.go index 7a797bde5..bb4dcc00e 100644 --- a/cli/commands/lint.go +++ b/cli/commands/lint.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "os/exec" + "slices" "github.com/urfave/cli/v2" ) @@ -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) } @@ -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 { @@ -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 -} diff --git a/frontend/dashboard/package.json b/frontend/dashboard/package.json index 4710ea171..4f6ec323b 100644 --- a/frontend/dashboard/package.json +++ b/frontend/dashboard/package.json @@ -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" }, diff --git a/frontend/lib/package.json b/frontend/lib/package.json index d11cf9dfd..206ef576a 100644 --- a/frontend/lib/package.json +++ b/frontend/lib/package.json @@ -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, diff --git a/frontend/mobile/package.json b/frontend/mobile/package.json index e936e2822..8353a8ea5 100644 --- a/frontend/mobile/package.json +++ b/frontend/mobile/package.json @@ -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": {