Add -clean option for bindings generation.

This commit is contained in:
Lea Anthony 2025-01-11 14:31:57 +11:00
commit c6f9ebe22d
No known key found for this signature in database
GPG key ID: 33DAF7BB90A58405
6 changed files with 14 additions and 2 deletions

View file

@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `wails3 generate template` command by [@leaanthony](https://github.com/leaanthony)
- `wails3 releasenotes` command by [@leaanthony](https://github.com/leaanthony)
- `wails3 update cli` command by [@leaanthony](https://github.com/leaanthony)
- `-clean` option for `wails3 generate bindings` command by [@leaanthony](https://github.com/leaanthony)
### Fixed

View file

@ -144,6 +144,7 @@ wails3 generate bindings [flags] [patterns...]
| `-dry` | Dry run | `false` |
| `-silent` | Silent mode | `false` |
| `-v` | Debug output | `false` |
| `-clean` | Clean output directory | `false` |
### `generate build-assets`
Generates build assets for your application.

View file

@ -47,7 +47,7 @@ tasks:
generates:
- "frontend/bindings/**/*"
cmds:
- wails3 generate bindings -f '{{.BUILD_FLAGS}}'{{if .UseTypescript}} -ts{{end}}
- wails3 generate bindings -f '{{.BUILD_FLAGS}}' -clean=true {{if .UseTypescript}} -ts{{end}}
generate:icons:
summary: Generates Windows `.ico` and Mac `.icns` files from an image

View file

@ -3,6 +3,7 @@ package commands
import (
"errors"
"fmt"
"os"
"path/filepath"
"github.com/pterm/pterm"
@ -37,6 +38,13 @@ func GenerateBindings(options *flags.GenerateBindingsOptions, patterns []string)
return err
}
// Clean the output directory if clean option is enabled
if options.Clean {
if err := os.RemoveAll(absPath); err != nil {
return fmt.Errorf("failed to clean output directory: %w", err)
}
}
// Initialise file creator.
var creator config.FileCreator
if !options.DryRun {

View file

@ -47,7 +47,8 @@ tasks:
generates:
- "frontend/bindings/**/*"
cmds:
- wails3 generate bindings -f {{ "'{{.BUILD_FLAGS}}'" }} {{if .Typescript}} -ts{{end}}
- wails3 generate bindings -f {{ "'{{.BUILD_FLAGS}}'" }} -clean=true {{if .Typescript}} -ts{{end}}
generate:icons:
summary: Generates Windows `.ico` and Mac `.icns` files from an image
dir: build

View file

@ -21,6 +21,7 @@ type GenerateBindingsOptions struct {
DryRun bool `name:"dry" description:"Do not write output files"`
Silent bool `name:"silent" description:"Silent mode"`
Verbose bool `name:"v" description:"Enable debug output"`
Clean bool `name:"clean" description:"Clean output directory before generation" default:"true"`
}
var ErrUnmatchedQuote = errors.New("build flags contain an unmatched quote")