Pre- and post-build actions
Anirudh Oppiliappan x@icyphox.sh
Fri, 30 Oct 2020 17:50:05 +0530
2 files changed,
20 insertions(+),
3 deletions(-)
M
build.go
→
build.go
@@ -4,11 +4,24 @@ import (
"github.com/cross-cpm/go-shutil" "io/ioutil" "os" + "os/exec" "path/filepath" "strings" "text/template" ) +var cfg = parseConfig() + +func execute(cmds []string) { + for _, cmd := range cmds { + _, err := exec.Command(cmd).Output() + printMsg("executing:", cmd) + if err != nil { + printErr(err) + } + } +} + func processTemplate(tmplPath string) *template.Template { tmplFile := filepath.Join("templates", tmplPath) tmpl, err := template.ParseFiles(tmplFile)@@ -42,13 +55,12 @@ }
os.MkdirAll(buildPath, 0755) - cfg := parseConfig() fm.Body = string(bodyHtml) // combine config and matter structs combined := struct { Cfg Config - Fm Matter + Fm Matter }{cfg, fm} htmlFile, err := os.Create(filepath.Join(buildPath, "index.html"))@@ -69,6 +81,8 @@ htmlFile.Close()
} func viteBuild() { + printMsg("executing pre-build actions") + execute(cfg.Prebuild) err := filepath.Walk("./pages", func(path string, info os.FileInfo, err error) error { if err != nil { printErr(err)@@ -103,4 +117,7 @@ _, err = shutil.CopyTree("static", filepath.Join("build", "static"), nil)
if err != nil { printErr(err) } + printMsg("build complete") + printMsg("executing post-build actions...") + execute(cfg.Postbuild) }
M
markdown.go
→
markdown.go
@@ -24,6 +24,6 @@ }),
), ), ), - bf.WithExtensions(bfExts), + bf.WithExtensions(bfExts), ) }