Public Access
feat: basalt 0.0.1
This commit is contained in:
22 files changed
+1364
-1
No files matched your search
@@ -0,0 +1,69 @@
|
||||
//go:build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
sourceDir = "assets/testdata/api_tmpl"
|
||||
targetDir = "assets/embedded"
|
||||
oldModuleName = "github.com/FernandoJVideira/simple_bank"
|
||||
moduleTemplate = "{{ .ModuleName }}"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Println("Syncing templates...")
|
||||
syncTemplates()
|
||||
}
|
||||
|
||||
func syncTemplates() {
|
||||
|
||||
err := filepath.WalkDir(sourceDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
relPath, _ := filepath.Rel(sourceDir, path)
|
||||
destPath := filepath.Join(targetDir, relPath)
|
||||
|
||||
if strings.HasPrefix(d.Name(), ".") && d.Name() != "." {
|
||||
if d.IsDir() {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if d.IsDir() {
|
||||
return os.MkdirAll(destPath, 0755)
|
||||
}
|
||||
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if d.Name() == "go.mod" || d.Name() == "go.sum" {
|
||||
destPath += ".tmpl"
|
||||
}
|
||||
|
||||
if d.Name() == "go.mod" {
|
||||
strContent := string(content)
|
||||
strContent = strings.Replace(strContent, oldModuleName, moduleTemplate, 1)
|
||||
content = []byte(strContent)
|
||||
}
|
||||
|
||||
return os.WriteFile(destPath, content, 0644)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error walking source: %v", err)
|
||||
}
|
||||
|
||||
log.Println("Templates synced successfully!")
|
||||
}
|
||||
Reference in new issue
Block a user