|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os/exec" |
| 6 | + |
| 7 | + "github.com/magefile/mage/mg" |
| 8 | +) |
| 9 | + |
| 10 | +type Dev mg.Namespace |
| 11 | + |
| 12 | +// InstallDependencies installs development tools required for the project. |
| 13 | +func (Dev) InstallDependencies() error { |
| 14 | + commands := [][]string{ |
| 15 | + {"brew", "install", "pre-commit"}, |
| 16 | + {"brew", "install", "bufbuild/buf/buf"}, |
| 17 | + {"pre-commit", "install"}, |
| 18 | + } |
| 19 | + |
| 20 | + for _, cmd := range commands { |
| 21 | + fmt.Printf("Running: %s\n", cmd) |
| 22 | + c := exec.Command(cmd[0], cmd[1:]...) |
| 23 | + if err := c.Run(); err != nil { |
| 24 | + return fmt.Errorf("failed to run %v: %w", cmd, err) |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + return nil |
| 29 | +} |
| 30 | + |
| 31 | +// BufGenerate builds the image and then produces results according to `buf.gen.yaml`. |
| 32 | +func (Dev) BufGenerate() error { |
| 33 | + fmt.Println("Running buf generate...") |
| 34 | + c := exec.Command("buf", "generate") |
| 35 | + if err := c.Run(); err != nil { |
| 36 | + return fmt.Errorf("failed to run buf generate: %w", err) |
| 37 | + } |
| 38 | + return nil |
| 39 | +} |
| 40 | + |
| 41 | +// BufBuild compiles protobuf files into an internal image format, verifying that the definitions are syntactically and semantically correct (e.g., resolving types, imports, etc.). |
| 42 | +func (Dev) BufBuild() error { |
| 43 | + fmt.Println("Running buf build...") |
| 44 | + c := exec.Command("buf", "build") |
| 45 | + if err := c.Run(); err != nil { |
| 46 | + return fmt.Errorf("failed to run buf build: %w", err) |
| 47 | + } |
| 48 | + return nil |
| 49 | +} |
0 commit comments