Skip to content

Commit

Permalink
refactor: change extension and remove replacing tmpl to go
Browse files Browse the repository at this point in the history
  • Loading branch information
mukezhz committed Dec 7, 2023
1 parent c1b8d12 commit d55b18e
Show file tree
Hide file tree
Showing 37 changed files with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions pkg/utility/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"bufio"
"embed"
"fmt"
"github.com/gookit/color"
"github.com/mukezhz/geng/pkg/model"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"io"
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/gookit/color"
"github.com/mukezhz/geng/pkg/model"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func WriteContentToPath(path, content string) {
Expand Down Expand Up @@ -85,25 +86,20 @@ func GenerateFiles(templatesFS embed.FS, templatePath string, targetRoot string,
}

// Handle template files
if filepath.Ext(path) == ".tmpl" {
// Generate the Go file in the target directory
goFile := strings.Replace(dst, "tmpl", "go", 1)
generateFromEmbeddedTemplate(templatesFS, path, goFile, data)
} else {
// Copy or process other files as before
if filepath.Ext(path) == ".mod" || filepath.Ext(path) == ".md" {
dst = strings.Replace(dst, ".mod", "", 1)
generateFromEmbeddedTemplate(templatesFS, path, dst, data)
} else {
if strings.HasPrefix(fileName, "hidden.") {
dst = strings.Replace(dst, "hidden.", ".", 1)
}
// just copy the files to the target directory
if err := copyFile(path, dst, templatesFS); err != nil {
panic(err)
}
// Copy or process other files as before
if filepath.Ext(path) == ".mod" {
dst = strings.Replace(dst, ".mod", "", 1)
}
generateFromEmbeddedTemplate(templatesFS, path, dst, data)

if strings.HasPrefix(fileName, "hidden.") {
dst = strings.Replace(dst, "hidden.", ".", 1)
// just copy the files to the target directory
if err := copyFile(path, dst, templatesFS); err != nil {
panic(err)
}
}

return nil
})
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d55b18e

Please sign in to comment.