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 18, 2021
2 parents 28cb872 + 1e94366 commit 5276d95
Show file tree
Hide file tree
Showing 35 changed files with 2,665 additions and 5 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/go.yml
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 ./...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Playground/Sources/**
Playground/Tests/**
config.yaml
57 changes: 57 additions & 0 deletions README.md
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.
5 changes: 5 additions & 0 deletions go.mod
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
)
567 changes: 567 additions & 0 deletions go.sum

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions internal/converter/header.go
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
}
60 changes: 60 additions & 0 deletions internal/converter/header_test.go
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)
}
})
}
Loading

0 comments on commit 5276d95

Please sign in to comment.