Skip to content

Commit

Permalink
Check project directories (#70)
Browse files Browse the repository at this point in the history
* Check project directories

* Remove partials directory

---------

Co-authored-by: maddalax <jm@madev.me>
  • Loading branch information
rafaelDev0ps and maddalax authored Nov 14, 2024
1 parent 971f05c commit a1af01a
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions cli/htmgo/tasks/astgen/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package astgen

import (
"fmt"
"github.com/maddalax/htmgo/cli/htmgo/internal/dirutil"
"github.com/maddalax/htmgo/cli/htmgo/tasks/process"
"github.com/maddalax/htmgo/framework/h"
"go/ast"
"go/parser"
"go/token"
"golang.org/x/mod/modfile"
"io/fs"
"log/slog"
"os"
"path/filepath"
"slices"
"strings"
"unicode"

"github.com/maddalax/htmgo/cli/htmgo/internal/dirutil"
"github.com/maddalax/htmgo/cli/htmgo/tasks/process"
"github.com/maddalax/htmgo/framework/h"
"golang.org/x/mod/modfile"
)

type Page struct {
Expand Down Expand Up @@ -483,9 +484,36 @@ func writeAssetsFile() {

}

func HasModuleFile(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}

func CheckPagesDirectory(path string) error {
pagesPath := filepath.Join(path, "pages")
_, err := os.Stat(pagesPath)
if err != nil {
return fmt.Errorf("The directory pages does not exist.")
}

return nil
}

func GetModuleName() string {
wd := process.GetWorkingDir()
modPath := filepath.Join(wd, "go.mod")

if HasModuleFile(modPath) == false {
fmt.Fprintf(os.Stderr, "Module not found: go.mod file does not exist.")
return ""
}

checkDir := CheckPagesDirectory(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)
Expand Down

0 comments on commit a1af01a

Please sign in to comment.