4 Commits

Author SHA1 Message Date
pk
dca493bfdc Allow different source folder when serving 2025-10-07 15:56:35 +02:00
pk
faadc3eb6f bump version 2025-08-25 11:56:59 +02:00
pk
51be76d4ad Find a free port for livereload by default. 2025-08-25 11:56:41 +02:00
pk
2efa8b43a3 Make sure build errors let the build command exit with a error code. 2025-08-06 20:43:38 +02:00
2 changed files with 18 additions and 5 deletions

View File

@@ -35,7 +35,11 @@ func buildAction(ctx *cli.Context) error {
esBuildCfg.Plugins = append(esBuildCfg.Plugins, contentSwapPlugin(o)) esBuildCfg.Plugins = append(esBuildCfg.Plugins, contentSwapPlugin(o))
api.Build(esBuildCfg) result := api.Build(esBuildCfg)
if len(result.Errors) > 0 {
os.Exit(1)
}
replace(o) replace(o)
if ctx.Bool("p") && o.ProductionBuildOptions.CmdPostBuild != "" { if ctx.Bool("p") && o.ProductionBuildOptions.CmdPostBuild != "" {

17
main.go
View File

@@ -26,7 +26,7 @@ func main() {
app := &cli.App{ app := &cli.App{
Name: "gowebbuild", Name: "gowebbuild",
Usage: "All in one tool to build web frontend projects.", Usage: "All in one tool to build web frontend projects.",
Version: "7.3.0", Version: "7.5.0",
Authors: []*cli.Author{{ Authors: []*cli.Author{{
Name: "trading-peter (https://github.com/trading-peter)", Name: "trading-peter (https://github.com/trading-peter)",
}}, }},
@@ -85,8 +85,11 @@ $ gowebbuild replace *.go foo bar
Flags: []cli.Flag{ Flags: []cli.Flag{
cfgParam, cfgParam,
&cli.UintFlag{ &cli.UintFlag{
Name: "lr-port", Name: "lr-port",
Value: uint(lrserver.DefaultPort), Value: (func() uint {
port := findFreePort(int(lrserver.DefaultPort), int(lrserver.DefaultPort)+100)
return uint(port)
}()),
Usage: "port for the live reload server", Usage: "port for the live reload server",
}, },
}, },
@@ -102,6 +105,11 @@ $ gowebbuild replace *.go foo bar
Value: "./", Value: "./",
Usage: "folder to serve", Usage: "folder to serve",
}, },
&cli.StringFlag{
Name: "src",
Value: "./",
Usage: "folder to watch for changes and trigger live reload",
},
&cli.UintFlag{ &cli.UintFlag{
Name: "port", Name: "port",
Value: uint(8080), Value: uint(8080),
@@ -116,6 +124,7 @@ $ gowebbuild replace *.go foo bar
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
port := ctx.Uint("port") port := ctx.Uint("port")
root := ctx.String("root") root := ctx.String("root")
src := ctx.String("src")
lrPort := ctx.Uint("lr-port") lrPort := ctx.Uint("lr-port")
if lrPort != 0 { if lrPort != 0 {
@@ -124,7 +133,7 @@ $ gowebbuild replace *.go foo bar
w.SetMaxEvents(1) w.SetMaxEvents(1)
w.FilterOps(watcher.Write, watcher.Rename, watcher.Move, watcher.Create, watcher.Remove) w.FilterOps(watcher.Write, watcher.Rename, watcher.Move, watcher.Create, watcher.Remove)
if err := w.AddRecursive(root); err != nil { if err := w.AddRecursive(src); err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
os.Exit(1) os.Exit(1)
} }