install.go
This commit is contained in:
parent
db69f3b519
commit
5d3e8fd7d4
13 changed files with 82 additions and 27 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -0,0 +1 @@
|
|||
_bootstrap
|
1
bootstrap/.gitignore
vendored
1
bootstrap/.gitignore
vendored
|
@ -1,4 +1,3 @@
|
|||
.env
|
||||
bin
|
||||
*_templ.go
|
||||
*_templ.txt
|
||||
|
|
|
@ -3,7 +3,7 @@ package handlers
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
"example-app/app/types"
|
||||
"AABBCCDD/app/types"
|
||||
|
||||
"github.com/anthdm/gothkit/pkg/kit"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package errors
|
||||
|
||||
import (
|
||||
"example-app/app/views/layouts"
|
||||
"AABBCCDD/app/views/layouts"
|
||||
)
|
||||
|
||||
templ Error404() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package errors
|
||||
|
||||
import "example-app/app/views/layouts"
|
||||
import "AABBCCDD/app/views/layouts"
|
||||
|
||||
templ Error500() {
|
||||
@layouts.BaseLayout() {
|
||||
|
|
|
@ -2,7 +2,7 @@ package landing
|
|||
|
||||
import (
|
||||
"github.com/anthdm/gothkit/pkg/view"
|
||||
"example-app/app/views/layouts"
|
||||
"AABBCCDD/app/views/layouts"
|
||||
)
|
||||
|
||||
templ Index() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package layouts
|
||||
|
||||
import "example-app/app/views/components"
|
||||
import "AABBCCDD/app/views/components"
|
||||
|
||||
templ App() {
|
||||
@BaseLayout() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"example-app/app"
|
||||
"AABBCCDD/app"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
|
@ -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
|
||||
|
|
69
install.go
Normal file
69
install.go
Normal file
|
@ -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)
|
||||
}
|
14
install.sh
14
install.sh
|
@ -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"
|
||||
|
Loading…
Reference in a new issue