diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
index 42f6212..0a207d9 100644
--- a/.github/workflows/go.yml
+++ b/.github/workflows/go.yml
@@ -1,8 +1,9 @@
name: Go
on:
+ pull_request:
push:
- branches: [ develop ]
+ branches: [ master ]
jobs:
diff --git a/README.md b/README.md
index b92eeab..2d23239 100644
--- a/README.md
+++ b/README.md
@@ -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
+#### Output
+
+
+## Basic Usage
+
#### make config.yaml
```yaml
target_project_name: Miro // target project name
@@ -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.
\ No newline at end of file
+- Default values of source & test directoly flag follow the configuration file.
diff --git a/internal/converter/copyright.go b/internal/converter/copyright.go
new file mode 100644
index 0000000..ed740f0
--- /dev/null
+++ b/internal/converter/copyright.go
@@ -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
+}
diff --git a/internal/converter/copyright_test.go b/internal/converter/copyright_test.go
new file mode 100644
index 0000000..8a78fd3
--- /dev/null
+++ b/internal/converter/copyright_test.go
@@ -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)
+ }
+ })
+}
diff --git a/internal/converter/header.go b/internal/converter/header.go
index 34cab86..2c37ba3 100644
--- a/internal/converter/header.go
+++ b/internal/converter/header.go
@@ -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,
}
}
@@ -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
}
diff --git a/internal/converter/header_test.go b/internal/converter/header_test.go
index a9239f4..0817dfa 100644
--- a/internal/converter/header_test.go
+++ b/internal/converter/header_test.go
@@ -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"
diff --git a/internal/converter/source_test.go b/internal/converter/source_test.go
index 230870e..daca5e8 100644
--- a/internal/converter/source_test.go
+++ b/internal/converter/source_test.go
@@ -15,7 +15,7 @@ func createSource() *converter.SourceConverter {
config := &model.Config{
TargetProjectName: "Miro",
- Copyright: "Geektree0101",
+ Copyright: "David Ha",
TemplatePath: "../../templates",
SourceDir: "./Playground/Sources",
TestDir: "./Playground/Tests",
@@ -23,6 +23,10 @@ func createSource() *converter.SourceConverter {
}
header := converter.NewHeaderConverter(
+ CopyrightStub{
+ GetSuccessStub: "Geektree0101",
+ GetErrorStub: nil,
+ },
config,
date,
)
diff --git a/internal/gen/generator.go b/internal/gen/generator.go
index e80a2f2..0126281 100644
--- a/internal/gen/generator.go
+++ b/internal/gen/generator.go
@@ -48,6 +48,7 @@ func (gen *Generator) Run() error {
gen.flag.Name,
strings.Split(gen.flag.UsecasesString, ","),
converter.NewHeaderConverter(
+ converter.CopyrightImpl{},
config,
today,
),
diff --git a/res/example.png b/res/example.png
index 285d284..5ccd9b9 100644
Binary files a/res/example.png and b/res/example.png differ
diff --git a/res/output.png b/res/output.png
new file mode 100644
index 0000000..8595a88
Binary files /dev/null and b/res/output.png differ
diff --git a/runner.go b/runner.go
index cea6626..6e7496e 100644
--- a/runner.go
+++ b/runner.go
@@ -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")
- }
-
},
}
@@ -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")
+ }
+}
diff --git a/templates/test/Presenter.swift b/templates/test/Presenter.swift
index 254ba57..b45c7b3 100644
--- a/templates/test/Presenter.swift
+++ b/templates/test/Presenter.swift
@@ -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
}
}
diff --git a/test/ArticleDetailPresenterTests.swift b/test/ArticleDetailPresenterTests.swift
index b720648..2575757 100644
--- a/test/ArticleDetailPresenterTests.swift
+++ b/test/ArticleDetailPresenterTests.swift
@@ -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
}
}