diff --git a/build.go b/build.go index b44d59c..297e99a 100644 --- a/build.go +++ b/build.go @@ -9,7 +9,12 @@ import ( ) func buildAction(ctx *cli.Context) error { - cfgPath := ctx.String("c") + cfgPath, err := filepath.Abs(ctx.String("c")) + + if err != nil { + return err + } + os.Chdir(filepath.Dir(cfgPath)) opts := readCfg(cfgPath) diff --git a/main.go b/main.go index bf7d3c0..171d9ae 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/evanw/esbuild/pkg/api" + "github.com/jaschaephraim/lrserver" "github.com/otiai10/copy" "github.com/urfave/cli/v2" ) @@ -94,6 +95,11 @@ func main() { Usage: "watch for changes and trigger the build", Flags: []cli.Flag{ cfgParam, + &cli.UintFlag{ + Name: "lr-port", + Value: uint(lrserver.DefaultPort), + Usage: "port for the live reload server", + }, }, Action: watchAction, }, @@ -132,6 +138,7 @@ func main() { }, }, }, + DefaultCommand: "watch", } if err := app.Run(os.Args); err != nil { diff --git a/watch.go b/watch.go index 2e2320a..8a65d90 100644 --- a/watch.go +++ b/watch.go @@ -15,7 +15,12 @@ import ( ) func watchAction(ctx *cli.Context) error { - cfgPath := ctx.String("c") + cfgPath, err := filepath.Abs(ctx.String("c")) + + if err != nil { + return err + } + os.Chdir(filepath.Dir(cfgPath)) optsSetups := readCfg(cfgPath) @@ -100,7 +105,8 @@ func watchAction(ctx *cli.Context) error { go func() { fmt.Println("Starting live reload server") - lr := lrserver.New(lrserver.DefaultName, lrserver.DefaultPort) + port := ctx.Uint("lr-port") + lr := lrserver.New(lrserver.DefaultName, uint16(port)) go func() { for {