gowebbuild/build.go

57 lines
1.2 KiB
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/evanw/esbuild/pkg/api"
"github.com/trading-peter/gowebbuild/fsutils"
"github.com/urfave/cli/v2"
)
func buildAction(ctx *cli.Context) error {
cfgPath := fsutils.ResolvePath(ctx.String("c"))
2022-11-29 10:23:42 +01:00
os.Chdir(filepath.Dir(cfgPath))
opts := readCfg(cfgPath)
for _, o := range opts {
2023-09-13 11:45:24 +02:00
if ctx.Bool("p") {
download(o)
}
2022-11-29 12:33:02 +01:00
purge(o)
cp(o)
2024-08-26 23:12:33 +02:00
esBuildCfg := cfgToESBuildCfg(o)
if ctx.Bool("p") {
2024-08-26 23:12:33 +02:00
esBuildCfg.MinifyIdentifiers = true
esBuildCfg.MinifySyntax = true
esBuildCfg.MinifyWhitespace = true
esBuildCfg.Sourcemap = api.SourceMapNone
}
2024-08-26 23:12:33 +02:00
api.Build(esBuildCfg)
replace(o)
if ctx.Bool("p") && o.ProductionBuildOptions.CmdPostBuild != "" {
2024-11-06 10:43:05 +01:00
defer func() {
fmt.Printf("Executing post production build command `%s`\n", o.ProductionBuildOptions.CmdPostBuild)
cmd := exec.Command("sh", "-c", o.ProductionBuildOptions.CmdPostBuild)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
fmt.Printf("Failed to execute post production build command `%s`: %+v\n", o.ProductionBuildOptions.CmdPostBuild, err)
os.Exit(1)
}
}()
}
}
return nil
}