From 5d3e8fd7d4aff5fcb9ec646f96adfef40ec6145a Mon Sep 17 00:00:00 2001 From: anthdm Date: Thu, 6 Jun 2024 11:44:55 +0200 Subject: [PATCH] install.go --- .gitignore | 1 + bootstrap/.gitignore | 1 - bootstrap/app/handlers/auth.go | 2 +- bootstrap/app/handlers/landing.go | 4 +- bootstrap/app/routes.go | 4 +- bootstrap/app/views/errors/404.templ | 2 +- bootstrap/app/views/errors/500.templ | 2 +- bootstrap/app/views/landing/index.templ | 2 +- bootstrap/app/views/layouts/app_layout.templ | 2 +- bootstrap/cmd/app/main.go | 2 +- bootstrap/go.mod | 4 +- install.go | 69 ++++++++++++++++++++ install.sh | 14 ---- 13 files changed, 82 insertions(+), 27 deletions(-) create mode 100644 install.go delete mode 100755 install.sh diff --git a/.gitignore b/.gitignore index e69de29..d5c6403 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +_bootstrap \ No newline at end of file diff --git a/bootstrap/.gitignore b/bootstrap/.gitignore index 09a94ca..6715962 100644 --- a/bootstrap/.gitignore +++ b/bootstrap/.gitignore @@ -1,4 +1,3 @@ -.env bin *_templ.go *_templ.txt diff --git a/bootstrap/app/handlers/auth.go b/bootstrap/app/handlers/auth.go index 86fde2a..f54f5d4 100644 --- a/bootstrap/app/handlers/auth.go +++ b/bootstrap/app/handlers/auth.go @@ -3,7 +3,7 @@ package handlers import ( "net/http" - "example-app/app/types" + "AABBCCDD/app/types" "github.com/anthdm/gothkit/pkg/kit" ) diff --git a/bootstrap/app/handlers/landing.go b/bootstrap/app/handlers/landing.go index 06724a5..eff84b1 100644 --- a/bootstrap/app/handlers/landing.go +++ b/bootstrap/app/handlers/landing.go @@ -1,8 +1,8 @@ package handlers import ( - "example-app/app/db" - "example-app/app/views/landing" + "AABBCCDD/app/db" + "AABBCCDD/app/views/landing" "github.com/anthdm/gothkit/pkg/kit" ) diff --git a/bootstrap/app/routes.go b/bootstrap/app/routes.go index 1712836..1f83161 100644 --- a/bootstrap/app/routes.go +++ b/bootstrap/app/routes.go @@ -1,8 +1,8 @@ package app import ( - "example-app/app/handlers" - "example-app/app/views/errors" + "AABBCCDD/app/handlers" + "AABBCCDD/app/views/errors" "log/slog" "github.com/anthdm/gothkit/pkg/kit" diff --git a/bootstrap/app/views/errors/404.templ b/bootstrap/app/views/errors/404.templ index d5eaae5..8b28f36 100644 --- a/bootstrap/app/views/errors/404.templ +++ b/bootstrap/app/views/errors/404.templ @@ -1,7 +1,7 @@ package errors import ( - "example-app/app/views/layouts" + "AABBCCDD/app/views/layouts" ) templ Error404() { diff --git a/bootstrap/app/views/errors/500.templ b/bootstrap/app/views/errors/500.templ index 61a6b97..e634d91 100644 --- a/bootstrap/app/views/errors/500.templ +++ b/bootstrap/app/views/errors/500.templ @@ -1,6 +1,6 @@ package errors -import "example-app/app/views/layouts" +import "AABBCCDD/app/views/layouts" templ Error500() { @layouts.BaseLayout() { diff --git a/bootstrap/app/views/landing/index.templ b/bootstrap/app/views/landing/index.templ index cca2a97..94746be 100644 --- a/bootstrap/app/views/landing/index.templ +++ b/bootstrap/app/views/landing/index.templ @@ -2,7 +2,7 @@ package landing import ( "github.com/anthdm/gothkit/pkg/view" - "example-app/app/views/layouts" + "AABBCCDD/app/views/layouts" ) templ Index() { diff --git a/bootstrap/app/views/layouts/app_layout.templ b/bootstrap/app/views/layouts/app_layout.templ index 6cb2d15..76180b3 100644 --- a/bootstrap/app/views/layouts/app_layout.templ +++ b/bootstrap/app/views/layouts/app_layout.templ @@ -1,6 +1,6 @@ package layouts -import "example-app/app/views/components" +import "AABBCCDD/app/views/components" templ App() { @BaseLayout() { diff --git a/bootstrap/cmd/app/main.go b/bootstrap/cmd/app/main.go index 6607af8..d03592d 100644 --- a/bootstrap/cmd/app/main.go +++ b/bootstrap/cmd/app/main.go @@ -1,7 +1,7 @@ package main import ( - "example-app/app" + "AABBCCDD/app" "fmt" "net/http" "os" diff --git a/bootstrap/go.mod b/bootstrap/go.mod index 64de1ff..2a1df69 100644 --- a/bootstrap/go.mod +++ b/bootstrap/go.mod @@ -1,4 +1,4 @@ -module example-app +module AABBCCDD go 1.22.0 @@ -26,4 +26,4 @@ require ( github.com/uptrace/bun/extra/bundebug v1.2.1 ) -replace github.com/anthdm/gothkit => ../gothkit +// replace github.com/anthdm/gothkit => ../gothkit diff --git a/install.go b/install.go new file mode 100644 index 0000000..0ff7060 --- /dev/null +++ b/install.go @@ -0,0 +1,69 @@ +package main + +import ( + "fmt" + "io/fs" + "log" + "os" + "path" + "path/filepath" + "strings" +) + +const ( + replaceID = "AABBCCDD" + bootstrapFolderName = "bootstrap" +) + +func main() { + args := os.Args[1:] + + if len(args) == 0 { + fmt.Println() + fmt.Println("install requires your project name as the first argument") + fmt.Println() + fmt.Println("\tgo run gothkit/install.go [your_project_name]") + fmt.Println() + os.Exit(1) + } + + projectName := args[0] + + if err := os.Rename(path.Join("gothkit", bootstrapFolderName), projectName); err != nil { + log.Fatal(err) + } + + err := filepath.Walk(path.Join(projectName), func(fullPath string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + return nil + } + + b, err := os.ReadFile(fullPath) + if err != nil { + return err + } + + contentStr := string(b) + if strings.Contains(contentStr, replaceID) { + replacedContent := strings.ReplaceAll(contentStr, replaceID, projectName) + file, err := os.OpenFile(fullPath, os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + return err + } + defer file.Close() + _, err = file.WriteString(replacedContent) + if err != nil { + return err + } + } + return nil + }) + if err != nil { + log.Fatal(err) + } + + fmt.Printf("project (%s) successfully installed!\n", projectName) +} diff --git a/install.sh b/install.sh deleted file mode 100755 index 25acc30..0000000 --- a/install.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -echo "enter the name of you project: " -read varname - -git clone git@github.com:anthdm/gothkit.git _gothkit -cd _gothkit -mv bootstrap ../$varname -cd .. -rm -rf _gothkit -echo "" -echo "project installed successfully" -echo "your project folder is available => cd $varname" -