mirror of
https://github.com/taigrr/wails.git
synced 2026-04-14 02:48:21 -07:00
[v2] Add forcebuild flag. Tags flag to dev. Refactor dev.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user