diff --git a/docs/src/content/docs/changelog.mdx b/docs/src/content/docs/changelog.mdx index 4f493caf9..c8c70355f 100644 --- a/docs/src/content/docs/changelog.mdx +++ b/docs/src/content/docs/changelog.mdx @@ -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 diff --git a/docs/src/content/docs/guides/cli.mdx b/docs/src/content/docs/guides/cli.mdx index 2148f56c7..4b9400f51 100644 --- a/docs/src/content/docs/guides/cli.mdx +++ b/docs/src/content/docs/guides/cli.mdx @@ -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. diff --git a/v3/examples/file-association/build/Taskfile.common.yml b/v3/examples/file-association/build/Taskfile.common.yml index 6aed2a68f..2b8a4d26d 100644 --- a/v3/examples/file-association/build/Taskfile.common.yml +++ b/v3/examples/file-association/build/Taskfile.common.yml @@ -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 diff --git a/v3/internal/commands/bindings.go b/v3/internal/commands/bindings.go index 89ce70376..478c16b21 100644 --- a/v3/internal/commands/bindings.go +++ b/v3/internal/commands/bindings.go @@ -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 { diff --git a/v3/internal/commands/build_assets/Taskfile.tmpl.yml b/v3/internal/commands/build_assets/Taskfile.tmpl.yml index 703a0def6..9ad50a8af 100644 --- a/v3/internal/commands/build_assets/Taskfile.tmpl.yml +++ b/v3/internal/commands/build_assets/Taskfile.tmpl.yml @@ -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 diff --git a/v3/internal/flags/bindings.go b/v3/internal/flags/bindings.go index 88d90182d..ab875213e 100644 --- a/v3/internal/flags/bindings.go +++ b/v3/internal/flags/bindings.go @@ -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")