Skip to content

Commit

Permalink
feat: add support for windows os
Browse files Browse the repository at this point in the history
  • Loading branch information
mukezhz committed Apr 14, 2024
1 parent 951923c commit 9702a1e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
8 changes: 4 additions & 4 deletions cmd/add_infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func addInfrastructureHandler(_ *cobra.Command, args []string) {
return
}
infrastructureModulePath := filepath.Join(projectPath, "pkg", "infrastructure", "module.go")
templateInfraPath := filepath.Join(".", "templates", "wesionary", "infrastructure")
templateInfraPath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "infrastructure"))
infrasTmpl := utility.ListDirectory(templatesFS, templateInfraPath)
infras := utility.Map[string, string](infrasTmpl, func(q string) string {
return strings.Replace(q, ".tmpl", "", 1)
Expand Down Expand Up @@ -89,7 +89,7 @@ func addInfrastructure(
selected := q.Input.Selected()
for s := range selected {
functions = append(functions,
utility.GetFunctionDeclarations(filepath.Join(".", "templates", "wesionary", "infrastructure", infrasTmpl[s]), templatesFS)...,
utility.GetFunctionDeclarations(utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "infrastructure", infrasTmpl[s])), templatesFS)...,
)
items = append(items, s)
}
Expand All @@ -103,7 +103,7 @@ func addInfrastructure(

servicesTmplMap := make(map[string]bool)
for _, i := range items {
templatePath := filepath.Join(".", "templates", "wesionary", "infrastructure", infrasTmpl[i])
templatePath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "infrastructure", infrasTmpl[i]))
var targetRoot string
if isNewProject {
if data.Directory == "" {
Expand All @@ -116,7 +116,7 @@ func addInfrastructure(
}

fileName := strings.Replace(infrasTmpl[i], ".tmpl", "", 1)
serviceTemplatePath := filepath.Join(".", "templates", "wesionary", "service")
serviceTemplatePath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "service"))
for _, file := range utility.ListDirectory(templatesFS, serviceTemplatePath) {
if strings.Contains(file, fileName) {
servicesTmplMap[file] = true
Expand Down
8 changes: 4 additions & 4 deletions cmd/add_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func addServiceHandler(_ *cobra.Command, args []string) {
return
}
serviceModulePath := filepath.Join(projectPath, "pkg", "services", "module.go")
templateInfraPath := filepath.Join(".", "templates", "wesionary", "service")
templateInfraPath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "service"))
servicesTmpl := utility.ListDirectory(templatesFS, templateInfraPath)
services := utility.Map[string, string](servicesTmpl, func(q string) string {
return strings.Replace(q, ".tmpl", "", 1)
Expand Down Expand Up @@ -88,7 +88,7 @@ func addService(
case constant.ServiceNameKEY:
selected := q.Input.Selected()
for s := range selected {
funcs := utility.GetFunctionDeclarations(filepath.Join(".", "templates", "wesionary", "service", servicesTmpl[s]), templatesFS)
funcs := utility.GetFunctionDeclarations(utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "service", servicesTmpl[s])), templatesFS)
filteredServices := utility.Filter[string](funcs, func(q string) bool {
return strings.Contains(q, "New")
})
Expand All @@ -99,7 +99,7 @@ func addService(
}
case constant.InfrastructureNameKEY:
for i, s := range servicesTmpl {
funcs := utility.GetFunctionDeclarations(filepath.Join(".", "templates", "wesionary", "service", s), templatesFS)
funcs := utility.GetFunctionDeclarations(utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "service", s)), templatesFS)
filteredServices := utility.Filter[string](funcs, func(q string) bool {
return strings.Contains(q, "New")
})
Expand All @@ -118,7 +118,7 @@ func addService(
utility.WriteContentToPath(serviceModulePath, updatedCode)

for _, i := range items {
templatePath := filepath.Join(".", "templates", "wesionary", "service", servicesTmpl[i])
templatePath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "service", servicesTmpl[i]))
var targetRoot string
if isNewProject {
targetRoot = filepath.Join(data.PackageName, "pkg", "services", strings.Replace(servicesTmpl[i], ".tmpl", ".go", 1))
Expand Down
4 changes: 2 additions & 2 deletions cmd/create_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func createProject(cmd *cobra.Command, args []string) {
var directory string
var questions []terminal.ProjectQuestion

templateInfraPath := filepath.Join(".", "templates", "wesionary", "infrastructure")
templateInfraPath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "infrastructure"))
infrasTmpl := utility.ListDirectory(templatesFS, templateInfraPath)
infras := utility.Map[string, string](infrasTmpl, func(q string) string {
return strings.Replace(q, ".tmpl", "", 1)
Expand Down Expand Up @@ -99,7 +99,7 @@ func createProject(cmd *cobra.Command, args []string) {
}
targetRoot := data.Directory

templatePath := filepath.Join("templates", "wesionary", "project")
templatePath := utility.IgnoreWindowsPath(filepath.Join("templates", "wesionary", "project"))
err := utility.GenerateFiles(templatesFS, templatePath, targetRoot, data)
if err != nil {
color.Redln("Error generate file", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/new_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func generateModule(projectPath string, args []string, projectModule model.GoMod
data := utility.GetModuleDataFromModuleName(moduleName, projectModule.Module, projectModule.GoVersion)

targetRoot := filepath.Join(".", "domain", data.PackageName)
templatePath := filepath.Join(".", "templates", "wesionary", "module")
templatePath := utility.IgnoreWindowsPath(filepath.Join(".", "templates", "wesionary", "module"))

err := utility.GenerateFiles(templatesFS, templatePath, targetRoot, data)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions pkg/utility/path.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package utility

import (
"runtime"
"strings"
)

func IgnoreWindowsPath(p string) string {
if runtime.GOOS == "windows" {
return strings.ReplaceAll(p, "\\", "/")
}
return p
}

0 comments on commit 9702a1e

Please sign in to comment.