-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
2,665 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ develop ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Playground/Sources/** | ||
Playground/Tests/** | ||
config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<img src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/logo.png" /> | ||
|
||
### Clean-Swift source & test code auto generator | ||
|
||
[![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 | ||
|
||
<img height=300pt src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/res/example.png" /> | ||
|
||
#### make config.yaml | ||
```yaml | ||
target_project_name: Miro // target project name | ||
copyright: Geektree0101 // copyright | ||
template_path: ./templates // templates path | ||
source_path: ./Playground/Sources // base source file destination | ||
test_path: ./Playground/Tests // base test file destination | ||
indentation: 2 // indentation | ||
``` | ||
#### add clean_swift_scaffold runner command on your command | ||
```go | ||
var rootCmd = &cobra.Command{ | ||
Use: "your cmd", | ||
Short: "your cmd short marty", | ||
Long: "your cmd long something", | ||
} | ||
|
||
init() { | ||
rootCmd.AddCommand(clean_swift_scaffold.NewRunnerCommand("**use_name**")) | ||
} | ||
|
||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} | ||
``` | ||
|
||
#### run | ||
```sh | ||
your_command **use_name** -n Feed -u Fetch,Delete,Update | ||
``` | ||
|
||
flag list | ||
```sh | ||
- -n/--name: scene prefix | ||
- -u/--usecase: some model behavior (such as Fetch, Get, Reload, Delete and so on) | ||
- -c/--config: config.yaml path ./some_dir/config.yaml or ./some_dir/some_config.yaml | ||
- -s/--source: custom base source_dir (Default values follow the configuration file.) | ||
- -t/--test: custon base test_dir (Default values follow the configuration file.) | ||
``` | ||
|
||
- 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
module github.com/Geektree0101/clean-swift-scaffold | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/spf13/cobra v1.2.1 | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package converter | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
"time" | ||
|
||
"github.com/Geektree0101/clean-swift-scaffold/internal/model" | ||
) | ||
|
||
type HeaderConverter struct { | ||
targetProjectName string | ||
copyright string | ||
date time.Time | ||
} | ||
|
||
func NewHeaderConverter( | ||
config *model.Config, | ||
date time.Time) *HeaderConverter { | ||
|
||
return &HeaderConverter{ | ||
targetProjectName: config.TargetProjectName, | ||
copyright: config.Copyright, | ||
date: date, | ||
} | ||
} | ||
|
||
func (header *HeaderConverter) Render(source string, sceneName string) string { | ||
|
||
day := header.date.Day() | ||
month := int(header.date.Month()) | ||
year := header.date.Year() | ||
|
||
dateStr := fmt.Sprintf("%d/%d/%d", day, month, year) | ||
|
||
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) | ||
|
||
return replacedSource | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package converter_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/Geektree0101/clean-swift-scaffold/internal/converter" | ||
"github.com/Geektree0101/clean-swift-scaffold/internal/model" | ||
) | ||
|
||
const dummySourceCode string = `// | ||
// __SCENE_NAME__Model.swift | ||
// __TARGET_PROJECT_NAME__ | ||
// | ||
// Created by clean-swift-scaffold on __DATE__. | ||
// Copyright © __YEAR__ __COPYRIGHT__. All rights reserved. | ||
// | ||
enum __SCENE_NAME__Model { | ||
// clean-swift-scaffold-generate-dto (do-not-remove-comments) | ||
}` | ||
|
||
const expectedSourceCode string = `// | ||
// ArticleDetailModel.swift | ||
// Miro | ||
// | ||
// Created by clean-swift-scaffold on 12/10/2020. | ||
// Copyright © 2020 Geektree0101. All rights reserved. | ||
// | ||
enum ArticleDetailModel { | ||
// clean-swift-scaffold-generate-dto (do-not-remove-comments) | ||
}` | ||
|
||
func TestHeader(t *testing.T) { | ||
|
||
t.Run("return expected header", func(t *testing.T) { | ||
// given | ||
config := model.Config{ | ||
TargetProjectName: "Miro", | ||
Copyright: "Geektree0101", | ||
TemplatePath: "", | ||
} | ||
|
||
date := time.Date(2020, 10, 12, 0, 0, 0, 0, time.UTC) | ||
sut := converter.NewHeaderConverter(&config, date) | ||
|
||
usecaseName := "ArticleDetail" | ||
|
||
// when | ||
output := sut.Render(dummySourceCode, usecaseName) | ||
|
||
// then | ||
if output != expectedSourceCode { | ||
t.Errorf("Failed to render\n expected:\n%s\noutput:\n%s\n", expectedSourceCode, output) | ||
} | ||
}) | ||
} |
Oops, something went wrong.