parser

package
v2.0.0-alpha.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package parser provides the ability to parse the data that is bound in Wails projects. Using this, it can also generate a Javascript module that represents the DTOs used, as well as providing wrappers for bound methods.

Index

Constants

View Source
const (
	// JsString is a JS string
	JsString JSType = "string"
	// JsBoolean is a JS bool
	JsBoolean = "boolean"
	// JsInt is a JS number
	JsInt = "number"
	// JsFloat is a JS number
	JsFloat = "number"
	// JsArray is a JS array
	JsArray = "Array"
	// JsObject is a JS object
	JsObject = "Object"
	// JsUnsupported represents a type that cannot be converted
	JsUnsupported = "*"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {

	// Name of the field
	Name string

	// The type of the field.
	// "struct" if it's a struct
	Type string

	// A pointer to the struct if the Type is "struct"
	Struct *Struct

	// User comments on the field
	Comments []string

	// Indicates if the Field is an array of type "Type"
	IsArray bool

	// JSON field name defined by a json tag
	JSONOptions
}

Field defines a parsed struct field

func (*Field) AsTSDeclaration

func (f *Field) AsTSDeclaration(pkgName string) string

AsTSDeclaration returns a TS definition of a single type field

func (*Field) JSName

func (f *Field) JSName() string

JSName returns the Javascript name for this field

func (*Field) JSType

func (f *Field) JSType() string

JSType returns the Javascript type for this field

func (*Field) NameForPropertyDoc

func (f *Field) NameForPropertyDoc() string

NameForPropertyDoc returns a formatted name for the jsdoc @property declaration

func (*Field) TSName

func (f *Field) TSName() string

TSName returns the Typescript name for this field

func (*Field) TypeAsTSType

func (f *Field) TypeAsTSType(pkgName string) string

TypeAsTSType converts the Field type to something TS wants

func (*Field) TypeForPropertyDoc

func (f *Field) TypeForPropertyDoc() string

TypeForPropertyDoc returns a formatted name for the jsdoc @property declaration

type JSONOptions

type JSONOptions struct {
	Name       string
	IsOptional bool
	Ignored    bool
}

type JSType

type JSType string

JSType represents a javascript type

type Method

type Method struct {
	Name     string
	Comments []string
	Inputs   []*Field
	Returns  []*Field
}

Method defines a struct method

func (*Method) InputsAsJSText

func (m *Method) InputsAsJSText() string

InputsAsJSText generates a string with the method inputs formatted in a way acceptable to Javascript

func (*Method) InputsAsTSText

func (m *Method) InputsAsTSText(pkgName string) string

InputsAsTSText generates a string with the method inputs formatted in a way acceptable to Typescript

func (*Method) OutputsAsTSDeclarationText

func (m *Method) OutputsAsTSDeclarationText(pkgName string) string

OutputsAsTSDeclarationText generates a string with the method inputs formatted in a way acceptable to Javascript

func (*Method) OutputsAsTSText

func (m *Method) OutputsAsTSText(pkgName string) string

OutputsAsTSText generates a string with the method inputs formatted in a way acceptable to Javascript

type Package

type Package struct {

	// A unique Name for this package.
	// This is calculated and may not be the same as the one
	// defined in Go - but that's ok!
	Name string

	// the package we are wrapping
	Gopackage *packages.Package
	// contains filtered or unexported fields
}

Package is a wrapper around the go parsed package

func (*Package) DeclarationReferences

func (p *Package) DeclarationReferences() []string

DeclarationReferences returns a list of external packages we reference from this package

func (*Package) HasBoundStructs

func (p *Package) HasBoundStructs() bool

HasBoundStructs returns true if any of its structs are bound

func (*Package) HasDataStructs

func (p *Package) HasDataStructs() bool

HasDataStructs returns true if any of its structs are used as data

func (*Package) ShouldGenerate

func (p *Package) ShouldGenerate() bool

ShouldGenerate returns true when this package should be generated

func (*Package) Structs

func (p *Package) Structs() []*Struct

Structs returns the structs that we want to generate

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser is the Wails project parser

func NewParser

func NewParser() *Parser

NewParser creates a new Wails project parser

func (*Parser) ParseProject

func (p *Parser) ParseProject(dir string) error

ParseProject will parse the Wails project in the given directory

type ParserReport

type ParserReport struct {
	Packages []*Package
}

func GenerateWailsFrontendPackage

func GenerateWailsFrontendPackage() (*ParserReport, error)

GenerateWailsFrontendPackage will generate a Javascript/Typescript package in `<project>/frontend/wails` that defines which methods and structs are bound to your frontend

type Struct

type Struct struct {

	// The name of the struct
	Name string

	// The package this was declared in
	Package *Package

	// Comments for the struct
	Comments []string

	// The fields used in this struct
	Fields []*Field

	// The methods available to the front end
	Methods []*Method

	// Indicates if this struct is bound to the app
	IsBound bool

	// Indicates if this struct is used as data
	IsUsedAsData bool
}

Struct represents a struct that is used by the frontend in a Wails project

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL