Skip to content

Commit

Permalink
feat: Rename project name to protoc-gen-venus
Browse files Browse the repository at this point in the history
  • Loading branch information
uanid committed Aug 23, 2023
1 parent dd5a790 commit 4321ec7
Show file tree
Hide file tree
Showing 75 changed files with 672 additions and 677 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
go.work

.idea/
examples/protoc-gen-vlossom
examples/example.vlossom.json
examples/protoc-gen-venus
examples/example.venus.json
**/request.pb.bin
**/request.pb.json
12 changes: 6 additions & 6 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ before:
hooks:
- go mod tidy
builds:
- id: protoc-gen-vlossom
main: cmd/protoc-gen-vlossom/main.go
binary: protoc-gen-vlossom
- id: protoc-gen-venus
main: cmd/protoc-gen-venus/main.go
binary: protoc-gen-venus
env:
- CGO_ENABLED=0
ldflags:
Expand All @@ -19,11 +19,11 @@ builds:
goarm:
- 8
archives:
- id: protoc-gen-vlossom-archive
- id: protoc-gen-venus-archive
name_template: |-
protoc-gen-vlossom_{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
protoc-gen-venus_{{ .Tag }}_{{ .Os }}_{{ .Arch -}}
builds:
- protoc-gen-vlossom
- protoc-gen-venus
format_overrides:
- goos: windows
format: zip
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ test:
go test ./... -v

install:
go install cmd/protoc-gen-vlossom/main.go
go install cmd/protoc-gen-venus/main.go
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# protoc-gen-vlossom
# protoc-gen-venus

Vlossom의 Dynamic Form을 만드는 proto plugin
venus의 Dynamic Form을 만드는 proto plugin

## Getting Started
1. protoc-gen-vlossom을 설치합니다.
1. protoc-gen-venus을 설치합니다.
```shell
go install github.com/pubg/protoc-gen-vlossom/cmd/protoc-gen-vlossom@latest
go install github.com/pubg/protoc-gen-venus/cmd/protoc-gen-venus@latest
```
또는 [여기](https://github.com/pubg/protoc-gen-vlossom/releases)에서 다운로드 받아 사용합니다.
또는 [여기](https://github.com/pubg/protoc-gen-venus/releases)에서 다운로드 받아 사용합니다.
2. proto/options.proto를 Workdir에 복사합니다.
3. 아래 내용대로 example.proto 파일을 생성합니다.
```
Expand All @@ -16,10 +16,10 @@ package schema;
import "options.proto";
option go_package = "github.com/sample";
option (pubg.vlossom.file) = {expose: true, entrypointMessage: "Values"};
option (pubg.venus.file) = {expose: true, entrypointMessage: "Values"};
message Values {
string sample_input = 1 [(pubg.vlossom.field) = {component: Input, input: {type: text, max: 10}}];
string sample_input = 1 [(pubg.venus.field) = {component: Input, input: {type: text, max: 10}}];
MyEnum my_enum = 2;
}
Expand All @@ -33,7 +33,7 @@ enum MyEnum {
4. 다음 명령어를 실행합니다.
```shell
protoc \
--vlossom_out=./ \
--venus_out=./ \
-I ./ \
./example.proto
```
Expand Down
2 changes: 1 addition & 1 deletion Roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
## 추후 과제
- [ ] 2차원 Location Override
- [x] Property Override
- [x] protobuf package name change to [pubg.vlossom]
- [x] protobuf package name change to [pubg.venus]
10 changes: 5 additions & 5 deletions cmd/protoc-gen-vlossom/main.go → cmd/protoc-gen-venus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"flag"

"github.com/pubg/protoc-gen-vlossom/generator"
"github.com/pubg/protoc-gen-vlossom/generator/protooptions"
"github.com/pubg/protoc-gen-venus/generator"
"github.com/pubg/protoc-gen-venus/generator/protoptions"

"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
Expand All @@ -16,14 +16,14 @@ func main() {
ParamFunc: flags.Set,
}

conf := &protooptions.PluginOptions{
conf := &protoptions.PluginOptions{
ExposeAll: flags.Bool("expose_all", false, `expose all fields, By default, only fields annotated with 'expose' are exposed.`),
OutputFileSuffix: flags.String("output_file_suffix", ".vlossom.json", `output file suffix`),
OutputFileSuffix: flags.String("output_file_suffix", ".venus.json", `output file suffix`),
PrettyOutput: flags.Bool("pretty_output", true, `pretty format json output`),
}

opts.Run(func(plugin *protogen.Plugin) error {
plugin.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
return generator.NewVlossomGenerator(plugin, conf).Run()
return generator.NewVenusGenerator(plugin, conf).Run()
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"path/filepath"
"testing"

"github.com/pubg/protoc-gen-vlossom/generator"
"github.com/pubg/protoc-gen-vlossom/generator/protooptions"
"github.com/pubg/protoc-gen-venus/generator"
"github.com/pubg/protoc-gen-venus/generator/protoptions"
"k8s.io/apimachinery/pkg/util/yaml"

"github.com/samber/lo"
Expand Down Expand Up @@ -40,9 +40,9 @@ func TestPlugin(t *testing.T) {
}

t.Run(testcase.Name, func(t *testing.T) {
response, err := toGenerateResponse(testRequest, &protooptions.PluginOptions{
response, err := toGenerateResponse(testRequest, &protoptions.PluginOptions{
ExposeAll: &[]bool{false}[0],
OutputFileSuffix: &[]string{".vlossom.json"}[0],
OutputFileSuffix: &[]string{".venus.json"}[0],
PrettyOutput: &[]bool{false}[0],
})
if err != nil {
Expand Down Expand Up @@ -93,7 +93,7 @@ func readTestCase(parentDir string, dir os.DirEntry) (*Testcase, *pluginpb.CodeG
return testcase, request, nil, nil
}

result, err := readVlossomResult(filepath.Join(path, testcase.ExpectResultFile))
result, err := readVenusResult(filepath.Join(path, testcase.ExpectResultFile))
if err != nil {
return nil, nil, nil, err
}
Expand Down Expand Up @@ -124,23 +124,23 @@ func readGeneratorRequest(path string) (*pluginpb.CodeGeneratorRequest, error) {
return req, nil
}

func readVlossomResult(path string) ([]any, error) {
func readVenusResult(path string) ([]any, error) {
buf, err := os.ReadFile(path)
if err != nil {
return nil, err
}
return toComparableComponent(buf)
}

func toGenerateResponse(request *pluginpb.CodeGeneratorRequest, options *protooptions.PluginOptions) (*pluginpb.CodeGeneratorResponse, error) {
func toGenerateResponse(request *pluginpb.CodeGeneratorRequest, options *protoptions.PluginOptions) (*pluginpb.CodeGeneratorResponse, error) {
opts := protogen.Options{}

plugin, err := opts.New(request)
if err != nil {
return nil, err
}

err = generator.NewVlossomGenerator(plugin, options).Run()
err = generator.NewVenusGenerator(plugin, options).Run()
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion examples/dump_example_request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eux
cd $(dirname $0)

protoc \
--plugin=protoc-gen-vlossom=prodoc-gen-debug \
--plugin=protoc-gen-venus=prodoc-gen-debug \
--debug_out=./ \
--debug_opt=parameter=expose_all=true \
-I ../proto \
Expand Down
22 changes: 11 additions & 11 deletions examples/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ package schema;

import "options.proto";

option go_package = "github.com/pubg/protoc-gen-vlossom/example/schema";
option go_package = "github.com/pubg/protoc-gen-venus/example/schema";

option (pubg.vlossom.file) = {expose: true, entrypointMessage: "Values"};
option (pubg.venus.file) = {expose: true, entrypointMessage: "Values"};

message Values {
FirstForm first = 1;
}

message FirstForm {
string name = 1 [(pubg.vlossom.field) = {component: Input, input: {type: text, max: 10}}];
SecondMessage second_message = 2 [(pubg.vlossom.field).expose = true];
string name = 1 [(pubg.venus.field) = {component: Input, input: {type: text, max: 10}}];
SecondMessage second_message = 2 [(pubg.venus.field).expose = true];
MyEnum my_enum = 3;
map<string, string> mymap = 4 [(pubg.vlossom.field) = {json_editor: {height: 10}}];
map<string, string> mymap = 4 [(pubg.venus.field) = {json_editor: {height: 10}}];

string v1 = 5 [(pubg.vlossom.field) = {default_string: "BAR", grid: {order: 0}}];
int32 v2 = 6 [(pubg.vlossom.field) = {default_integer: 123, grid: {order: 1}}];
double v3 = 7 [(pubg.vlossom.field)= {default_float: 583, messages: {state: success, text: "Success"}, messages: {state: info, text: "Info"}}];
string v1 = 5 [(pubg.venus.field) = {default_string: "BAR", grid: {order: 0}}];
int32 v2 = 6 [(pubg.venus.field) = {default_integer: 123, grid: {order: 1}}];
double v3 = 7 [(pubg.venus.field)= {default_float: 583, messages: {state: success, text: "Success"}, messages: {state: info, text: "Info"}}];
}

message SecondMessage {
option (pubg.vlossom.message).expose = true;
string a = 1 [(pubg.vlossom.field).label = "AAAAAAAA"];
string b = 2 [(pubg.vlossom.field) = {placeholder: "Input B", label: "BBBBBBBB"}];
option (pubg.venus.message).expose = true;
string a = 1 [(pubg.venus.field).label = "AAAAAAAA"];
string b = 2 [(pubg.venus.field) = {placeholder: "Input B", label: "BBBBBBBB"}];
}

enum MyEnum {
Expand Down
10 changes: 5 additions & 5 deletions examples/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ set -eux

cd $(dirname $0)

go build -o protoc-gen-vlossom ../cmd/protoc-gen-vlossom/main.go
go build -o protoc-gen-venus ../cmd/protoc-gen-venus/main.go

protoc \
--plugin=protoc-gen-vlossom=./protoc-gen-vlossom \
--vlossom_out=./ \
--vlossom_opt=expose_all=true \
--plugin=protoc-gen-venus=./protoc-gen-venus \
--venus_out=./ \
--venus_opt=expose_all=true \
-I ../proto \
-I ./ \
./example.proto

rm protoc-gen-vlossom
rm protoc-gen-venus
39 changes: 19 additions & 20 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ import (
"fmt"
"path/filepath"

"github.com/pubg/protoc-gen-vlossom/generator/protooptions"
"github.com/pubg/protoc-gen-vlossom/generator/vlossom"

"github.com/pubg/protoc-gen-venus/generator/protoptions"
"github.com/pubg/protoc-gen-venus/generator/venus"
"github.com/samber/lo"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
)

type VlossomGenerator struct {
type VenusGenerator struct {
plugin *protogen.Plugin
options *protooptions.PluginOptions
options *protoptions.PluginOptions
}

func NewVlossomGenerator(plugin *protogen.Plugin, options *protooptions.PluginOptions) *VlossomGenerator {
return &VlossomGenerator{plugin: plugin, options: options}
func NewVenusGenerator(plugin *protogen.Plugin, options *protoptions.PluginOptions) *VenusGenerator {
return &VenusGenerator{plugin: plugin, options: options}
}

func (g *VlossomGenerator) Run() error {
func (g *VenusGenerator) Run() error {
ctx := NewHierarchicalContext()
if *g.options.ExposeAll {
ctx.AppendExpose(g.options.ExposeAll)
Expand Down Expand Up @@ -56,9 +55,9 @@ func (g *VlossomGenerator) Run() error {
return nil
}

func (g *VlossomGenerator) buildFromFile(ctx *HierarchicalContext, file *protogen.File) ([]vlossom.Component, error) {
func (g *VenusGenerator) buildFromFile(ctx *HierarchicalContext, file *protogen.File) ([]venus.Component, error) {
fd := file.Desc
fo := protooptions.GetFileOptions(fd)
fo := protoptions.GetFileOptions(fd)
if fo == nil {
return nil, fmt.Errorf("FileOption must be set, File: %s", fd.Path())
}
Expand All @@ -75,16 +74,16 @@ func (g *VlossomGenerator) buildFromFile(ctx *HierarchicalContext, file *protoge
return g.buildFromMessage(ctx, message)
}

func (g *VlossomGenerator) buildFromMessage(ctx *HierarchicalContext, message *protogen.Message) ([]vlossom.Component, error) {
func (g *VenusGenerator) buildFromMessage(ctx *HierarchicalContext, message *protogen.Message) ([]venus.Component, error) {
md := message.Desc
mo := protooptions.GetMessageOptions(md)
mo := protoptions.GetMessageOptions(md)

ctx = NewFromHierarchicalContext(ctx)
if mo != nil {
ctx.AppendExpose(mo.Expose)
}

var resukt []vlossom.Component
var resukt []venus.Component
for _, field := range message.Fields {
nestedComponents, err := g.buildFromField(ctx, field)
if err != nil {
Expand All @@ -95,9 +94,9 @@ func (g *VlossomGenerator) buildFromMessage(ctx *HierarchicalContext, message *p
return resukt, nil
}

func (g *VlossomGenerator) buildFromField(ctx *HierarchicalContext, field *protogen.Field) ([]vlossom.Component, error) {
func (g *VenusGenerator) buildFromField(ctx *HierarchicalContext, field *protogen.Field) ([]venus.Component, error) {
fd := field.Desc
fo := protooptions.GetFieldOptions(fd)
fo := protoptions.GetFieldOptions(fd)

ctx = NewFromHierarchicalContext(ctx)
if fo != nil {
Expand All @@ -120,7 +119,7 @@ func (g *VlossomGenerator) buildFromField(ctx *HierarchicalContext, field *proto
if err != nil {
return nil, err
}
return []vlossom.Component{component}, nil
return []venus.Component{component}, nil
}

// Repeated Types
Expand All @@ -144,13 +143,13 @@ func (g *VlossomGenerator) buildFromField(ctx *HierarchicalContext, field *proto
if err != nil {
return nil, err
}
return []vlossom.Component{component}, nil
return []venus.Component{component}, nil
}

func (g *VlossomGenerator) generateToJson(components []vlossom.Component) ([]byte, error) {
var transformed [][]vlossom.Component
func (g *VenusGenerator) generateToJson(components []venus.Component) ([]byte, error) {
var transformed [][]venus.Component
for _, component := range components {
transformed = append(transformed, []vlossom.Component{component})
transformed = append(transformed, []venus.Component{component})
}
if *g.options.PrettyOutput {
return json.MarshalIndent(transformed, "", " ")
Expand Down
Loading

0 comments on commit 4321ec7

Please sign in to comment.