├── .github └── workflows │ └── go.yml ├── .gitignore ├── README.md ├── build-platforms.sh ├── go.mod ├── imgs ├── cover-4k.png ├── cover-hd.png └── cover.png ├── install.sh ├── main.go └── utils └── print.go /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: Go 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | jobs: 13 | 14 | build: 15 | runs-on: ubuntu-latest 16 | steps: 17 | - uses: actions/checkout@v3 18 | 19 | - name: Set up Go 20 | uses: actions/setup-go@v3 21 | with: 22 | go-version: 1.19 23 | 24 | - name: Build 25 | run: go build -v ./... 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # build file 2 | git-boilerplate 3 | build -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Git-Boilerplate](/imgs/cover-hd.png) 2 | 3 | # Git Boilerplate CLI Tool 4 | 5 | The Git Boilerplate CLI Tool is a command-line interface for creating new projects from a GitHub repository template. This tool provides a simple way to automate the process of setting up new projects by cloning a repository template and customizing it with your own content. 6 | 7 | ## Installation 8 | 9 | 24 | 25 | ### Using curl 26 | 27 | You can also install Git Boilerplate using the following command: 28 | 29 | ```bash 30 | curl -sSf https://raw.githubusercontent.com/gui-marc/git-boilerplate/main/install.sh | sh 31 | ``` 32 | 33 | This command will download the latest release of Git Boilerplate and install it in `~/.git-boilerplate`. 34 | 35 | ### Adding to path 36 | 37 | If you installed Git Boilerplate using the `curl` command above, you will need to add the `~/.git-boilerplate` directory to your `$PATH` environment variable. To do this, add the following line to your `.bashrc` or `.zshrc` file: 38 | 39 | ```bash 40 | export PATH=$PATH:$HOME/.git-boilerplate 41 | ``` 42 | 43 | If you use the fish shell, just run the following command: 44 | 45 | ```bash 46 | set -gx PATH "$HOME/.git-boilerplate" $PATH; 47 | ``` 48 | 49 | ## Usage 50 | 51 | To use Git Boilerplate, simply run the following command: 52 | 53 | ```bash 54 | git-boilerplate 55 | ``` 56 | 57 | Replace `` with the URL of the GitHub repository template you want to use, and `` with the name of the project you want to create. 58 | 59 | The Git Boilerplate CLI Tool will clone the template repository into a temporary directory, create a new project directory with the specified name, copy the contents of the template repository into the project directory, remove the `.git` directory from the project directory, initialize a new Git repository in the project directory, and finally remove the temporary directory. 60 | 61 | ## Contributing 62 | 63 | If you find a bug or have an idea for a new feature, please open an issue or submit a pull request on GitHub. All contributions are welcome! 64 | 65 | ## License 66 | 67 | This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. 68 | -------------------------------------------------------------------------------- /build-platforms.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | package="git-boilerplate" 4 | if [[ -z "$package" ]]; then 5 | echo "usage: $0 " 6 | exit 1 7 | fi 8 | package_split=(${package//\// }) 9 | package_name=${package_split[-1]} 10 | 11 | platforms=("windows/amd64" "darwin/amd64" "linux/amd64") 12 | 13 | for platform in "${platforms[@]}" 14 | do 15 | platform_split=(${platform//\// }) 16 | GOOS=${platform_split[0]} 17 | GOARCH=${platform_split[1]} 18 | output_name=$package_name'-'$GOOS'-'$GOARCH 19 | if [ $GOOS = "windows" ]; then 20 | output_name+='.exe' 21 | fi 22 | 23 | env GOOS=$GOOS GOARCH=$GOARCH go build -o build/$output_name 24 | if [ $? -ne 0 ]; then 25 | echo 'An error has occurred! Aborting the script execution...' 26 | exit 1 27 | fi 28 | done -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/gui-marc/git-boilerplate 2 | 3 | go 1.20 4 | -------------------------------------------------------------------------------- /imgs/cover-4k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gui-marc/git-boilerplate/43b4d4d2e44342da9a3d6fc04bbc67b169f66245/imgs/cover-4k.png -------------------------------------------------------------------------------- /imgs/cover-hd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gui-marc/git-boilerplate/43b4d4d2e44342da9a3d6fc04bbc67b169f66245/imgs/cover-hd.png -------------------------------------------------------------------------------- /imgs/cover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gui-marc/git-boilerplate/43b4d4d2e44342da9a3d6fc04bbc67b169f66245/imgs/cover.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | set -eu 4 | printf '\n' 5 | 6 | # Determine the latest release version 7 | VERSION=$(curl -s https://api.github.com/repos/gui-marc/git-boilerplate/releases/latest | grep "tag_name" | awk '{print substr($2, 2, length($2)-3)}') 8 | 9 | # Determine the operating system and architecture 10 | OS=$(uname -s | tr '[:upper:]' '[:lower:]') 11 | ARCH=$(uname -m) 12 | 13 | if [ "${OS}" == "darwin" ]; then 14 | OS="macos" 15 | elif [ "${OS}" == "linux" ]; then 16 | if [ "${ARCH}" == "x86_64" ]; then 17 | ARCH="amd64" 18 | elif [ "${ARCH}" == "aarch64" ]; then 19 | ARCH="arm64" 20 | fi 21 | fi 22 | 23 | echo https://github.com/gui-marc/git-boilerplate/releases/download/${VERSION}/git-boilerplate-${OS}-${ARCH} 24 | 25 | rm -rf ~/.git-boilerplate 26 | mkdir ~/.git-boilerplate 27 | 28 | # Download and install the binary file 29 | curl -L -o ~/.git-boilerplate/git-boilerplate https://github.com/gui-marc/git-boilerplate/releases/download/${VERSION}/git-boilerplate-${OS}-${ARCH} 30 | 31 | chmod +x ~/.git-boilerplate/git-boilerplate 32 | 33 | echo "git-boilerplate has been installed to ~/.git-boilerplate" 34 | 35 | # Write the path to the .bashrc file 36 | echo "PATH=$PATH:$HOME/.git-boilerplate" >> ~/.bashrc -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "os/exec" 8 | "strings" 9 | 10 | "github.com/gui-marc/git-boilerplate/utils" 11 | ) 12 | 13 | func main() { 14 | utils.Clear() 15 | 16 | if len(os.Args) < 3 { 17 | utils.Error("Invalid arguments") 18 | utils.Info("Usage: git-boilerplate ") 19 | return 20 | } 21 | 22 | templateURL := os.Args[1] 23 | projectName := os.Args[2] 24 | 25 | utils.Loading("Cloning template repository...") 26 | output, err := exec.Command("git", "clone", "--depth=1", "--branch=main", templateURL, ".git-boilerplate-temp").CombinedOutput() 27 | 28 | if err != nil { 29 | utils.Error("Error cloning template repository") 30 | fmt.Printf("%v\n%s\n", err, string(output)) 31 | return 32 | } 33 | 34 | utils.Success("Template repository cloned successfully") 35 | utils.Loading("Removing .git directory...") 36 | 37 | err = os.RemoveAll(".git-boilerplate-temp/.git") 38 | 39 | if err != nil { 40 | utils.Error("Error removing .git directory") 41 | return 42 | } 43 | 44 | utils.Success(".git directory removed successfully") 45 | 46 | utils.Loading("Copying to new folder...") 47 | 48 | err = copyDir(".git-boilerplate-temp", projectName, projectName) 49 | 50 | if err != nil { 51 | utils.Error("Error copying files") 52 | return 53 | } 54 | 55 | utils.Success("Files copied successfully") 56 | 57 | utils.Loading("Removing temporary directory...") 58 | 59 | err = os.RemoveAll(".git-boilerplate-temp") 60 | 61 | if err != nil { 62 | utils.Error("Error removing temporary directory") 63 | return 64 | } 65 | 66 | utils.Success("Temporary directory removed successfully") 67 | 68 | utils.Loading("Initializing git repository...") 69 | 70 | output, err = exec.Command("git", "init", projectName).CombinedOutput() 71 | 72 | if err != nil { 73 | utils.Error("Error initializing git repository") 74 | fmt.Printf("%v\n%s\n", err, string(output)) 75 | return 76 | } 77 | 78 | utils.Success("Git repository initialized successfully") 79 | 80 | utils.Clear() 81 | 82 | utils.Success("Project created successfully 🎉\n") 83 | utils.Info("To start working on your project, run the following command:") 84 | utils.Info(fmt.Sprintf("cd %s", projectName)) 85 | } 86 | 87 | func copyDir(src string, dest string, projectName string) error { 88 | // Read source directory 89 | files, err := ioutil.ReadDir(fmt.Sprintf("./%s", src)) 90 | if err != nil { 91 | return err 92 | } 93 | 94 | // Create destination directory 95 | err = os.Mkdir(dest, os.ModePerm) 96 | if err != nil { 97 | return err 98 | } 99 | 100 | // Copy files 101 | for _, file := range files { 102 | srcFile := src + "/" + file.Name() 103 | destFile := dest + "/" + file.Name() 104 | 105 | if file.IsDir() { 106 | err = copyDir(srcFile, destFile, projectName) 107 | if err != nil { 108 | return err 109 | } 110 | } else { 111 | content, err := ioutil.ReadFile(srcFile) 112 | if err != nil { 113 | return err 114 | } 115 | 116 | // Replace template variables with project-specific values 117 | contentStr := strings.Replace(string(content), "{{project-name}}", projectName, -1) 118 | 119 | err = ioutil.WriteFile(destFile, []byte(contentStr), file.Mode()) 120 | if err != nil { 121 | return err 122 | } 123 | } 124 | } 125 | 126 | return nil 127 | } 128 | -------------------------------------------------------------------------------- /utils/print.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "fmt" 4 | 5 | const ( 6 | Black = 30 7 | Red = 31 8 | Green = 32 9 | Yellow = 33 10 | Blue = 34 11 | Magenta = 35 12 | Cyan = 36 13 | White = 37 14 | ) 15 | 16 | const ( 17 | Bold = 1 18 | Underline = 4 19 | Blinking = 5 20 | Reverse = 7 21 | ) 22 | 23 | func Print(text string, color int) { 24 | fmt.Printf("\033[%dm%s\033[0m\n", color, text) 25 | } 26 | 27 | func PrintStyled(text string, color int, style int) { 28 | fmt.Printf("\033[%d;%dm%s\033[0m\n", style, color, text) 29 | } 30 | 31 | func Error(text string) { 32 | PrintStyled(text, Red, Bold) 33 | } 34 | 35 | func Success(text string) { 36 | PrintStyled(text, Green, Bold) 37 | } 38 | 39 | func Info(text string) { 40 | Print(text, Blue) 41 | } 42 | 43 | func Loading(text string) { 44 | PrintStyled(text, Yellow, Blinking) 45 | } 46 | 47 | func Clear() { 48 | fmt.Print("\033[H\033[2J") 49 | } 50 | --------------------------------------------------------------------------------