Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented .env varibale to be load #53

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/generate-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Linting Generated Blueprints

on:
pull_request: {}
workflow_dispatch: {}

jobs:
install_dependencies:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Install Dependencies
run: go mod download

framework_matrix:
needs: install_dependencies
strategy:
matrix:
framework:
[chi, gin, fiber, gorilla/mux, httprouter, standard-library, echo]
goVersion: ["1.20"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.goVersion }}
- name: build templates
run: go run main.go create -n ${{ matrix.framework }} -f ${{ matrix.framework}}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55.2
working-directory: ${{ matrix.framework }}
args: --timeout=5m
30 changes: 26 additions & 4 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
name: Linting

on:
push:
paths:
- '**.go'
- go.sum
- go.mod
branches-ignore:
- main
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
Expand All @@ -14,11 +21,26 @@ jobs:
with:
go-version: '1.21.1'

- name: Deps cache
id: cache-go-deps
uses: actions/cache@v3
env:
cache-name: go-deps-cache
with:
path: ~/godeps
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-

- if: ${{ steps.cache-go-deps.outputs.cache-hit != 'true' }}
name: List the state of node modules
continue-on-error: true
run: go mod graph

- name: Install dependencies
run: |
go mod tidy
go mod download
go mod tidy
go mod download

- name: Run golangci-lint
uses: golangci/[email protected]

29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: goreleaser

on:
push:
tags:
- "v*.*.*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.1'
-
name: Run GoReleaser
uses: goreleaser/[email protected]
with:
distribution: goreleaser
version: ${{ env.GITHUB_REF_NAME }}
args: release --clean
workdir: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 changes: 0 additions & 43 deletions .github/workflows/tag-release.yml

This file was deleted.

25 changes: 25 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
builds:
- binary: go-blueprint
main: ./
goos:
- darwin
- linux
- windows
goarch:
- amd64
- arm64
env:
- CGO_ENABLED=0

release:
prerelease: auto

universal_binaries:
- replace: true

brews:
- name: go-blueprint
homepage: "https://github.com/Melkeydev/homebrew-melkey"

checksum:
name_template: 'checksums.txt'
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ gives the option to integrate with one of the more popular Go frameworks (and th

### Install

- **Brew install :**

```sh
brew install go-blueprint
```

- **Go install :**

```sh
go install github.com/melkeydev/go-blueprint@latest
```

Expand Down
21 changes: 19 additions & 2 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/melkeydev/go-blueprint/cmd/steps"
"github.com/melkeydev/go-blueprint/cmd/ui/multiInput"
"github.com/melkeydev/go-blueprint/cmd/ui/textinput"
"github.com/melkeydev/go-blueprint/cmd/utils"
"github.com/spf13/cobra"
)

Expand All @@ -30,6 +31,7 @@ const logo = `

var (
logoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#01FAC6")).Bold(true)
tipMsgStyle = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.Color("190")).Italic(true)
endingMsgStyle = lipgloss.NewStyle().PaddingLeft(1).Foreground(lipgloss.Color("170")).Bold(true)
allowedProjectTypes = []string{"chi", "gin", "fiber", "gorilla/mux", "httprouter", "standard-library", "echo"}
)
Expand All @@ -54,6 +56,8 @@ var createCmd = &cobra.Command{
ProjectName: &textinput.Output{},
}

isInteractive := !utils.HasChangedFlag(cmd.Flags())

flagName := cmd.Flag("name").Value.String()
flagFramework := cmd.Flag("framework").Value.String()

Expand All @@ -75,14 +79,17 @@ var createCmd = &cobra.Command{

if project.ProjectName == "" {
tprogram := tea.NewProgram(textinput.InitialTextInputModel(options.ProjectName, "What is the name of your project?", project))

if _, err := tprogram.Run(); err != nil {
log.Printf("Name of project contains an error: %v", err)
cobra.CheckErr(err)
}
project.ExitCLI(tprogram)

project.ProjectName = options.ProjectName.Output
err := cmd.Flag("name").Value.Set(project.ProjectName)
if err != nil {
log.Fatal("failed to set the name flag value", err)
}
}

if project.ProjectType == "" {
Expand All @@ -98,6 +105,10 @@ var createCmd = &cobra.Command{
}

project.ProjectType = strings.ToLower(options.ProjectType)
err := cmd.Flag("framework").Value.Set(project.ProjectType)
if err != nil {
log.Fatal("failed to set the framework flag value", err)
}
}

currentWorkingDir, err := os.Getwd()
Expand All @@ -117,10 +128,16 @@ var createCmd = &cobra.Command{

fmt.Println(endingMsgStyle.Render("\nNext steps cd into the newly created project with:"))
fmt.Println(endingMsgStyle.Render(fmt.Sprintf("• cd %s\n", project.ProjectName)))

if isInteractive {
nonInteractiveCommand := utils.NonInteractiveCommand(cmd.Flags())
fmt.Println(tipMsgStyle.Render("Tip: Repeat the equivalent Blueprint with the following non-interactive command:"))
fmt.Println(tipMsgStyle.Italic(false).Render(fmt.Sprintf("• %s\n", nonInteractiveCommand)))
}
},
}

// isValidProjectType checks if the inputted project type matches
// isValidProjectType checks if the inputted project type matches
// the currently supported list of project types
func isValidProjectType(input string, allowedTypes []string) bool {
for _, t := range allowedTypes {
Expand Down
45 changes: 45 additions & 0 deletions cmd/program/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ func (p *Project) CreateMainFile() error {
return err
}

// Initialize git repo
err = utils.ExecuteCmd("git", []string{"init"}, projectPath)
if err != nil {
log.Printf("Error initializing git repo: %v", err)
cobra.CheckErr(err)
return err
}
// Create gitignore
gitignoreFile, err := os.Create(fmt.Sprintf("%s/.gitignore", projectPath))
if err != nil {
cobra.CheckErr(err)
return err
}
defer gitignoreFile.Close()

// inject gitignore template
gitignoreTemplate := template.Must(template.New(".gitignore").Parse(string(tpl.GitIgnoreTemplate())))
err = gitignoreTemplate.Execute(gitignoreFile, p)
if err != nil {
return err
}

// Create .air.toml file
airTomlFile, err := os.Create(fmt.Sprintf("%s/.air.toml", projectPath))
if err != nil {
Expand All @@ -227,10 +249,33 @@ func (p *Project) CreateMainFile() error {
return err
}

// Create .env.example file
envFile, err := os.Create(fmt.Sprintf("%s/.env", projectPath))
if err != nil {
cobra.CheckErr(err)
return err
}

defer envFile.Close()

// Inject .env template
envFileTemplate := template.Must(template.New("envfile").Parse(string(tpl.EnvFileTemplate())))
err = envFileTemplate.Execute(envFile, p)
if err != nil {
return err
}

err = utils.GoFmt(projectPath)
if err != nil {
log.Printf("Could not gofmt in new project %v\n", err)
cobra.CheckErr(err)
return err
}

err = utils.GoModTidy(projectPath)
if err != nil {
log.Printf("Could not tidy go.mod in new project %v\n", err)
cobra.CheckErr(err)
}

return nil
Expand Down
Loading
Loading