Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekTree0101 committed Aug 29, 2021
2 parents 5276d95 + 33f3ed9 commit 9abf0db
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Go

on:
pull_request:
push:
branches: [ develop ]
branches: [ master ]

jobs:

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
[![Go](https://github.com/GeekTree0101/clean-swift-scaffold/actions/workflows/go.yml/badge.svg?branch=develop)](https://github.com/GeekTree0101/clean-swift-scaffold/actions/workflows/go.yml)


### Basic Usage
## Overview

#### Run
<img height=300pt src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/res/example.png" />

#### Output
<img height=300pt src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/res/output.png" />

## Basic Usage

#### make config.yaml
```yaml
target_project_name: Miro // target project name
Expand Down Expand Up @@ -54,4 +60,4 @@ flag list
```

- Please set the name and directory of the configuration file freely. Instead, please enter the correct path on -c/--config flag.
- Default values of source & test directoly flag follow the configuration file.
- Default values of source & test directoly flag follow the configuration file.
43 changes: 43 additions & 0 deletions internal/converter/copyright.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package converter

import (
"os/exec"
"os/user"
"strings"
)

type Copyright interface {
Get() (string, error)
}

type CopyrightImpl struct {
}

func (c CopyrightImpl) Get() (string, error) {

gitUsername, err := c.getGitUsername()

if err == nil {
return gitUsername, nil
}

user, err := user.Current()

if err == nil {
return user.Username, nil
}

return "", err
}

func (c CopyrightImpl) getGitUsername() (string, error) {

gitCmd := exec.Command("git", "config", "--global", "user.name")
nameBytes, err := gitCmd.Output()

if err == nil && len(nameBytes) > 0 {
return strings.Trim(string(nameBytes), "\n"), nil
}

return "", err
}
41 changes: 41 additions & 0 deletions internal/converter/copyright_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package converter_test

import (
"testing"

"github.com/Geektree0101/clean-swift-scaffold/internal/converter"
)

// MARK: - Test Double

type CopyrightStub struct {
GetSuccessStub string
GetErrorStub error
}

func (c CopyrightStub) Get() (string, error) {

return c.GetSuccessStub, c.GetErrorStub
}

// MARK: - Test Case

func TestCopyright(t *testing.T) {

t.Run("get copyright", func(t *testing.T) {
// given
sut := converter.CopyrightImpl{}

// when
out, err := sut.Get()

// then
if err != nil {
t.Error(err)
}

if len(out) == 0 {
t.Errorf("output should be longer than 0, output: %s", out)
}
})
}
23 changes: 16 additions & 7 deletions internal/converter/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ import (
)

type HeaderConverter struct {
targetProjectName string
copyright string
date time.Time
copyright Copyright
targetProjectName string
copyrightDefaultValue string
date time.Time
}

func NewHeaderConverter(
copyright Copyright,
config *model.Config,
date time.Time) *HeaderConverter {

return &HeaderConverter{
targetProjectName: config.TargetProjectName,
copyright: config.Copyright,
date: date,
copyright: copyright,
targetProjectName: config.TargetProjectName,
copyrightDefaultValue: config.Copyright,
date: date,
}
}

Expand All @@ -34,12 +37,18 @@ func (header *HeaderConverter) Render(source string, sceneName string) string {

dateStr := fmt.Sprintf("%d/%d/%d", day, month, year)

copyright, err := header.copyright.Get()

if err != nil {
copyright = header.copyrightDefaultValue
}

var replacedSource string = source
replacedSource = strings.ReplaceAll(replacedSource, "__SCENE_NAME__", sceneName)
replacedSource = strings.ReplaceAll(replacedSource, "__TARGET_PROJECT_NAME__", header.targetProjectName)
replacedSource = strings.ReplaceAll(replacedSource, "__DATE__", dateStr)
replacedSource = strings.ReplaceAll(replacedSource, "__YEAR__", strconv.Itoa(year))
replacedSource = strings.ReplaceAll(replacedSource, "__COPYRIGHT__", header.copyright)
replacedSource = strings.ReplaceAll(replacedSource, "__COPYRIGHT__", copyright)

return replacedSource
}
11 changes: 9 additions & 2 deletions internal/converter/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,19 @@ func TestHeader(t *testing.T) {
// given
config := model.Config{
TargetProjectName: "Miro",
Copyright: "Geektree0101",
Copyright: "David Ha",
TemplatePath: "",
}

date := time.Date(2020, 10, 12, 0, 0, 0, 0, time.UTC)
sut := converter.NewHeaderConverter(&config, date)
sut := converter.NewHeaderConverter(
CopyrightStub{
GetSuccessStub: "Geektree0101",
GetErrorStub: nil,
},
&config,
date,
)

usecaseName := "ArticleDetail"

Expand Down
6 changes: 5 additions & 1 deletion internal/converter/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ func createSource() *converter.SourceConverter {

config := &model.Config{
TargetProjectName: "Miro",
Copyright: "Geektree0101",
Copyright: "David Ha",
TemplatePath: "../../templates",
SourceDir: "./Playground/Sources",
TestDir: "./Playground/Tests",
Indentation: 2,
}

header := converter.NewHeaderConverter(
CopyrightStub{
GetSuccessStub: "Geektree0101",
GetErrorStub: nil,
},
config,
date,
)
Expand Down
1 change: 1 addition & 0 deletions internal/gen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (gen *Generator) Run() error {
gen.flag.Name,
strings.Split(gen.flag.UsecasesString, ","),
converter.NewHeaderConverter(
converter.CopyrightImpl{},
config,
today,
),
Expand Down
Binary file modified res/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 77 additions & 18 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,19 @@ func NewRunnerCommand(use string) *cobra.Command {
Short: "generate source & unit tests files",
Run: func(cmd *cobra.Command, args []string) {

fmt.Printf("\033[32m%s\033[0m\n", logo)

if len(name) == 0 {
fmt.Println("[Error] invalid usecase name\033[0m")
return
}

gen := gen.NewGenerator(
gen.Genflag{
Name: name,
UsecasesString: usecasesString,
SourceDir: sourceDir,
TestDir: testDir,
ConfigFilePath: configFilePath,
},
run(
name,
usecasesString,
sourceDir,
testDir,
configFilePath,
)

err := gen.Run()

if err != nil {
fmt.Printf("\033[31m[Error] failed to generate: %s\n\033[0m", err.Error())
} else {
fmt.Printf("\033[32m[Log] Done!\n\n\033[0m")
}

},
}

Expand All @@ -78,3 +66,74 @@ func NewRunnerCommand(use string) *cobra.Command {

return genCmd
}

// Procedural runner command
// name: the prefix of the scene/screen
// usecases
// config path
func NewProceduralRunnerCommand(use string) *cobra.Command {

var name string
var usecasesString string
var configFilePath string

genCmd := &cobra.Command{
Use: use,
Short: "generate source & unit tests files",
Run: func(cmd *cobra.Command, args []string) {

fmt.Println("Please enter the prefix of the scene/screen.")
fmt.Println("example: ArticleDetail or ChatList or UserList and so on")
fmt.Print("insert: ")
fmt.Scanln(&name)

fmt.Println("\nPlease enter usecases")
fmt.Println("example: Fetch,Delete,Update")
fmt.Print("insert: ")
fmt.Scanln(&usecasesString)

fmt.Println("\nPlease enter the config file")
fmt.Println("example: ./some_path/some_config.yaml")
fmt.Print("insert: ")
fmt.Scanln(&configFilePath)

run(
name,
usecasesString,
"", // unused
"", // unused
configFilePath,
)
},
}
return genCmd
}

func run(
name string,
usecasesString string,
sourceDir string,
testDir string,
configFilePath string,
) {

fmt.Printf("\033[32m%s\033[0m\n", logo)

gen := gen.NewGenerator(
gen.Genflag{
Name: name,
UsecasesString: usecasesString,
SourceDir: sourceDir,
TestDir: testDir,
ConfigFilePath: configFilePath,
},
)

err := gen.Run()

if err != nil {
fmt.Printf("\033[31m[Error] failed to generate: %s\n\033[0m", err.Error())
} else {
fmt.Printf("\033[32m[Log] Done!\n\n\033[0m")
}
}
2 changes: 1 addition & 1 deletion templates/test/Presenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class __SCENE_NAME__PresenterTests: XCTestCase {
override func setUp() {
self.presenter = __SCENE_NAME__Presenter()
self.display = __SCENE_NAME__DisplaySpy()
self.presenter.view = self.display
self.presenter.viewController = self.display
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/ArticleDetailPresenterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class ArticleDetailPresenterTests: XCTestCase {
override func setUp() {
self.presenter = ArticleDetailPresenter()
self.display = ArticleDetailDisplaySpy()
self.presenter.view = self.display
self.presenter.viewController = self.display
}
}

Expand Down

0 comments on commit 9abf0db

Please sign in to comment.