react

package
v0.0.0-...-ae29a83 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddContextStore = command.InlineHandler[*ReactContextConfig](func(c *cli.Context, config *ReactContextConfig) error {
	contextName := strcase.ToCamel(fmt.Sprintf("%sContext", config.Name))
	contextFileName := strcase.ToKebab(fmt.Sprintf("%sContext", config.Name))
	hookFileName := strcase.ToKebab(fmt.Sprintf("use%s", contextName))

	var buffers []*bytes.Buffer
	for range 2 {
		buffers = append(buffers, new(bytes.Buffer))
	}
	tasks := []task.Task{
		task.NewSequentialScheduler().
			AddTask(task.NewReadFromProviderTask(provider.NewEmbedFileProvider("templates/react/react_context.go.tmpl"), buffers[0])).
			AddTask(task.NewTemplateRenderTask("react_context", map[string]string{"name": contextName}, buffers[0], buffers[0])).
			AddTask(task.NewWriteFileToDiskTask(contextFileName, ".tsx", buffers[0], task.WithFolder(config.OutDir))),
		task.NewSequentialScheduler().
			AddTask(task.NewReadFromProviderTask(provider.NewEmbedFileProvider("templates/react/react_context_hook.go.tmpl"), buffers[1])).
			AddTask(task.NewTemplateRenderTask("react_context_hook", map[string]string{"name": contextName, "file": contextFileName}, buffers[1], buffers[1])).
			AddTask(task.NewWriteFileToDiskTask(hookFileName, ".ts", buffers[1], task.WithFolder(config.OutDir))),
	}

	s := task.NewParallelScheduler()
	for _, t := range tasks {
		s.AddTask(t)
	}
	return s.Run()
})
View Source
var AddReactHook = command.InlineHandler[*ReactHookConfig](func(c *cli.Context, config *ReactHookConfig) error {
	varName := strcase.ToCamel(config.Name)
	filename := strcase.ToKebab(fmt.Sprintf("use%s", varName))

	var buffers []*bytes.Buffer
	for range 2 {
		buffers = append(buffers, new(bytes.Buffer))
	}

	tasks := []task.Task{
		task.NewSequentialScheduler().
			AddTask(task.NewReadFromProviderTask(provider.NewEmbedFileProvider("templates/react/react_hook.go.tmpl"), buffers[0])).
			AddTask(task.NewTemplateRenderTask("react_hook", map[string]string{"name": varName}, buffers[0], buffers[0])).
			AddTask(task.NewWriteFileToDiskTask(filename, ".ts", buffers[0], task.WithFolder(config.OutDir))),
	}

	if config.AddTest {
		tasks = append(tasks,
			task.NewSequentialScheduler().
				AddTask(task.NewReadFromProviderTask(provider.NewEmbedFileProvider("templates/react/react_hook_test.go.tmpl"), buffers[1])).
				AddTask(task.NewTemplateRenderTask("react_hook_test", map[string]string{"name": varName}, buffers[1], buffers[1])).
				AddTask(task.NewWriteFileToDiskTask(filename, ".test.ts", buffers[1], task.WithFolder(config.OutDir))))
	}

	s := task.NewParallelScheduler()
	for _, t := range tasks {
		s.AddTask(t)
	}
	return s.Run()
})
View Source
var AddZustandStore = command.InlineHandler[*ReactZustandConfig](func(c *cli.Context, config *ReactZustandConfig) error {
	varName := fmt.Sprintf("use%sStore", strcase.ToCamel(config.Name))
	filename := strcase.ToKebab(varName)

	b := new(bytes.Buffer)
	tasks := []task.Task{
		task.NewSequentialScheduler().
			AddTask(task.NewReadFromProviderTask(provider.NewEmbedFileProvider("templates/react/react_zustand.go.tmpl"), b)).
			AddTask(task.NewTemplateRenderTask("react_zustand", map[string]string{"name": filename}, b, b)).
			AddTask(task.NewWriteFileToDiskTask(filename, ".ts", b, task.WithFolder(config.OutDir))),
	}

	s := task.NewParallelScheduler()
	for _, t := range tasks {
		s.AddTask(t)
	}
	return s.Run()
})
View Source
var CommandSet = &cli.Command{
	Name:    "react",
	Aliases: []string{"r"},
	Usage:   "react kit",
	Subcommands: []*cli.Command{
		ReactComponentCmd,
		ReactHookCmd,
		ReactZustandCmd,
		ReactContextCmd,
	},
}
View Source
var ReactComponentCmd = command.NewCommand("component", "add react component",
	new(ReactComponentConfig),
	command.WithAlias([]string{"c"}),
).AddHandler(
	new(AddReactComponent),
).Create()
View Source
var ReactContextCmd = command.NewCommand("context", "add custom context",
	new(ReactContextConfig),
	command.WithAlias([]string{"ctx"}),
).AddHandler(
	AddContextStore,
).Create()
View Source
var ReactHookCmd = command.NewCommand("hook", "add react hook",
	new(ReactHookConfig),
	command.WithAlias([]string{"k"}),
).AddHandler(
	AddReactHook,
).Create()
View Source
var ReactZustandCmd = command.NewCommand("zustand", "add zustand store",
	new(ReactZustandConfig),
	command.WithAlias([]string{"z"}),
).AddHandler(
	AddZustandStore,
).Create()

Functions

This section is empty.

Types

type AddReactComponent

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

func (*AddReactComponent) Handle

func (arc *AddReactComponent) Handle(c *cli.Context, config *ReactComponentConfig) error

type ReactComponentConfig

type ReactComponentConfig struct {
	AddStory bool   `flag:"add-storybook" alias:"s" usage:"add storybook"`
	Isolated bool   `flag:"isolated" alias:"i" usage:"generate files in a folder"`
	OutDir   string `flag:"output" alias:"o" usage:"destination directory"`
	Name     string `arg:"0" alias:"COMPONENT_NAME" validate:"required,min=1,max=32,identifier"`
}

type ReactContextConfig

type ReactContextConfig struct {
	Name   string `arg:"0" alias:"CONTEXT_NAME" validate:"required,min=1,max=32,identifier"`
	OutDir string `flag:"output" alias:"o" usage:"destination directory"`
}

type ReactHookConfig

type ReactHookConfig struct {
	Name    string `arg:"0" alias:"HOOK_NAME" validate:"required,identifier"`
	OutDir  string `flag:"output" alias:"o" usage:"destination directory"`
	AddTest bool   `flag:"add-test" alias:"t" usage:"add associated hook test file"`
}

type ReactZustandConfig

type ReactZustandConfig struct {
	Name   string `arg:"0" alias:"STORE_NAME" validate:"required,identifier"`
	OutDir string `flag:"output" alias:"o" usage:"destination directory"`
}

Jump to

Keyboard shortcuts

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