Skip to content

Commit

Permalink
feat(protobuf-gen-http): add a protobuf-http-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
stenehall committed Feb 7, 2022
1 parent adf661f commit 9a31a6b
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tools/sgprotocgentypescriptaip/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package sgprotocgentypescriptaip

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

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

const (
version = "0.1.2"
binaryName = "protoc-gen-typescript-aip"
)

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)
hostOS := runtime.GOOS
hostArch := runtime.GOARCH
if hostArch == sgtool.AMD64 {
hostArch = sgtool.X8664
}
// nolint: lll
downloadURL := fmt.Sprintf(
"https://github.com/einride/protoc-gen-typescript-aip/releases/download/v%s/protoc-gen-typescript-aip_%s_%s_%s.tar.gz",
version,
version,
hostOS,
hostArch,
)

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
}
57 changes: 57 additions & 0 deletions tools/sgprotocgentypescripthttp/tools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package sgprotocgentypescripthttp

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

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

const (
version = "0.7.0"
binaryName = "protoc-gen-typescript-http"
)

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)
hostOS := runtime.GOOS
hostArch := runtime.GOARCH
if hostArch == sgtool.AMD64 {
hostArch = sgtool.X8664
}
// nolint: lll
downloadURL := fmt.Sprintf(
"https://github.com/einride/protoc-gen-typescript-http/releases/download/v%s/protoc-gen-typescript-http_%s_%s_%s.tar.gz",
version,
version,
hostOS,
hostArch,
)

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 9a31a6b

Please sign in to comment.