Skip to content

Commit

Permalink
feat(protoc-gen-decap-cms): add Decap CMS proto generator
Browse files Browse the repository at this point in the history
  • Loading branch information
magnusewe committed Jul 9, 2024
1 parent 5ec5aad commit 3f8e39f
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tools/sgprotocgendecapcms/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package sgprotocgendecapcms

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"

"go.einride.tech/sage/sg"
"go.einride.tech/sage/sgtool"
)

const (
version = "1.1.0"
binaryName = "protoc-gen-decap-cms"
)

func Command(ctx context.Context, args ...string) *exec.Cmd {
sg.Deps(ctx, PrepareCommand)
return sg.Command(ctx, sg.FromBinDir(binaryName), args...)
}

func PrepareCommand(ctx context.Context) error {
binDir := sg.FromToolsDir(binaryName, version)
binary := filepath.Join(binDir, binaryName)
downloadURL := fmt.Sprintf(
"https://github.com/einride/protobuf-decap-cms/releases/download/v%s/protobuf-decap-cms_%s_%s_%s.tar.gz",
version,
version,
runtime.GOOS,
runtime.GOARCH,
)

if err := sgtool.FromRemote(
ctx,
downloadURL,
sgtool.WithDestinationDir(binDir),
sgtool.WithUntarGz(),
sgtool.WithSkipIfFileExists(binary),
sgtool.WithSymlink(binary),
); err != nil {
return fmt.Errorf("unable to download %s: %w", binaryName, err)
}
if err := os.Chmod(binary, 0o755); err != nil {
return fmt.Errorf("unable to make %s command: %w", binaryName, err)
}
return nil
}

0 comments on commit 3f8e39f

Please sign in to comment.