From fe5fc0657ffe59b064b7d0fa08f25258e99e131a Mon Sep 17 00:00:00 2001 From: Mari Date: Thu, 15 Jul 2021 05:16:46 -0400 Subject: [PATCH] Add more stuff to the magefiles. --- .idea/hexmap.iml | 1 + client/magefile.go | 19 ++++++++++++++++--- magefile.go | 4 +++- server/magefile.go | 35 +++++++++++++++-------------------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/.idea/hexmap.iml b/.idea/hexmap.iml index 7ccc5ba..1accc2b 100644 --- a/.idea/hexmap.iml +++ b/.idea/hexmap.iml @@ -12,6 +12,7 @@ + diff --git a/client/magefile.go b/client/magefile.go index c4e7b4c..d804115 100644 --- a/client/magefile.go +++ b/client/magefile.go @@ -1,5 +1,18 @@ -// +build mage - package client -const ProtocPluginPath = "client/node_modules/.bin/protoc-gen-ts_proto" \ No newline at end of file +import ( + "github.com/magefile/mage/mg" +) + +const ProtocPluginPath = "client/node_modules/.bin/protoc-gen-ts_proto" + +type Protobuf mg.Namespace + +// TODO: NPMInstall +// TODO: Protobuf:InstallTSPlugin +// TODO: Protobuf:InstallPlugins +// TODO: Protobuf:Build +// TODO: Protobuf:Clean +// TODO: Build +// TODO: Clean +// TODO: Serve diff --git a/magefile.go b/magefile.go index a2148eb..2bc9c95 100644 --- a/magefile.go +++ b/magefile.go @@ -3,6 +3,8 @@ package main import ( - // mage:import + // mage:import server _ "git.reya.zone/reya/hexmap/server" + // mage:import client + _ "git.reya.zone/reya/hexmap/client" ) diff --git a/server/magefile.go b/server/magefile.go index f64e3a8..15a365d 100644 --- a/server/magefile.go +++ b/server/magefile.go @@ -13,19 +13,13 @@ import ( "strings" ) +// TODO: GoGet +// TODO: Build +// TODO: Clean -func InstallZapMarshaler(ctx context.Context) error { - alreadyDone, err := build.HasExecutableInBuildtools("protoc-gen-zap-marshaler") - if err != nil { - return err - } - if alreadyDone { - return nil - } - return build.InstallGoExecutable(ctx, "github.com/kazegusuri/go-proto-zap-marshaler/protoc-gen-zap-marshaler@latest") -} +type Protobuf mg.Namespace -func InstallGoProtoc(ctx context.Context) error { +func (Protobuf) InstallGoPlugin(ctx context.Context) error { alreadyDone, err := build.HasExecutableInBuildtools("protoc-gen-go") if err != nil { return err @@ -36,21 +30,22 @@ func InstallGoProtoc(ctx context.Context) error { return build.InstallGoExecutable(ctx, "google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1") } -func InstallProtoDeps(ctx context.Context) { - mg.CtxDeps(ctx, InstallZapMarshaler, InstallGoProtoc) +func (Protobuf) InstallPlugins(ctx context.Context) { + mg.CtxDeps(ctx, Protobuf.InstallGoPlugin) } -type Protobuf mg.Namespace - -func (Protobuf) BuildProtocolBuffers(ctx context.Context) error { - mg.CtxDeps(ctx, InstallProtoDeps) +func (Protobuf) Build(ctx context.Context) error { + mg.CtxDeps(ctx, Protobuf.Clean, Protobuf.InstallPlugins) tooldir, err := build.GetBuildToolsDir() if err != nil { return err } - pluginPathFlag := fmt.Sprintf("--plugin=%s", path.Join(tooldir, "protoc-gen-go")) - cmd := exec.CommandContext(ctx, "protoc", pluginPathFlag, "-I=proto", "--go_out=.", "--go_opt=module=git.reya.zone/reya/hexmap", "proto/action.proto", "proto/client.proto", "proto/coords.proto", "proto/map.proto", "proto/server.proto", "proto/user.proto") + goPluginPathFlag := fmt.Sprintf("--plugin=%s", path.Join(tooldir, "protoc-gen-go")) + cmd := exec.CommandContext(ctx, "protoc", goPluginPathFlag, "-I=proto", "--go_out=.", "--go_opt=module=git.reya.zone/reya/hexmap", "proto/action.proto", "proto/client.proto", "proto/coords.proto", "proto/map.proto", "proto/server.proto", "proto/user.proto") cmd.Stderr = os.Stderr + if mg.Verbose() { + cmd.Stdout = os.Stdout + } return cmd.Run() } @@ -73,4 +68,4 @@ func (Protobuf) Clean(ctx context.Context) error { } return nil }) -} \ No newline at end of file +}