This commit is contained in:
david 2024-02-27 21:02:40 +08:00
parent f26648abfd
commit f48415d46a
4 changed files with 84 additions and 45 deletions

View File

@ -6,27 +6,27 @@ export interface Crc {
export interface StatusReply {
status?: number;
identity?: string;
message?: string;
timeseq?: number;
status?: number; // 状态码
identity?: string; // 标识码
message?: string; // 状态说明
timeseq?: number; // 响应时间序列
}
export interface CheckForUpdatesRequest {
app?: string;
os?: string;
arch?: string;
version?: string;
app?: string; // 应用程序名称 <必填>
os?: string; // 操作系统 <必填>
arch?: string; // 构架名称 <必填>
version?: string; // 版本号 <必填>
}
export interface CheckForUpdatesReply {
identity?: string;
version?: string;
summary?: string;
files?: string;
pubdate?: string;
identity?: string; // 唯一码
version?: string; // 版本号
summary?: string; // 更析说明
files?: string; // 更新文件以及文件hash
pubdate?: string; // 发布时间
}
@ -36,21 +36,21 @@ export interface Empty {
export interface ConfigureRequest {
app?: string;
os?: string;
app?: string; // 应用程序名称 <必填>
os?: string; // 操作系统 <必填>
}
export interface ConfigureReply {
data?: ConfigureItem[];
data?: ConfigureItem[]; // 配置参数列表
}
export interface ConfigureItem {
Identity?: string;
key?: string;
value?: string;
version?: number;
Identity?: string; // 唯一标识
key?: string; // 配置键
value?: string; // 配置值
version?: number; // 版本号
}

View File

@ -1,7 +1,6 @@
package main
import (
"encoding/json"
"fmt"
"os"
"path"
@ -9,7 +8,8 @@ import (
"strings"
"git.apinb.com/bsm-sdk/engine/utils"
"github.com/tallstoat/pbparser"
"github.com/jhump/protoreflect/desc"
"github.com/jhump/protoreflect/desc/protoparse"
)
var (
@ -41,7 +41,8 @@ func getSubDirs(root string) []string {
}
func parseProtos(root, dir string) {
var msg []pbparser.MessageElement
//var msg []pbparser.MessageElement
var mess []*desc.MessageDescriptor
fPath := path.Join(root, dir)
tsPath := path.Join(jsPath, dir)
@ -52,24 +53,28 @@ func parseProtos(root, dir string) {
continue
} else {
pfPath := filepath.Join(fPath, file.Name())
pb, err := pbparser.ParseFile(pfPath)
Parser := protoparse.Parser{
IncludeSourceCodeInfo: true,
}
descs, err := Parser.ParseFiles(pfPath)
if err != nil {
panic(err)
}
msg = append(msg, pb.Messages...)
mess = append(mess, descs[0].GetMessageTypes()...)
}
}
writeTypes(tsPath, msg)
writeMessageTypes(tsPath, mess)
}
func writeSrvs(fileName string) {
}
func writeTypes(tsPath string, msg []pbparser.MessageElement) {
func writeMessageTypes(tsPath string, msg []*desc.MessageDescriptor) {
tpl := `
{{Commit}}
export interface {{Name}} {
@ -83,15 +88,18 @@ export interface {{Name}} {
var data []string
var msgBody = tpl
for _, fd := range msgItem.Fields {
for _, fd := range msgItem.GetFields() {
data = append(data, dispFields(fd))
}
keyFname := strings.ToLower(msgItem.Name)
keyFname := strings.ToLower(msgItem.GetName())
if _, ok := keyMap[keyFname]; !ok {
msgBody = strings.ReplaceAll(msgBody, "{{Commit}}", msgItem.Documentation)
msgBody = strings.ReplaceAll(msgBody, "{{Name}}", msgItem.Name)
var commit string = ""
if msgItem.GetSourceInfo().GetLeadingComments() != "" {
commit = msgItem.GetSourceInfo().GetLeadingComments()
}
msgBody = strings.ReplaceAll(msgBody, "{{Commit}}", commit)
msgBody = strings.ReplaceAll(msgBody, "{{Name}}", msgItem.GetName())
msgBody = strings.ReplaceAll(msgBody, "{{Data}}", strings.Join(data, "\r\n"))
bodys = append(bodys, msgBody)
@ -104,39 +112,47 @@ export interface {{Name}} {
}
func dispFields(fd pbparser.FieldElement) string {
func dispFields(fd *desc.FieldDescriptor) string {
tpl := " {{Name}}?: {{Type}}; {{Commit}}"
name := strings.Trim(fd.Name, "")
name := strings.Trim(fd.GetName(), "")
name = strings.ReplaceAll(name, "\t", "")
tpl = strings.ReplaceAll(tpl, "{{Name}}", name)
jsonByte, _ := json.Marshal(fd)
fmt.Println(string(jsonByte))
var commit string = ""
if fd.GetSourceInfo().GetLeadingComments() != "" {
commit = commit + fd.GetSourceInfo().GetLeadingComments() + " "
}
if fd.Documentation == "" {
if fd.GetSourceInfo().GetTrailingComments() != "" {
commit = commit + fd.GetSourceInfo().GetTrailingComments() + " "
}
if commit == "" {
tpl = strings.ReplaceAll(tpl, "{{Commit}}", "")
} else {
tpl = strings.ReplaceAll(tpl, "{{Commit}}", " // "+fd.Documentation)
tpl = strings.ReplaceAll(tpl, "{{Commit}}", " // "+commit)
}
var fdType string = ""
switch fd.Type.Name() {
case "string":
switch fd.GetType().String() {
case "TYPE_STRING":
fdType = "string"
case "int32", "int64", "float":
case "TYPE_INT64", "TYPE_INT32", "TYPE_FLOAT32", "TYPE_FLOAT64":
fdType = "number"
case "bool":
fdType = "bool"
fdType = "TYPE_BOOL"
default:
if fd.Label == "repeated" {
fdType = fd.Type.Name() + "[]"
if fd.GetLabel().String() == "LABEL_REPEATED" {
fdType = fd.GetMessageType().GetName() + "[]"
} else {
fdType = fd.Type.Name()
fdType = fd.GetType().String()
}
}
tpl = strings.ReplaceAll(tpl, "{{Type}}", fdType)
tpl = strings.ReplaceAll(tpl, "\r\n", "")
return tpl
}

8
go.mod
View File

@ -7,7 +7,15 @@ require (
github.com/tallstoat/pbparser v0.2.0
)
require (
github.com/bufbuild/protocompile v0.8.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/sync v0.5.0 // indirect
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1 // indirect
)
require (
github.com/google/uuid v1.6.0 // indirect
github.com/jaevor/go-nanoid v1.3.0 // indirect
github.com/jhump/protoreflect v1.15.6
)

15
go.sum
View File

@ -1,8 +1,23 @@
git.apinb.com/bsm-sdk/engine v1.0.5 h1:nsU+5suyRFaVqHhnrU9ontpgW+54cuY/+7OnI7VEa60=
git.apinb.com/bsm-sdk/engine v1.0.5/go.mod h1:tNYgBhykUTBtpH+4EdAamcKqMwpJ3XUJ0roKqxGM3lM=
github.com/bufbuild/protocompile v0.8.0 h1:9Kp1q6OkS9L4nM3FYbr8vlJnEwtbpDPQlQOVXfR+78s=
github.com/bufbuild/protocompile v0.8.0/go.mod h1:+Etjg4guZoAqzVk2czwEQP12yaxLJ8DxuqCJ9qHdH94=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jaevor/go-nanoid v1.3.0 h1:nD+iepesZS6pr3uOVf20vR9GdGgJW1HPaR46gtrxzkg=
github.com/jaevor/go-nanoid v1.3.0/go.mod h1:SI+jFaPuddYkqkVQoNGHs81navCtH388TcrH0RqFKgY=
github.com/jhump/protoreflect v1.15.6 h1:WMYJbw2Wo+KOWwZFvgY0jMoVHM6i4XIvRs2RcBj5VmI=
github.com/jhump/protoreflect v1.15.6/go.mod h1:jCHoyYQIJnaabEYnbGwyo9hUqfyUMTbJw/tAut5t97E=
github.com/tallstoat/pbparser v0.2.0 h1:lsFH4mdiOv1MIQVmge/idThSTd2uByNodWVfbtysjzg=
github.com/tallstoat/pbparser v0.2.0/go.mod h1:aUC6W9uQLeAXZkknve8ZDO6InhRYpYHlJ9kvsQh1i2k=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1 h1:fk72uXZyuZiTtW5tgd63jyVK6582lF61nRC/kGv6vCA=
google.golang.org/protobuf v1.31.1-0.20231027082548-f4a6c1f6e5c1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=