Install dev dependencies before starting dev mode (#1615)

This commit is contained in:
Lea Anthony 2022-07-20 20:52:35 +10:00 committed by GitHub
commit b21a92ecdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View file

@ -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")

View file

@ -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 {