tons of code
This commit is contained in:
parent
22df76a97f
commit
ae855b08f8
@ -31,7 +31,11 @@ func main() {
|
|||||||
|
|
||||||
cmdStr := fmt.Sprintf("node %s", path.Join(cwd, "..", "ts/index.js"))
|
cmdStr := fmt.Sprintf("node %s", path.Join(cwd, "..", "ts/index.js"))
|
||||||
cmd := exec.Command(cmdStr)
|
cmd := exec.Command(cmdStr)
|
||||||
kit := kittenipc.New(cmd, &api)
|
|
||||||
|
kit, err := kittenipc.New(cmd, &api, kittenipc.Config{})
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := kit.Start(); err != nil {
|
if err := kit.Start(); err != nil {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* kek
|
|
||||||
* @readonly
|
|
||||||
* lol
|
|
||||||
* @kittenipc api
|
* @kittenipc api
|
||||||
*/
|
*/
|
||||||
class IpcApi {
|
class IpcApi {
|
||||||
Mul(a: number, b: number): number {
|
Div(a: number, b: number): number {
|
||||||
return a * b;
|
return a / b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,17 +20,33 @@ func parseFlags() {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
type Method struct {
|
type ValType int
|
||||||
|
|
||||||
|
// todo check TInt size < 64
|
||||||
|
// todo check not float
|
||||||
|
|
||||||
|
const (
|
||||||
|
TInt ValType = 1
|
||||||
|
TString ValType = 2
|
||||||
|
TBool ValType = 3
|
||||||
|
TBlob ValType = 4
|
||||||
|
TArray ValType = 5
|
||||||
|
)
|
||||||
|
|
||||||
|
type Val struct {
|
||||||
Name string
|
Name string
|
||||||
|
Type ValType
|
||||||
|
Children []Val
|
||||||
}
|
}
|
||||||
|
|
||||||
type Endpoint struct {
|
type Method struct {
|
||||||
Name string
|
Name string
|
||||||
Methods []Method
|
Pars []Val
|
||||||
|
Ret []Val
|
||||||
}
|
}
|
||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
Endpoints []Endpoint
|
Methods []Method
|
||||||
}
|
}
|
||||||
|
|
||||||
type ApiParser interface {
|
type ApiParser interface {
|
||||||
|
|||||||
@ -19,6 +19,7 @@ type TypescriptApiParser struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type apiClass struct {
|
type apiClass struct {
|
||||||
|
methods []Method
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TypescriptApiParser) Parse(sourceFilePath string) (*Api, error) {
|
func (t *TypescriptApiParser) Parse(sourceFilePath string) (*Api, error) {
|
||||||
@ -56,23 +57,79 @@ func (t *TypescriptApiParser) Parse(sourceFilePath string) (*Api, error) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isApi bool
|
||||||
|
|
||||||
|
outer:
|
||||||
for _, jsDocNode := range jsDocNodes {
|
for _, jsDocNode := range jsDocNodes {
|
||||||
jsDoc := jsDocNode.AsJSDoc()
|
jsDoc := jsDocNode.AsJSDoc()
|
||||||
for _, tag := range jsDoc.Tags.Nodes {
|
for _, tag := range jsDoc.Tags.Nodes {
|
||||||
if tag.TagName().Text() == TagName {
|
if tag.TagName().Text() == TagName {
|
||||||
for _, com := range tag.Comments() {
|
for _, com := range tag.Comments() {
|
||||||
if strings.TrimSpace(com.Text()) == TagComment {
|
if strings.TrimSpace(com.Text()) == TagComment {
|
||||||
apiClasses = append(apiClasses, apiClass{})
|
isApi = true
|
||||||
return false
|
break outer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !isApi {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var apiCls apiClass
|
||||||
|
|
||||||
|
for _, member := range cls.MemberList().Nodes {
|
||||||
|
if member.Kind != ast.KindMethodDeclaration {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
method := member.AsMethodDeclaration()
|
||||||
|
var apiMethod Method
|
||||||
|
apiMethod.Name = method.Name().Text()
|
||||||
|
for _, parNode := range method.ParameterList().Nodes {
|
||||||
|
par := parNode.AsParameterDeclaration()
|
||||||
|
var apiPar Val
|
||||||
|
apiPar.Name = par.Name().Text()
|
||||||
|
switch par.Type.Kind {
|
||||||
|
case ast.KindNumberKeyword:
|
||||||
|
apiPar.Type = TInt
|
||||||
|
case ast.KindStringKeyword:
|
||||||
|
apiPar.Type = TString
|
||||||
|
case ast.KindBooleanKeyword:
|
||||||
|
apiPar.Type = TBool
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("parameter type %s is not supported yet", par.Type.Kind)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
apiMethod.Pars = append(apiMethod.Pars, apiPar)
|
||||||
|
}
|
||||||
|
var apiRet Val
|
||||||
|
switch method.Type.Kind {
|
||||||
|
case ast.KindNumberKeyword:
|
||||||
|
apiRet.Type = TInt
|
||||||
|
case ast.KindStringKeyword:
|
||||||
|
apiRet.Type = TString
|
||||||
|
case ast.KindBooleanKeyword:
|
||||||
|
apiRet.Type = TBool
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("return type %s is not supported yet", method.Type.Kind)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
apiMethod.Ret = []Val{apiRet}
|
||||||
|
apiCls.methods = append(apiCls.methods, apiMethod)
|
||||||
|
}
|
||||||
|
|
||||||
|
apiClasses = append(apiClasses, apiCls)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if len(apiClasses) == 0 {
|
if len(apiClasses) == 0 {
|
||||||
return nil, fmt.Errorf("no api class found")
|
return nil, fmt.Errorf("no api class found")
|
||||||
}
|
}
|
||||||
@ -81,5 +138,5 @@ func (t *TypescriptApiParser) Parse(sourceFilePath string) (*Api, error) {
|
|||||||
return nil, fmt.Errorf("multiple api classes found")
|
return nil, fmt.Errorf("multiple api classes found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, nil
|
return &Api{Methods: apiClasses[0].methods}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user