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

feat: Update spinner action #3

Merged
merged 9 commits into from
Jun 3, 2024
Merged
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
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ Goravel Installer is a command-line tool that helps you to install the Goravel f

| goravel/installer | goravel/framework |
|-------------------|-------------------|
| v1.1.x | v1.13.x |
| v1.0.x | v1.14.x |

## Installation

```bash
go install -u github.com/goravel/installer
# Install the latest version of the goravel installer
go install github.com/goravel/installer@latest

# You can rename the executable file
# Linux
mv "$GOBIN/installer" "$GOBIN/goravel"

# Windows
move "%GOBIN%\installer.exe" "%GOBIN%\goravel.exe"
```

## Usage
Expand Down
56 changes: 23 additions & 33 deletions console/commands/new_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package commands

import (
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"

"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/support/color"
"github.com/goravel/framework/support/file"
"github.com/pterm/pterm"

"github.com/goravel/installer/support"
Expand Down Expand Up @@ -44,7 +45,7 @@ func (receiver *NewCommand) Extend() command.Extend {

// Handle Execute the console command.
func (receiver *NewCommand) Handle(ctx console.Context) (err error) {
color.Cyan().Println(support.WelcomeHeading)
fmt.Println(pterm.NewRGB(142, 211, 249).Sprint(support.WelcomeHeading)) // color hex code: #8ED3F9
ctx.NewLine()
name := ctx.Argument(0)
if name == "" {
Expand Down Expand Up @@ -106,11 +107,8 @@ func (receiver *NewCommand) generate(ctx console.Context, name string) error {
// clone the repository
clone := exec.Command("git", "clone", "https://github.com/goravel/goravel.git", path)
err := ctx.Spinner("Creating a \"goravel/goravel\" project at \""+name+"\"", console.SpinnerOption{
Action: func() {
if err := clone.Run(); err != nil {
color.Errorf("error while generating the project : %s\n", err.Error())
return
}
Action: func() error {
return clone.Run()
},
})
if err != nil {
Expand All @@ -120,18 +118,9 @@ func (receiver *NewCommand) generate(ctx console.Context, name string) error {
color.Successln("created project in " + path)

// git cleanup
var removeFiles *exec.Cmd
if runtime.GOOS == "windows" {
removeFiles = exec.Command("Remove-Item", "-Path", path+"/.git", path+"/.github", "-Recursive", "-Force")
} else {
removeFiles = exec.Command("rm", "-rf", path+"/.git", path+"/.github")
}
err = ctx.Spinner("> @rm -rf "+name+"/.git "+name+"/.github", console.SpinnerOption{
Action: func() {
if err := removeFiles.Run(); err != nil {
color.Errorf("error happend while removing the files : %s\n", err)
return
}
Action: func() error {
return receiver.removeFiles(path)
},
})
if err != nil {
Expand All @@ -144,11 +133,8 @@ func (receiver *NewCommand) generate(ctx console.Context, name string) error {
install := exec.Command("go", "mod", "tidy")
install.Dir = path
err = ctx.Spinner("> @go mod tidy", console.SpinnerOption{
Action: func() {
if err := install.Run(); err != nil {
color.Errorf("error while installing the dependecies : %s\n", err)
return
}
Action: func() error {
return install.Run()
},
})
if err != nil {
Expand All @@ -161,11 +147,8 @@ func (receiver *NewCommand) generate(ctx console.Context, name string) error {
copyEnv := exec.Command("cp", ".env.example", ".env")
copyEnv.Dir = path
err = ctx.Spinner("> @cp .env.example .env", console.SpinnerOption{
Action: func() {
if err := copyEnv.Run(); err != nil {
color.Errorf("error while generating the .env file : %s\n", err)
return
}
Action: func() error {
return copyEnv.Run()
},
})
if err != nil {
Expand All @@ -178,11 +161,8 @@ func (receiver *NewCommand) generate(ctx console.Context, name string) error {
initAppKey := exec.Command("go", "run", ".", "artisan", "key:generate")
initAppKey.Dir = path
err = ctx.Spinner("> @go run . artisan key:generate", console.SpinnerOption{
Action: func() {
if err := initAppKey.Run(); err != nil {
color.Errorf("error while generating the app key : %s\n", err)
return
}
Action: func() error {
return initAppKey.Run()
},
})
if err != nil {
Expand All @@ -195,3 +175,13 @@ func (receiver *NewCommand) generate(ctx console.Context, name string) error {
color.Successln("Are you new to Goravel? Please visit https://goravel.dev to get started.")
return nil
}

func (receiver *NewCommand) removeFiles(path string) error {
// Remove the .git directory
if err := file.Remove(filepath.Join(path, ".git")); err != nil {
return err
}

// Remove the .GitHub directory
return file.Remove(filepath.Join(path, ".github"))
}
2 changes: 1 addition & 1 deletion console/commands/new_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNewCommand(t *testing.T) {
mockContext.On("Spinner", mock.Anything, mock.AnythingOfType("console.SpinnerOption")).Return(nil).
Run(func(args mock.Arguments) {
options := args.Get(1).(console.SpinnerOption)
options.Action()
assert.Nil(t, options.Action())
}).Times(5)
assert.Contains(t, color.CaptureOutput(func(w io.Writer) {
assert.Nil(t, newCommand.Handle(mockContext))
Expand Down
1 change: 1 addition & 0 deletions console/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package console

import (
"github.com/goravel/framework/contracts/console"

"github.com/goravel/installer/console/commands"
)

Expand Down
16 changes: 10 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/goravel/installer
go 1.21

require (
github.com/goravel/framework v1.13.1-0.20240528023202-cd4d68c816fc
github.com/goravel/framework v1.13.1-0.20240602041957-23b1eff4deec
github.com/pterm/pterm v0.12.79
github.com/stretchr/testify v1.9.0
)
Expand All @@ -16,14 +16,19 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/catppuccin/go v0.2.0 // indirect
github.com/charmbracelet/bubbles v0.18.0 // indirect
github.com/charmbracelet/bubbletea v0.26.1 // indirect
github.com/charmbracelet/huh v0.3.0 // indirect
github.com/charmbracelet/bubbletea v0.26.3 // indirect
github.com/charmbracelet/huh v0.4.2 // indirect
github.com/charmbracelet/huh/spinner v0.0.0-20240508140610-13957916abf0 // indirect
github.com/charmbracelet/lipgloss v0.10.1-0.20240506202754-3ee5dcab73cb // indirect
github.com/charmbracelet/x/exp/term v0.0.0-20240506152644-8135bef4e495 // indirect
github.com/charmbracelet/lipgloss v0.11.0 // indirect
github.com/charmbracelet/x/ansi v0.1.1 // indirect
github.com/charmbracelet/x/exp/strings v0.0.0-20240524151031-ff83003bf67a // indirect
github.com/charmbracelet/x/input v0.1.1 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/gabriel-vasile/mimetype v1.4.4 // indirect
github.com/gookit/color v1.5.4 // indirect
Expand All @@ -34,7 +39,6 @@ require (
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func main() {
name := "Goravel Installer"
usage := "A command-line tool to create Goravel projects."
usageText := "go run . [global options] command [command options] [arguments...]"
usageText := "goravel [global options] command [command options] [arguments...]"

cliApp := frameworkconsole.NewApplication(name, usage, usageText, support.Version, false)

Expand Down
2 changes: 1 addition & 1 deletion support/constant.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package support

const Version string = "v0.0.1"
const Version string = "v1.0.0"

const WelcomeHeading = `
___ ___ ___ _ __ __ ___ _
Expand Down
Loading