diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index e69c8fec0..17d96e332 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/bitfield/script" "io" "net" "net/http" @@ -183,6 +184,28 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { signal.Notify(quitChannel, os.Interrupt, os.Kill, syscall.SIGTERM) exitCodeChannel := make(chan int, 1) + // Install if needed + installCommand := projectConfig.GetDevInstallerCommand() + if installCommand == "" { + return fmt.Errorf("no `frontend:dev` or `frontend:install` defined. Please add one of these to your wails.json") + } + + // Install initial frontend dev dependencies + err = os.Chdir(filepath.Join(cwd, "frontend")) + if err != nil { + return err + } + LogGreen("Installing frontend dependencies...") + pipe := script.Exec(installCommand) + pipe.Wait() + if pipe.Error() != nil { + return pipe.Error() + } + err = os.Chdir(cwd) + if err != nil { + return err + } + // frontend:dev:watcher command. if command := projectConfig.DevWatcherCommand; command != "" { closer, devServerURL, err := runFrontendDevWatcherCommand(cwd, command, projectConfig.FrontendDevServerURL == "auto") diff --git a/v2/internal/project/project.go b/v2/internal/project/project.go index 34db43acd..1098d9a6e 100644 --- a/v2/internal/project/project.go +++ b/v2/internal/project/project.go @@ -84,6 +84,13 @@ type Project struct { NSISType string `json:"nsisType"` } +func (p *Project) GetDevInstallerCommand() string { + if p.DevCommand != "" { + return p.DevCommand + } + return p.InstallCommand +} + func (p *Project) Save() error { data, err := json.MarshalIndent(p, "", " ") if err != nil {