From ff8e701793879360e7843deef4a8b863c68c640e Mon Sep 17 00:00:00 2001 From: stffabi Date: Wed, 23 Feb 2022 10:12:59 +0100 Subject: [PATCH] [v2] Introduce frontend:dev:watcher command (#1170) --- v2/cmd/wails/internal/commands/dev/dev.go | 12 ++++++------ v2/internal/project/project.go | 5 ++++- website/docs/reference/project-config.mdx | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/v2/cmd/wails/internal/commands/dev/dev.go b/v2/cmd/wails/internal/commands/dev/dev.go index 904177914..5089f8380 100644 --- a/v2/cmd/wails/internal/commands/dev/dev.go +++ b/v2/cmd/wails/internal/commands/dev/dev.go @@ -142,10 +142,10 @@ func AddSubcommand(app *clir.Cli, w io.Writer) error { return err } - // frontend:dev server command. *Not concurrent* - if projectConfig.DevCommand != "" { + // frontend:dev:watcher command. + if command := projectConfig.DevWatcherCommand; command != "" { var devCommandWaitGroup sync.WaitGroup - closer := runFrontendDevCommand(cwd, projectConfig.DevCommand, &devCommandWaitGroup) + closer := runFrontendDevWatcherCommand(cwd, command, &devCommandWaitGroup) defer closer(&devCommandWaitGroup) } @@ -368,9 +368,9 @@ func loadAndMergeProjectConfig(cwd string, flags *devFlags) (*project.Project, e return projectConfig, nil } -// runFrontendDevCommand will run the `frontend:dev` command if it was given, ex- `npm run dev` -func runFrontendDevCommand(cwd string, devCommand string, wg *sync.WaitGroup) func(group *sync.WaitGroup) { - LogGreen("Running frontend dev command: '%s'", devCommand) +// runFrontendDevWatcherCommand will run the `frontend:dev:watcher` command if it was given, ex- `npm run dev` +func runFrontendDevWatcherCommand(cwd string, devCommand string, wg *sync.WaitGroup) func(group *sync.WaitGroup) { + LogGreen("Running frontend dev watcher command: '%s'", devCommand) ctx, cancel := context.WithCancel(context.Background()) dir := filepath.Join(cwd, "frontend") cmdSlice := strings.Split(devCommand, " ") diff --git a/v2/internal/project/project.go b/v2/internal/project/project.go index 02253f28d..61f5ea612 100644 --- a/v2/internal/project/project.go +++ b/v2/internal/project/project.go @@ -19,7 +19,10 @@ type Project struct { BuildCommand string `json:"frontend:build"` InstallCommand string `json:"frontend:install"` - DevCommand string `json:"frontend:dev"` + + // Commands used in `wails dev` + DevCommand string `json:"frontend:dev"` + DevWatcherCommand string `json:"frontend:dev:watcher"` // Directory to generate the API Module WailsJSDir string `json:"wailsjsdir"` diff --git a/website/docs/reference/project-config.mdx b/website/docs/reference/project-config.mdx index e03bf4844..524d13e69 100644 --- a/website/docs/reference/project-config.mdx +++ b/website/docs/reference/project-config.mdx @@ -13,7 +13,8 @@ The project config resides in the `wails.json` file in the project directory. Th "reloaddirs": "[Additional directories to trigger reloads (comma separated), this is only used for some advanced asset configurations]", "frontend:install": "[The command to install node dependencies, run in the frontend directory - often `npm install`]", "frontend:build": "[The command to build the assets, run in the frontend directory - often `npm run build`]", - "frontend:dev": "[This command is the dev equivalent of frontend:build]", + "frontend:dev": "[This command is the dev equivalent of frontend:build. If not specified falls back to frontend:build]", + "frontend:dev:watcher": "[This command is run in a separate process on `wails dev`. Useful for 3rd party watchers]", "wailsjsdir": "[Relative path to the directory that the auto-generated JS modules will be created]", "version": "[Project config version]", "outputfilename": "[The name of the binary]",