diff --git a/cmd/add_infrastructure.go b/cmd/add_infrastructure.go index 5883751..8163c29 100644 --- a/cmd/add_infrastructure.go +++ b/cmd/add_infrastructure.go @@ -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) @@ -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) } @@ -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 == "" { @@ -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 diff --git a/cmd/add_service.go b/cmd/add_service.go index 5248dca..7c432ac 100644 --- a/cmd/add_service.go +++ b/cmd/add_service.go @@ -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) @@ -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") }) @@ -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") }) @@ -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)) diff --git a/cmd/create_project.go b/cmd/create_project.go index bc9db94..692fbbd 100644 --- a/cmd/create_project.go +++ b/cmd/create_project.go @@ -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) @@ -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) diff --git a/cmd/new_module.go b/cmd/new_module.go index cc43917..0a678d0 100644 --- a/cmd/new_module.go +++ b/cmd/new_module.go @@ -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 { diff --git a/pkg/utility/path.go b/pkg/utility/path.go new file mode 100644 index 0000000..101bbc4 --- /dev/null +++ b/pkg/utility/path.go @@ -0,0 +1,13 @@ +package utility + +import ( + "runtime" + "strings" +) + +func IgnoreWindowsPath(p string) string { + if runtime.GOOS == "windows" { + return strings.ReplaceAll(p, "\\", "/") + } + return p +}