diff --git a/v2/cmd/wails/internal/commands/build/build.go b/v2/cmd/wails/internal/commands/build/build.go index f9541d3d..fb48ef7b 100644 --- a/v2/cmd/wails/internal/commands/build/build.go +++ b/v2/cmd/wails/internal/commands/build/build.go @@ -69,6 +69,9 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { skipFrontend := false command.BoolFlag("s", "Skips building the frontend", &skipFrontend) + forceBuild := false + command.BoolFlag("f", "Force build application", &forceBuild) + command.Action(func() error { quiet := verbosity == 0 @@ -152,6 +155,7 @@ func AddBuildSubcommand(app *clir.Cli, w io.Writer) { LDFlags: ldflags, Compiler: compilerCommand, Verbosity: verbosity, + ForceBuild: forceBuild, IgnoreFrontend: skipFrontend, Compress: compress, CompressFlags: compressFlags, diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index 0109a59d..595f8ceb 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -78,6 +78,10 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { wailsjsdir := "" command.StringFlag("wailsjsdir", "Directory to generate the Wails JS modules", &wailsjsdir) + // tags to pass to `go` + tags := "" + command.StringFlag("tags", "tags to pass to Go compiler (quoted and space separated)", &tags) + // Verbosity verbosity := 1 command.IntFlag("v", "Verbosity level (0 - silent, 1 - standard, 2 - verbose)", &verbosity) @@ -85,6 +89,9 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { loglevel := "" command.StringFlag("loglevel", "Loglevel to use - Trace, Dev, Info, Warning, Error", &loglevel) + forceBuild := false + command.BoolFlag("f", "Force build application", &forceBuild) + command.Action(func() error { // Create logger @@ -136,6 +143,21 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { } } + buildOptions := &build.Options{ + Logger: logger, + OutputType: "dev", + Mode: build.Dev, + Arch: runtime.GOARCH, + Pack: true, + Platform: runtime.GOOS, + LDFlags: ldflags, + Compiler: compilerCommand, + ForceBuild: forceBuild, + IgnoreFrontend: false, + Verbosity: verbosity, + WailsJSDir: wailsjsdir, + } + watcher, err := fsnotify.NewWatcher() if err != nil { return err @@ -162,7 +184,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { // Do initial build logger.Println("Building application for development...") - newProcess, appBinary, err := restartApp(logger, ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs, verbosity, assetDir, true, exitCodeChannel, wailsjsdir) + newProcess, appBinary, err := restartApp(logger, buildOptions, debugBinaryProcess, loglevel, passthruArgs, assetDir, false, exitCodeChannel) if err != nil { return err } @@ -269,7 +291,7 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { rebuild = false LogGreen("[Rebuild triggered] files updated") // Try and build the app - newBinaryProcess, _, err = restartApp(logger, ldflags, compilerCommand, debugBinaryProcess, loglevel, passthruArgs, verbosity, assetDir, false, exitCodeChannel, wailsjsdir) + newBinaryProcess, _, err = restartApp(logger, buildOptions, debugBinaryProcess, loglevel, passthruArgs, assetDir, false, exitCodeChannel) if err != nil { LogRed("Error during build: %s", err.Error()) continue @@ -314,9 +336,9 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { return nil } -func restartApp(logger *clilogger.CLILogger, ldflags string, compilerCommand string, debugBinaryProcess *process.Process, loglevel string, passthruArgs []string, verbosity int, assetDir string, firstRun bool, exitCodeChannel chan int, wailsjsdir string) (*process.Process, string, error) { +func restartApp(logger *clilogger.CLILogger, buildOptions *build.Options, debugBinaryProcess *process.Process, loglevel string, passthruArgs []string, assetDir string, firstRun bool, exitCodeChannel chan int) (*process.Process, string, error) { - appBinary, err := buildApp(logger, ldflags, compilerCommand, verbosity, wailsjsdir) + appBinary, err := build.Build(buildOptions) println() if err != nil { if firstRun { @@ -361,31 +383,3 @@ func restartApp(logger *clilogger.CLILogger, ldflags string, compilerCommand str return newProcess, appBinary, nil } - -func buildApp(logger *clilogger.CLILogger, ldflags string, compilerCommand string, verbosity int, wailsjsdir string) (string, error) { - - // Create random output file - outputFile := "wailsdev" - if runtime.GOOS == "windows" { - outputFile += ".exe" - } - - // Create BuildOptions - buildOptions := &build.Options{ - Logger: logger, - OutputType: "dev", - Mode: build.Dev, - Arch: runtime.GOARCH, - Pack: true, - Platform: runtime.GOOS, - LDFlags: ldflags, - Compiler: compilerCommand, - //OutputFile: outputFile, - IgnoreFrontend: false, - Verbosity: verbosity, - WailsJSDir: wailsjsdir, - } - - return build.Build(buildOptions) - -} diff --git a/v2/pkg/commands/build/base.go b/v2/pkg/commands/build/base.go index 14a3b5bd..49fba023 100644 --- a/v2/pkg/commands/build/base.go +++ b/v2/pkg/commands/build/base.go @@ -423,6 +423,11 @@ func (b *BaseBuilder) NpmInstallUsingCommand(sourceDir string, installCommand st install = true } + // check if forced install + if b.options.ForceBuild { + install = true + } + // Shortcut installation if install == false { return nil diff --git a/v2/pkg/commands/build/build.go b/v2/pkg/commands/build/build.go index 534ff134..3401d5cd 100644 --- a/v2/pkg/commands/build/build.go +++ b/v2/pkg/commands/build/build.go @@ -50,6 +50,7 @@ type Options struct { WebView2Strategy string // WebView2 installer strategy RunDelve bool // Indicates if we should run delve after the build WailsJSDir string // Directory to generate the wailsjs module + ForceBuild bool // Force } // Build the project! @@ -104,14 +105,7 @@ func Build(options *Options) (string, error) { // Initialise Builder builder.SetProjectData(projectData) - // Generate Frontend JS Package - // outputLogger.Println(" - Generating Backend JS Package") - // // Ignore the parser report coming back - // _, err = parser.GenerateWailsFrontendPackage() - // if err != nil { - // return "", err - // } - if !options.IgnoreFrontend { + if !options.IgnoreFrontend || options.ForceBuild { err = builder.BuildFrontend(outputLogger) if err != nil { return "", err