feat: funciones Wails — scaffold, CRUD bindings, build, eventos y streaming
Funciones Go para crear apps Wails: scaffold estructura, bind CRUD genérico, build multiplataforma, emit eventos y stream de datos al frontend. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// WailsBuildConfig configura la compilación de un proyecto Wails.
|
||||
type WailsBuildConfig struct {
|
||||
Dir string // Directorio del proyecto Wails
|
||||
Platform string // linux, windows, darwin (default: current)
|
||||
Output string // Nombre del binario de salida
|
||||
Debug bool // Build con debug info
|
||||
}
|
||||
|
||||
// WailsBuild compila un proyecto Wails para la plataforma especificada.
|
||||
func WailsBuild(ctx context.Context, cfg WailsBuildConfig) error {
|
||||
if cfg.Dir == "" {
|
||||
return fmt.Errorf("dir is required")
|
||||
}
|
||||
|
||||
args := []string{"build"}
|
||||
|
||||
if cfg.Platform != "" {
|
||||
args = append(args, "-platform", cfg.Platform)
|
||||
}
|
||||
if cfg.Output != "" {
|
||||
args = append(args, "-o", cfg.Output)
|
||||
}
|
||||
if cfg.Debug {
|
||||
args = append(args, "-debug")
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, "wails", args...)
|
||||
cmd.Dir = cfg.Dir
|
||||
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("wails build failed: %w\n%s", err, string(output))
|
||||
}
|
||||
|
||||
fmt.Printf("Built successfully: %s\n", strings.TrimSpace(string(output)))
|
||||
return nil
|
||||
}
|
||||
|
||||
// WailsDev lanza un proyecto Wails en modo desarrollo con hot reload.
|
||||
func WailsDev(ctx context.Context, dir string, browser bool) error {
|
||||
if dir == "" {
|
||||
return fmt.Errorf("dir is required")
|
||||
}
|
||||
|
||||
args := []string{"dev"}
|
||||
if browser {
|
||||
args = append(args, "-browser")
|
||||
}
|
||||
|
||||
cmd := exec.CommandContext(ctx, "wails", args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Stdout = nil // inherit
|
||||
cmd.Stderr = nil
|
||||
|
||||
return cmd.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user