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"))
|
||||
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 {
|
||||
log.Panic(err)
|
||||
|
||||
@ -1,18 +1,15 @@
|
||||
/**
|
||||
* kek
|
||||
* @readonly
|
||||
* lol
|
||||
* @kittenipc api
|
||||
*/
|
||||
class IpcApi {
|
||||
Mul(a: number, b: number): number {
|
||||
return a * b;
|
||||
Div(a: number, b: number): number {
|
||||
return a / b;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function main() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@ -20,17 +20,33 @@ func parseFlags() {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
type Method struct {
|
||||
Name string
|
||||
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
|
||||
Type ValType
|
||||
Children []Val
|
||||
}
|
||||
|
||||
type Endpoint struct {
|
||||
Name string
|
||||
Methods []Method
|
||||
type Method struct {
|
||||
Name string
|
||||
Pars []Val
|
||||
Ret []Val
|
||||
}
|
||||
|
||||
type Api struct {
|
||||
Endpoints []Endpoint
|
||||
Methods []Method
|
||||
}
|
||||
|
||||
type ApiParser interface {
|
||||
|
||||
@ -19,6 +19,7 @@ type TypescriptApiParser struct {
|
||||
}
|
||||
|
||||
type apiClass struct {
|
||||
methods []Method
|
||||
}
|
||||
|
||||
func (t *TypescriptApiParser) Parse(sourceFilePath string) (*Api, error) {
|
||||
@ -56,23 +57,79 @@ func (t *TypescriptApiParser) Parse(sourceFilePath string) (*Api, error) {
|
||||
return false
|
||||
}
|
||||
|
||||
var isApi bool
|
||||
|
||||
outer:
|
||||
for _, jsDocNode := range jsDocNodes {
|
||||
jsDoc := jsDocNode.AsJSDoc()
|
||||
for _, tag := range jsDoc.Tags.Nodes {
|
||||
if tag.TagName().Text() == TagName {
|
||||
for _, com := range tag.Comments() {
|
||||
if strings.TrimSpace(com.Text()) == TagComment {
|
||||
apiClasses = append(apiClasses, apiClass{})
|
||||
return false
|
||||
isApi = true
|
||||
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
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(apiClasses) == 0 {
|
||||
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, nil
|
||||
return &Api{Methods: apiClasses[0].methods}, nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user