about summary refs log tree commit diff stats
path: root/cmd/build
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/build')
-rw-r--r--cmd/build/build.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/cmd/build/build.go b/cmd/build/build.go
index 058b82f..ea611aa 100644
--- a/cmd/build/build.go
+++ b/cmd/build/build.go
@@ -25,6 +25,7 @@ import (
 	"github.com/adrg/frontmatter"
 	"github.com/antchfx/xmlquery"
 	"github.com/antchfx/xpath"
+	"github.com/ardanlabs/conf/v3"
 	mapset "github.com/deckarep/golang-set/v2"
 	cp "github.com/otiai10/copy"
 	"github.com/pkg/errors"
@@ -519,29 +520,39 @@ func build(outDir string) error {
 	return nil
 }
 
+type IOConfig struct {
+	Source      string `conf:"default:.,short:s"`
+	Destination string `conf:"default:public,short:d"`
+}
+
 func main() {
 	if os.Getenv("DEBUG") != "" {
 		slog.SetLogLoggerLevel(slog.LevelDebug)
 	}
 	slog.Debug("starting build process")
-	_, err := os.Getwd()
-	if err != nil {
-		log.Panic(errors.Errorf("working directory does not exist: %v", err))
-	}
 
-	outDir := "public"
-	err = os.RemoveAll("public")
+	ioConfig := IOConfig{}
+	conf.Parse("", &ioConfig)
+
+	if ioConfig.Source != "." {
+		err := os.Chdir(ioConfig.Source)
+		if err != nil {
+			log.Panic("could not change to source directory")
+		}
+	}
+	err := os.RemoveAll(ioConfig.Destination)
 	if err != nil {
 		log.Panic(errors.Errorf("could not remove public directory: %v", err))
 	}
-	err = cp.Copy("static", outDir, cp.Options{
-		PreserveTimes: true,
+	err = cp.Copy(path.Join(ioConfig.Source, "static"), ioConfig.Destination, cp.Options{
+		PreserveTimes:     true,
+		PermissionControl: cp.AddPermission(0755),
 	})
 	if err != nil {
 		log.Panic(errors.Errorf("could not copy static files: %v", err))
 	}
 
-	if err := build(outDir); err != nil {
+	if err := build(ioConfig.Destination); err != nil {
 		switch cause := errors.Cause(err).(type) {
 		case *fs.PathError:
 			slog.Info("pathError")