gowebbuild/build.go

58 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"github.com/evanw/esbuild/pkg/api"
"github.com/urfave/cli/v2"
)
func buildAction(ctx *cli.Context) error {
2022-11-29 10:23:42 +01:00
cfgPath, err := filepath.Abs(ctx.String("c"))
if err != nil {
return err
}
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 != "" {
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
}