Add ent schema to starter

This commit is contained in:
Achim Rohn
2025-09-14 16:34:52 +02:00
parent 92488618a9
commit fae6653f94
25 changed files with 3982 additions and 7 deletions
+20 -6
View File
@@ -40,6 +40,14 @@ func NewStarterCreator(params Params) StarterCreator {
panic("ProjectDir is empty; nothing to do")
}
thisDir := GetPathToThisDir()
return StarterCreator{
params: params,
thisDir: thisDir,
}
}
func GetPathToThisDir() string {
// Resolve the path to the starter main.go located at ../main.go relative to this file
_, thisFile, _, ok := runtime.Caller(0)
if !ok {
@@ -47,10 +55,7 @@ func NewStarterCreator(params Params) StarterCreator {
panic("unable to resolve current file location via runtime.Caller")
}
thisDir := filepath.Dir(thisFile)
return StarterCreator{
params: params,
thisDir: thisDir,
}
return thisDir
}
// Create reads the starter main.go file bundled with this package
@@ -105,10 +110,20 @@ func (s StarterCreator) Create() {
"page",
"routes",
"static",
"ent",
}
for _, dir := range directories {
s.copyDirectoryRecursive(path.Join(s.thisDir, "..", dir), path.Join(s.params.ProjectDir, dir))
}
s.copySchemaFiles()
}
func (s StarterCreator) copySchemaFiles() {
s.copyFile("../../schema/ent/pagination_query.tmpl", "ent/pagination_query.tmpl")
content, err := os.ReadFile(filepath.Join(s.thisDir, "../generate_schema.go"))
must(err)
//content = s.replaceImports(content)
must(os.WriteFile(filepath.Join(s.params.ProjectDir, "generate_schema.go"), content, 0o644))
}
func (s StarterCreator) createEnvironment() {
@@ -157,7 +172,6 @@ func (s StarterCreator) copyFile(src string, dst string) {
func (s StarterCreator) copyDirectoryRecursive(src string, dst string) {
must(os.MkdirAll(dst, 0o755))
entries, err := os.ReadDir(src)
Debug()
must(err)
for _, entry := range entries {
srcPath := filepath.Join(src, entry.Name())
@@ -165,7 +179,7 @@ func (s StarterCreator) copyDirectoryRecursive(src string, dst string) {
Debug("copying srcPath: ", srcPath, " to dstPath: ", dstPath)
if entry.IsDir() {
s.copyDirectoryRecursive(srcPath, dstPath)
return
continue
}
content, err := os.ReadFile(srcPath)
content = s.replaceImports(content)