Public Access
Rename the module, CLI command name, and all references from keystone/basalt to draft, and fix the stale build/README content found along the way.
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
//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/api_tmpl"
|
|
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!")
|
|
}
|