From e97cacc0e7c16078b75485e97fa76f43bb328b4c Mon Sep 17 00:00:00 2001 From: maddalax Date: Fri, 13 Sep 2024 15:42:42 -0500 Subject: [PATCH] tool to dl template --- cli/go.mod | 3 -- cli/mhtml/main.go | 5 -- framework/tooling/astgen/entry.go | 2 - framework/tooling/downloadtemplate/main.go | 59 ++++++++++++++++++++++ framework/tooling/mhtml/Taskfile.yml | 6 +++ framework/tooling/mhtml/runner.go | 9 ++++ 6 files changed, 74 insertions(+), 10 deletions(-) delete mode 100644 cli/go.mod delete mode 100644 cli/mhtml/main.go create mode 100644 framework/tooling/downloadtemplate/main.go diff --git a/cli/go.mod b/cli/go.mod deleted file mode 100644 index 9dbc195..0000000 --- a/cli/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module github.com/maddalax/mhtml/cli - -go 1.23.0 diff --git a/cli/mhtml/main.go b/cli/mhtml/main.go deleted file mode 100644 index 342ce56..0000000 --- a/cli/mhtml/main.go +++ /dev/null @@ -1,5 +0,0 @@ -package main - -func main() { - println("Hesssllo, ssHTML!") -} diff --git a/framework/tooling/astgen/entry.go b/framework/tooling/astgen/entry.go index dcab397..5924572 100644 --- a/framework/tooling/astgen/entry.go +++ b/framework/tooling/astgen/entry.go @@ -254,7 +254,6 @@ func writePartialsFile() { if partial.Import == "partials/load" { continue } - fmt.Println(partial.Import) builder.AddImport(fmt.Sprintf(`%s/%s`, moduleName, partial.Import)) } @@ -344,7 +343,6 @@ func GetModuleName() string { } func main() { - fmt.Println("Generating partials...") writePartialsFile() writePagesFile() } diff --git a/framework/tooling/downloadtemplate/main.go b/framework/tooling/downloadtemplate/main.go new file mode 100644 index 0000000..b1f610e --- /dev/null +++ b/framework/tooling/downloadtemplate/main.go @@ -0,0 +1,59 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "path/filepath" +) + +func deleteAllExceptTemplate(outPath string, excludeDir string) { + // List all files and directories in the root folder + files, err := os.ReadDir(outPath) + if err != nil { + fmt.Printf("Error reading directory: %v\n", err) + return + } + + // Iterate through each item in the root folder + for _, file := range files { + // Skip the excluded directory + if file.Name() == excludeDir { + fmt.Printf("Skipping directory: %s\n", file.Name()) + continue + } + + // Get full path + fullPath := filepath.Join(outPath, file.Name()) + + // Remove the file or directory + fmt.Printf("Removing: %s\n", fullPath) + err := os.RemoveAll(fullPath) + if err != nil { + fmt.Printf("Error removing %s: %v\n", fullPath, err) + } else { + fmt.Printf("Successfully removed %s\n", fullPath) + } + } +} + +func main() { + outPath := "new-app" + excludeDir := "starter-template" + + install := exec.Command("git", "clone", "https://github.com/maddalax/mhtml", "--depth=1", outPath) + install.Stdout = os.Stdout + install.Stderr = os.Stderr + err := install.Run() + + if err != nil { + println("Error downloading template %v\n", err) + return + } + + deleteAllExceptTemplate(outPath, excludeDir) + + //exec.Command("mv", "starter-template/*", "./ 2>/dev/null && rmdir starter-template") + + println("Template downloaded successfully!") +} diff --git a/framework/tooling/mhtml/Taskfile.yml b/framework/tooling/mhtml/Taskfile.yml index 10c1be3..91212d7 100644 --- a/framework/tooling/mhtml/Taskfile.yml +++ b/framework/tooling/mhtml/Taskfile.yml @@ -4,6 +4,12 @@ interval: 500ms tasks: + template: + dir: '{{.USER_WORKING_DIR}}' + desc: Generate template from source code + cmds: + - go run github.com/maddalax/mhtml/framework/tooling/downloadtemplate + setup: deps: [copy-framework-assets, ast] dir: '{{.USER_WORKING_DIR}}' diff --git a/framework/tooling/mhtml/runner.go b/framework/tooling/mhtml/runner.go index c009446..5372cce 100644 --- a/framework/tooling/mhtml/runner.go +++ b/framework/tooling/mhtml/runner.go @@ -17,6 +17,15 @@ func main() { // Parse the command-line flags flag.Parse() + install := exec.Command("go", "install", "github.com/go-task/task/v3/cmd/task@latest") + install.Stdout = os.Stdout + install.Stderr = os.Stderr + err := install.Run() + if err != nil { + fmt.Printf("Error installing task: %v\n", err) + return + } + temp, err := os.CreateTemp("", "Taskfile.yml") if err != nil {