Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ build/
# vendor/
dist/

# Built frontend assets (regenerated by `make frontend`)
pkg/explorer/frontend/assets/
pkg/explorer/frontend/index.html

*.map
46 changes: 3 additions & 43 deletions pkg/explorer/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import (
"io/fs"
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"

"github.com/conductorone/baton-sdk/pkg/dotc1z"
Expand Down Expand Up @@ -58,51 +56,13 @@ func (ctrl *Controller) Run(addr string) error {
return ctrl.router(addr).Run(addr)
}

// TODO - this is a hack to get the frontend to work. Should be rewritten.
func runNpmInstallAndBuild(ctx context.Context, projectPath string) error {
nodeModulesPath := filepath.Join(projectPath, "node_modules")
if _, err := os.Stat(nodeModulesPath); os.IsNotExist(err) {
log.Default().Print("node_modules folder not found. Running npm install...")
cmd := exec.CommandContext(ctx, "npm", "install")
cmd.Dir = projectPath
output, err := cmd.CombinedOutput()
if err != nil {
log.Default().Print("Error running npm install:", err)
log.Default().Print(string(output))
return fmt.Errorf("error running 'npm install': %w", err)
}

log.Default().Print("npm install completed successfully.")
}

buildPath := filepath.Join(projectPath, "build")
if _, err := os.Stat(buildPath); os.IsNotExist(err) {
log.Default().Print("Build folder not found. Running npm build...")

cmd := exec.CommandContext(ctx, "npm", "run", "build")
cmd.Dir = projectPath
output, err := cmd.CombinedOutput()
if err != nil {
log.Default().Print("Error running npm build:", err)
log.Default().Print(string(output))
return fmt.Errorf("error running 'npm run build': %w", err)
}

log.Default().Print("npm build completed successfully.")
}
return nil
}

func (ctrl *Controller) router(addr string) *gin.Engine {
ctx := context.Background()
router := gin.Default()
api := router.Group("/api")
if !ctrl.baton.devMode {
err := runNpmInstallAndBuild(ctx, "frontend")
if err != nil {
log.Default().Println("error setting up frontend: ", err)
}
gin.SetMode(gin.ReleaseMode)
}
router := gin.Default()
api := router.Group("/api")

efs := newEmbeddedFS(frontend)
router.Use(static.Serve("/", efs))
Expand Down
1 change: 1 addition & 0 deletions pkg/explorer/frontend/assets/index-B5DZHykP.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions pkg/explorer/frontend/assets/index-DEzZ3ZSV.js

Large diffs are not rendered by default.

Loading
Loading