diff --git a/cli/htmgo/tasks/astgen/entry.go b/cli/htmgo/tasks/astgen/entry.go index c3dab72..cdd2d82 100644 --- a/cli/htmgo/tasks/astgen/entry.go +++ b/cli/htmgo/tasks/astgen/entry.go @@ -5,7 +5,6 @@ import ( "go/ast" "go/parser" "go/token" - "golang.org/x/mod/modfile" "io/fs" "log/slog" "os" @@ -14,6 +13,8 @@ import ( "strings" "unicode" + "golang.org/x/mod/modfile" + "github.com/maddalax/htmgo/cli/htmgo/internal/dirutil" "github.com/maddalax/htmgo/cli/htmgo/tasks/process" "github.com/maddalax/htmgo/framework/h" @@ -425,6 +426,22 @@ func HasModuleFile(path string) bool { return !os.IsNotExist(err) } +func CheckProjectDirectories(path string) error { + pagesPath := filepath.Join(path, "pages") + _, err := os.Stat(pagesPath) + if err != nil { + return fmt.Errorf("The directory pages does not exist.") + } + + partialsPath := filepath.Join(path, "partials") + _, err = os.Stat(partialsPath) + if err != nil { + return fmt.Errorf("The directory partials does not exist.") + } + + return nil +} + func writeAssetsFile() { cwd := process.GetWorkingDir() config := dirutil.GetConfig() @@ -494,6 +511,12 @@ func GetModuleName() string { return "" } + checkDir := CheckProjectDirectories(wd) + if checkDir != nil { + fmt.Fprintf(os.Stderr, checkDir.Error()) + return "" + } + goModBytes, err := os.ReadFile(modPath) if err != nil { fmt.Fprintf(os.Stderr, "error reading go.mod: %v\n", err)