nuclei/pkg/js/devtools/tsgen/cmd/tsgen/tsmodule.go.tmpl
Tarun Koyalwar 36985345a9
javascript bindings + docs generation enhancements ( generate typescript defination .d.ts files) (#4487)
* introduce typescript files generation using ast + tmpl

* feat valid ts with scraping

* feat remove old logic + tsdocs for all modules

* fix ikev and related bugs

* typescript docs for js modules

* lint,build + ldap realm fix

* go mod tidy

* fix named imports ast parsing

* fix ast code generation errors

* complete support for ts files generation

* support go global/const in ts docs

* updated template

* feat: typescript using go code generation

* nuke jsdoc generator

* update generated ts dir structure

* fix multifile ts gen issue

* fix panic in ts code gen

* fix test

* update docs of js libs

* feat: add doc+example for every js class,function,method

* fix missing quotes in ikev example

---------

Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
2024-02-07 21:45:40 +05:30

79 lines
2.0 KiB
Cheetah

{{- range .}}
{{ if eq .Type "const" -}}
{{ if .Description }}/** {{ .Description }} */{{- end }}
export const {{ .Name }} = {{ .Value }};
{{- else if eq .Type "class" -}}
/**
{{- range (splitLines .Description) }}
* {{ . }}
{{- end }}
*/
export class {{ .Name }} {
{{"\n"}}
{{- range $property := .Class.Properties }}
{{ if .Description }}
/**
{{- range (splitLines $property.Description) }}
* {{ . }}
{{- end }}
*/
{{ end }}
public {{ $property.Name }}?: {{ $property.Type }};
{{"\n"}}
{{- end }}
// Constructor of {{ .Name}}
{{- if eq (len .Class.Constructor.Parameters) 0 }}
constructor() {}
{{- else }}
constructor(
{{- range $index, $param := .Class.Constructor.Parameters }}
{{- if $index }}, {{ end }}{{ $param.Name }}: {{ $param.Type }}
{{- end }} ) {}
{{"\n"}}
{{- end }}
{{- range $method := .Class.Methods }}
/**
{{- range (splitLines $method.Description) }}
* {{ . }}
{{- end }}
*/
public {{ $method.Name }}({{ range $index, $element := $method.Parameters }}{{ if $index }}, {{ end }}{{ $element.Name }}: {{ $element.Type }}{{ end }}): {{ $method.Returns }} {
{{ $method.ReturnStmt }}
}
{{"\n"}}
{{- end }}
}
{{ else if eq .Type "function" -}}
/**
{{- range (splitLines .Description) }}
* {{ . }}
{{- end }}
*/
export function {{ .Name }}({{ range $index, $element := .Function.Parameters }}{{ if $index }}, {{ end }}{{ $element.Name }}: {{ $element.Type }}{{ end }}): {{ .Function.Returns }} {
{{ .Function.ReturnStmt }}
}
{{ else if eq .Type "interface" -}}
/**
{{- range (splitLines .Description) }}
* {{ . }}
{{- end }}
*/
export interface {{ .Name }} {
{{- range $property := .Object.Properties }}
{{ if .Description }}
/**
{{- range (splitLines .Description) }}
* {{ . }}
{{- end }}
*/
{{ end }}
{{ $property.Name }}?: {{ $property.Type }},
{{- end }}
}
{{ end }}
{{- end }}