Skip to content

Commit 754b278

Browse files
committed
Changes:
- `GeneratedFileCase` config values renamed to match world-wide accepted terms - Template functions: `uCamel`, `lCamel`, `snake` renamed with equivalent world-wide accepted terms - Model template now has previous config values accessible through `Routine` variable - New config values for folder names where generated models and processors will be placed - Model, Processor and DbContext templates now have new variable `Config` pointing to the config values of the application
1 parent 031f5db commit 754b278

File tree

7 files changed

+118
-22
lines changed

7 files changed

+118
-22
lines changed

.editorconfig

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = crlf
6+
indent_size = 2
7+
indent_style = tab
8+
insert_final_newline = true
9+
max_line_length = 160
10+
tab_width = 2
11+
trim_trailing_whitespace = false
12+
ij_formatter_off_tag = @formatter:off
13+
ij_formatter_on_tag = @formatter:on
14+
ij_formatter_tags_enabled = false
15+
ij_smart_tabs = true
16+
ij_visual_guides = none
17+
ij_wrap_on_typing = false
18+
19+
[*.{cs,js,css,cshtml,json,svelte,vue}]
20+
indent_style = tab
21+
indent_size = 2
22+
trim_trailing_whitespace = true
23+
end_of_line = crlf
24+
charset = utf-8
25+
ij_javascript_use_semicolon_after_statement = false
26+
27+
[*.{xaml,html,xml,heex,exs,ex,eex}]
28+
indent_style = tab
29+
indent_size = 2
30+
trim_trailing_whitespace = true
31+
end_of_line = crlf
32+
charset = utf-8
33+
34+
[*.{heex,exs,ex,eex}]
35+
indent_style = space
36+
ij_any_line_comment_at_first_column = false
37+
ij_any_block_comment_at_first_column = false

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# CHANGELOG
2+
3+
# 0.2.2
4+
5+
## Breaking changes!
6+
7+
- `GeneratedFileCase` config values renamed to match world-wide accepted terms:
8+
- from: `"snake"` to: `"snakecase"`
9+
- from: `"lcase"` to: `"camelcase"`
10+
- from: `"ucase"` to: `"pascalcase"`
11+
12+
- Template functions: `uCamel`, `lCamel`, `snake` renamed with equivalent world-wide accepted terms:
13+
- from: `"snake"` to: `"snakeCased"`
14+
- from: `"lCamel"` to: `"camelCased"`
15+
- from: `"uCamel"` to: `"pascalCased"`
16+
17+
- Model template now has previous config values accessible through `Routine` variable
18+
19+
## New features
20+
21+
- New config values for folder names where generated models and processors will be placed
22+
- `ProcessorsFolderName` with default value: `"processors"`
23+
- `ModelsFolderName` with default value: `"models"`
24+
- Model, Processor and DbContext templates now have new variable `Config` pointing to the config values of the application

CHANGELOG.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/config.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type Config struct {
1717
PathBase string //for now just using config folder
1818
ConnectionString string `mapstructure:"ConnectionString"`
1919
OutputFolder string `mapstructure:"OutputFolder"`
20+
ProcessorsFolderName string `mapstructure:"ProcessorsFolderName"`
21+
ModelsFolderName string `mapstructure:"ModelsFolderName"`
2022
GenerateModels bool `mapstructure:"GenerateModels"`
2123
GenerateProcessors bool `mapstructure:"GenerateProcessors"`
2224
GenerateProcessorsForVoidReturns bool `mapstructure:"GenerateProcessorsForVoidReturns"`
@@ -51,7 +53,25 @@ var loadedConfigLocation = ""
5153

5254
// GetAndValidateConfig gets configuration from viper
5355
func GetAndValidateConfig() (*Config, error) {
54-
config := new(Config)
56+
config := &Config{
57+
PathBase: "",
58+
ConnectionString: "",
59+
OutputFolder: "",
60+
ProcessorsFolderName: "processors",
61+
ModelsFolderName: "models",
62+
GenerateModels: false,
63+
GenerateProcessors: false,
64+
GenerateProcessorsForVoidReturns: false,
65+
DbContextTemplate: "",
66+
ModelTemplate: "",
67+
ProcessorTemplate: "",
68+
GeneratedFileExtension: "",
69+
GeneratedFileCase: "",
70+
Debug: false,
71+
ClearOutputFolder: false,
72+
Generate: nil,
73+
Mappings: nil,
74+
}
5575

5676
err := viper.Unmarshal(config)
5777
if err != nil {

src/generator-functions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ func getTemplateFunctions() template.FuncMap {
1010
"inc": func(n int) int {
1111
return n + 1
1212
},
13-
"uCamel": func(s string) string {
13+
"pascalCased": func(s string) string {
1414
return strcase.UpperCamelCase(s)
1515
},
16-
"lCamel": func(s string) string {
16+
"camelCased": func(s string) string {
1717
return strcase.LowerCamelCase(s)
1818
},
19-
"snake": func(s string) string {
19+
"snakeCased": func(s string) string {
2020
return strcase.SnakeCase(s)
2121
},
2222
}

src/generator.go

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import (
1414
"text/template"
1515
)
1616

17-
const processorsFolder = "processors"
18-
const modelsFolder = "models"
19-
2017
var ValidCaseNormalized = []string{"snakecase", "camelcase", "pascalcase"}
2118

2219
func Generate(routines []Routine, config *Config) error {
@@ -64,19 +61,20 @@ func Generate(routines []Routine, config *Config) error {
6461
}
6562

6663
func generateDbContext(routines []Routine, hashMap *map[string]string, config *Config) error {
67-
dbcontextTemplate, err := parseTemplates(config.DbContextTemplate)
64+
dbContextTemplate, err := parseTemplate(config.DbContextTemplate)
6865
if err != nil {
6966
return fmt.Errorf("loading dbContext template: %s", err)
7067
}
7168

7269
data := &DbContextData{
70+
Config: config,
7371
Functions: routines,
7472
}
7573

7674
filename := changeCase("DbContext"+config.GeneratedFileExtension, config.GeneratedFileCase)
7775
fp := filepath.Join(config.OutputFolder, filename)
7876

79-
changed, err := generateFile(data, dbcontextTemplate, fp, hashMap)
77+
changed, err := generateFile(data, dbContextTemplate, fp, hashMap)
8078
if err != nil {
8179
return err
8280
}
@@ -92,24 +90,28 @@ func generateDbContext(routines []Routine, hashMap *map[string]string, config *C
9290
}
9391

9492
func generateModels(routines []Routine, hashMap *map[string]string, config *Config) error {
95-
96-
moduleTemplate, err := parseTemplates(config.ModelTemplate)
93+
moduleTemplate, err := parseTemplate(config.ModelTemplate)
9794
if err != nil {
9895
return fmt.Errorf("loading module template: %s", err)
9996
}
10097

101-
err = os.MkdirAll(filepath.Join(config.OutputFolder, modelsFolder), 0777)
98+
err = os.MkdirAll(filepath.Join(config.OutputFolder, config.ModelsFolderName), 0777)
10299

103100
for _, routine := range routines {
104101
if !routine.HasReturn {
105102
continue
106103
}
107104

108105
filename := changeCase(routine.ModelName+config.GeneratedFileExtension, config.GeneratedFileCase)
109-
relPath := filepath.Join(modelsFolder, filename)
106+
relPath := filepath.Join(config.ModelsFolderName, filename)
110107
filePath := filepath.Join(config.OutputFolder, relPath)
111108

112-
changed, err := generateFile(routine, moduleTemplate, filePath, hashMap)
109+
data := &ModelTemplateData{
110+
Config: config,
111+
Routine: routine,
112+
}
113+
114+
changed, err := generateFile(data, moduleTemplate, filePath, hashMap)
113115
if err != nil {
114116
return fmt.Errorf("generating models: %s", err)
115117
}
@@ -125,12 +127,12 @@ func generateModels(routines []Routine, hashMap *map[string]string, config *Conf
125127
}
126128

127129
func generateProcessors(routines []Routine, hashMap *map[string]string, config *Config) error {
128-
processorTemplate, err := parseTemplates(config.ProcessorTemplate)
130+
processorTemplate, err := parseTemplate(config.ProcessorTemplate)
129131
if err != nil {
130132
return fmt.Errorf("loading processor template: %s", err)
131133
}
132134

133-
err = os.MkdirAll(filepath.Join(config.OutputFolder, processorsFolder), 0777)
135+
err = os.MkdirAll(filepath.Join(config.OutputFolder, config.ProcessorsFolderName), 0777)
134136
if err != nil {
135137
return fmt.Errorf("creating processor output folder: %s", err)
136138
}
@@ -143,10 +145,15 @@ func generateProcessors(routines []Routine, hashMap *map[string]string, config *
143145
}
144146

145147
filename := changeCase(routine.ProcessorName+config.GeneratedFileExtension, config.GeneratedFileCase)
146-
relPath := filepath.Join(processorsFolder, filename)
148+
relPath := filepath.Join(config.ProcessorsFolderName, filename)
147149
filePath := filepath.Join(config.OutputFolder, relPath)
148150

149-
changed, err := generateFile(routine, processorTemplate, filePath, hashMap)
151+
data := &ProcessorTemplateData{
152+
Config: config,
153+
Routine: routine,
154+
}
155+
156+
changed, err := generateFile(data, processorTemplate, filePath, hashMap)
150157
if err != nil {
151158
return fmt.Errorf("generating processor %s: %s", routine.ProcessorName, err)
152159
}
@@ -161,7 +168,7 @@ func generateProcessors(routines []Routine, hashMap *map[string]string, config *
161168
return nil
162169
}
163170

164-
func parseTemplates(templatePath string) (*template.Template, error) {
171+
func parseTemplate(templatePath string) (*template.Template, error) {
165172
if !common.PathExists(templatePath) {
166173
return nil, fmt.Errorf("template file %s does not exist", templatePath)
167174

src/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,16 @@ type Routine struct {
2525
}
2626

2727
type DbContextData struct {
28+
Config *Config
2829
Functions []Routine
2930
}
31+
32+
type ProcessorTemplateData struct {
33+
Config *Config
34+
Routine Routine
35+
}
36+
37+
type ModelTemplateData struct {
38+
Config *Config
39+
Routine Routine
40+
}

0 commit comments

Comments
 (0)