tsgen

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	Name   string
	TSName string
	Fields []Field
}

Component is a component in the model.

func (Component) Referenced

func (c Component) Referenced() []ImportReference

Referenced returns import references for this Component.

type Converter

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

Converter converts types to typescript.

func NewConverter

func NewConverter(componentNames []string) *Converter

NewConverter creates an instance of Converter.

func (*Converter) Convert

func (c *Converter) Convert(t reflect.Type) (string, []string, error)

Convert converts a type to Typescript. It returns the typescript, a list of components that were reference.

type Field

type Field struct {
	Name     string
	Type     string
	Optional bool
	RefNames []string
}

Field is a struct field in a Component.

func ConvertField

func ConvertField(xType reflect.Type, i int, componentNames []string) (Field, bool)

ConvertField converts struct field a to a tsgen Field. If the field cannot be converted to a type script type, it will panic. If the field should be skipped, it will return false the second return value.

func (Field) TSFactoryType

func (f Field) TSFactoryType() string

TSFactoryType returns the typescript factory type for a field.

func (Field) TSNameToComponent

func (f Field) TSNameToComponent() string

TSNameToComponent converts a field to a component.

func (Field) TSType

func (f Field) TSType() string

TSType returns the typescript type for a field.

type ImportReference

type ImportReference struct {
	// Name is the name of the component.
	Name string
	// Import name is the name of the file that will be imported.
	ImportName string
}

ImportReference is a reference for an import that is used to build typescript imports.

type Model

type Model struct {
	Components     []Component
	ComponentNames []string
}

Model is a model contains information about components and their names.

type Option

type Option func(o *options)

Option is an option for configuration tsgen.

func DisableFormatter

func DisableFormatter() Option

DisableFormatter disables the typescript formatter.

type TSFormatter

type TSFormatter struct{}

TSFormatter formats typescript.

func NewTSFormatter

func NewTSFormatter() *TSFormatter

NewTSFormatter creates an instance of the typescript formatter.

func (*TSFormatter) Format

func (tf *TSFormatter) Format(in []byte) ([]byte, error)

Format formats the supplied typescript.

type TSGen

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

TSGen generates typescript for components.

func NewTSGen

func NewTSGen(options ...Option) (*TSGen, error)

NewTSGen creates an instance of TSGen.

func (*TSGen) Component

func (tg *TSGen) Component() ([]byte, error)

Component generates the typescript component interface.

func (*TSGen) ComponentConfig

func (tg *TSGen) ComponentConfig(c Component) ([]byte, error)

ComponentConfig generates a config interface and factory for a model component.

func (*TSGen) ComponentFactory

func (tg *TSGen) ComponentFactory() ([]byte, error)

ComponentFactory generates the typescript component factory interface.

func (*TSGen) Names

func (tg *TSGen) Names(source string) ([]string, error)

Names returns all the component names ina

func (*TSGen) Reflect

func (tg *TSGen) Reflect(names []string) (*Model, error)

Reflect reflects on list of components. It generates a temporary binary and runs that to get type information for components.

func (*TSGen) ReflectTemplate

func (tg *TSGen) ReflectTemplate(names []string) ([]byte, error)

ReflectTemplate generates a reflect template.

func (*TSGen) Stage

func (tg *TSGen) Stage(dest string, model *Model) error

Stage generates typescript for all components.

Jump to

Keyboard shortcuts

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