Skip to content

Commit 5276d95

Browse files
committed
Merge branch 'refs/heads/develop'
2 parents 28cb872 + 1e94366 commit 5276d95

35 files changed

+2665
-5
lines changed

.github/workflows/go.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
7+
jobs:
8+
9+
build:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up Go
15+
uses: actions/setup-go@v2
16+
with:
17+
go-version: 1.16
18+
19+
- name: Build
20+
run: go build -v ./...
21+
22+
- name: Test
23+
run: go test -v ./...

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Playground/Sources/**
2+
Playground/Tests/**
3+
config.yaml

README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<img src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/logo.png" />
2+
3+
### Clean-Swift source & test code auto generator
4+
5+
[![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)
6+
7+
8+
### Basic Usage
9+
10+
<img height=300pt src="https://github.com/GeekTree0101/clean-swift-scaffold/blob/develop/res/example.png" />
11+
12+
#### make config.yaml
13+
```yaml
14+
target_project_name: Miro // target project name
15+
copyright: Geektree0101 // copyright
16+
template_path: ./templates // templates path
17+
source_path: ./Playground/Sources // base source file destination
18+
test_path: ./Playground/Tests // base test file destination
19+
indentation: 2 // indentation
20+
```
21+
22+
#### add clean_swift_scaffold runner command on your command
23+
```go
24+
var rootCmd = &cobra.Command{
25+
Use: "your cmd",
26+
Short: "your cmd short marty",
27+
Long: "your cmd long something",
28+
}
29+
30+
init() {
31+
rootCmd.AddCommand(clean_swift_scaffold.NewRunnerCommand("**use_name**"))
32+
}
33+
34+
func Execute() {
35+
if err := rootCmd.Execute(); err != nil {
36+
fmt.Fprintln(os.Stderr, err)
37+
os.Exit(1)
38+
}
39+
}
40+
```
41+
42+
#### run
43+
```sh
44+
your_command **use_name** -n Feed -u Fetch,Delete,Update
45+
```
46+
47+
flag list
48+
```sh
49+
- -n/--name: scene prefix
50+
- -u/--usecase: some model behavior (such as Fetch, Get, Reload, Delete and so on)
51+
- -c/--config: config.yaml path ./some_dir/config.yaml or ./some_dir/some_config.yaml
52+
- -s/--source: custom base source_dir (Default values follow the configuration file.)
53+
- -t/--test: custon base test_dir (Default values follow the configuration file.)
54+
```
55+
56+
- Please set the name and directory of the configuration file freely. Instead, please enter the correct path on -c/--config flag.
57+
- Default values of source & test directoly flag follow the configuration file.

go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module github.com/Geektree0101/clean-swift-scaffold
22

33
go 1.16
4+
5+
require (
6+
github.com/spf13/cobra v1.2.1
7+
gopkg.in/yaml.v2 v2.4.0 // indirect
8+
)

go.sum

+567
Large diffs are not rendered by default.

internal/converter/header.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package converter
2+
3+
import (
4+
"fmt"
5+
"strconv"
6+
"strings"
7+
"time"
8+
9+
"github.com/Geektree0101/clean-swift-scaffold/internal/model"
10+
)
11+
12+
type HeaderConverter struct {
13+
targetProjectName string
14+
copyright string
15+
date time.Time
16+
}
17+
18+
func NewHeaderConverter(
19+
config *model.Config,
20+
date time.Time) *HeaderConverter {
21+
22+
return &HeaderConverter{
23+
targetProjectName: config.TargetProjectName,
24+
copyright: config.Copyright,
25+
date: date,
26+
}
27+
}
28+
29+
func (header *HeaderConverter) Render(source string, sceneName string) string {
30+
31+
day := header.date.Day()
32+
month := int(header.date.Month())
33+
year := header.date.Year()
34+
35+
dateStr := fmt.Sprintf("%d/%d/%d", day, month, year)
36+
37+
var replacedSource string = source
38+
replacedSource = strings.ReplaceAll(replacedSource, "__SCENE_NAME__", sceneName)
39+
replacedSource = strings.ReplaceAll(replacedSource, "__TARGET_PROJECT_NAME__", header.targetProjectName)
40+
replacedSource = strings.ReplaceAll(replacedSource, "__DATE__", dateStr)
41+
replacedSource = strings.ReplaceAll(replacedSource, "__YEAR__", strconv.Itoa(year))
42+
replacedSource = strings.ReplaceAll(replacedSource, "__COPYRIGHT__", header.copyright)
43+
44+
return replacedSource
45+
}

internal/converter/header_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package converter_test
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/Geektree0101/clean-swift-scaffold/internal/converter"
8+
"github.com/Geektree0101/clean-swift-scaffold/internal/model"
9+
)
10+
11+
const dummySourceCode string = `//
12+
// __SCENE_NAME__Model.swift
13+
// __TARGET_PROJECT_NAME__
14+
//
15+
// Created by clean-swift-scaffold on __DATE__.
16+
// Copyright © __YEAR__ __COPYRIGHT__. All rights reserved.
17+
//
18+
19+
enum __SCENE_NAME__Model {
20+
21+
// clean-swift-scaffold-generate-dto (do-not-remove-comments)
22+
}`
23+
24+
const expectedSourceCode string = `//
25+
// ArticleDetailModel.swift
26+
// Miro
27+
//
28+
// Created by clean-swift-scaffold on 12/10/2020.
29+
// Copyright © 2020 Geektree0101. All rights reserved.
30+
//
31+
32+
enum ArticleDetailModel {
33+
34+
// clean-swift-scaffold-generate-dto (do-not-remove-comments)
35+
}`
36+
37+
func TestHeader(t *testing.T) {
38+
39+
t.Run("return expected header", func(t *testing.T) {
40+
// given
41+
config := model.Config{
42+
TargetProjectName: "Miro",
43+
Copyright: "Geektree0101",
44+
TemplatePath: "",
45+
}
46+
47+
date := time.Date(2020, 10, 12, 0, 0, 0, 0, time.UTC)
48+
sut := converter.NewHeaderConverter(&config, date)
49+
50+
usecaseName := "ArticleDetail"
51+
52+
// when
53+
output := sut.Render(dummySourceCode, usecaseName)
54+
55+
// then
56+
if output != expectedSourceCode {
57+
t.Errorf("Failed to render\n expected:\n%s\noutput:\n%s\n", expectedSourceCode, output)
58+
}
59+
})
60+
}

0 commit comments

Comments
 (0)