From 1924270e4e6c55e8c512f997d8d8c6fda4434217 Mon Sep 17 00:00:00 2001 From: maddalax Date: Fri, 25 Oct 2024 07:48:41 -0500 Subject: [PATCH] update more deps --- tools/html-to-htmgo/internal/domain/node.go | 3 -- tools/update-htmgo-dep.go | 42 ++++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/tools/html-to-htmgo/internal/domain/node.go b/tools/html-to-htmgo/internal/domain/node.go index a90e52e..1c1c079 100644 --- a/tools/html-to-htmgo/internal/domain/node.go +++ b/tools/html-to-htmgo/internal/domain/node.go @@ -30,9 +30,6 @@ func (n *CustomNode) SetType(in string) { n.Type = "h.TBody" case "id": n.Type = "h.Id" - case "path": - n.Type = "path" - n.customType = true case "circle": n.Type = "circle" n.customType = true diff --git a/tools/update-htmgo-dep.go b/tools/update-htmgo-dep.go index bd96b80..2737f0d 100644 --- a/tools/update-htmgo-dep.go +++ b/tools/update-htmgo-dep.go @@ -13,6 +13,13 @@ import ( ) const frameworkRepo = "github.com/maddalax/htmgo/framework" +const htmlToHtmgoRepo = "github.com/maddalax/htmgo/tools/html-to-htmgo" + +var depsToUpdate = []string{ + frameworkRepo, + htmlToHtmgoRepo, +} + const githubAPIURL = "https://api.github.com/repos/maddalax/htmgo/commits" // Commit represents the structure of a commit object returned by the GitHub API. @@ -52,17 +59,14 @@ func main() { // Check if the directory contains a go.mod file. if info.IsDir() && fileExists(filepath.Join(path, "go.mod")) { - // Check if the go.mod contains 'github.com/maddalax/htmgo/framework'. - if containsFrameworkDependency(filepath.Join(path, "go.mod")) { - wg.Add(1) - go func() { - defer wg.Done() - // Run go get github.com/maddalax/htmgo/framework@. - fmt.Printf("Running 'go get' with latest commit hash in %s\n", path) - RunCommand(path, "go", "get", fmt.Sprintf("%s@%s", frameworkRepo, latestCommitHash)) - RunCommand(path, "go", "mod", "tidy") - }() - } + goModPath := filepath.Join(path, "go.mod") + wg.Add(1) + go func() { + defer wg.Done() + for _, s := range depsToUpdate { + updateDepToLatestVersion(s, goModPath, latestCommitHash) + } + }() } return nil @@ -82,8 +86,18 @@ func fileExists(path string) bool { return !os.IsNotExist(err) } -// containsFrameworkDependency checks if 'github.com/maddalax/htmgo/framework' is in the go.mod file. -func containsFrameworkDependency(goModPath string) bool { +func updateDepToLatestVersion(dep string, goModPath string, latestCommitHash string) { + if containsDep(dep, goModPath) { + dir := filepath.Dir(goModPath) + // Run go get github.com/maddalax/htmgo/framework@. + fmt.Printf("Running 'go get' with latest commit hash in %s\n", dep) + RunCommand(dir, "go", "get", fmt.Sprintf("%s@%s", dep, latestCommitHash)) + RunCommand(dir, "go", "mod", "tidy") + } +} + +// containsDep checks if 'github.com/maddalax/htmgo/framework' is in the go.mod file. +func containsDep(dep string, goModPath string) bool { file, err := os.Open(goModPath) if err != nil { fmt.Println("Error opening go.mod file:", err) @@ -93,7 +107,7 @@ func containsFrameworkDependency(goModPath string) bool { scanner := bufio.NewScanner(file) for scanner.Scan() { - if strings.Contains(scanner.Text(), frameworkRepo) { + if strings.Contains(scanner.Text(), dep) { return true } }