Continuing the starter kit
This commit is contained in:
@@ -20,6 +20,8 @@ const (
|
||||
type Params struct {
|
||||
DbType DatabaseType
|
||||
ProjectDir string
|
||||
ModuleName string
|
||||
GoPath string
|
||||
}
|
||||
|
||||
type StarterCreator struct {
|
||||
@@ -74,6 +76,9 @@ func (s StarterCreator) Create() {
|
||||
|
||||
s.copyFile("../go.work.template", "go.work")
|
||||
s.copyFile("../../template.air.toml", ".air.toml")
|
||||
//s.copyGoMod()
|
||||
//s.executeGoModTidy()
|
||||
s.executeGetPrismaClient()
|
||||
|
||||
if s.params.DbType == DataBaseTypeSqlite {
|
||||
must(os.MkdirAll(filepath.Join(s.params.ProjectDir, "db"), 0o755))
|
||||
@@ -83,6 +88,12 @@ func (s StarterCreator) Create() {
|
||||
must(os.MkdirAll(filepath.Join(s.params.ProjectDir, "scripts"), 0o755))
|
||||
s.copyFile("../../scripts/db-push.sh", "scripts/db-push.sh")
|
||||
|
||||
if s.params.DbType == DataBaseTypeSqlite {
|
||||
s.executeDbPush()
|
||||
}
|
||||
}
|
||||
|
||||
func (s StarterCreator) executeDbPush() {
|
||||
// After copying create_db.sh, run it with the project directory as the root
|
||||
scriptPath := filepath.Join(s.params.ProjectDir, "scripts", "db-push.sh")
|
||||
if runtime.GOOS == "windows" {
|
||||
@@ -131,12 +142,51 @@ func (s StarterCreator) copySchema() {
|
||||
sqliteBlock := "datasource db {\n provider = \"sqlite\"\n url = \"file:./db/sqlite.db\"\n}\n"
|
||||
contentStr := string(content)
|
||||
contentStr = strings.Replace(contentStr, pgBlock, sqliteBlock, 1)
|
||||
contentStr = strings.ReplaceAll(contentStr, " @db.Timestamptz(3)", "")
|
||||
contentStr = strings.ReplaceAll(contentStr, " @db.Timestamp(6)", "")
|
||||
content = []byte(contentStr)
|
||||
}
|
||||
|
||||
must(os.WriteFile(filepath.Join(s.params.ProjectDir, "schema.prisma"), content, 0o644))
|
||||
}
|
||||
|
||||
func (s StarterCreator) copyGoMod() {
|
||||
content, err := os.ReadFile(filepath.Join(s.thisDir, "../go.mod.template"))
|
||||
must(err)
|
||||
contentString := InlineTemplate(string(content), struct {
|
||||
ModuleName string
|
||||
}{
|
||||
ModuleName: s.params.ModuleName,
|
||||
})
|
||||
must(os.WriteFile(filepath.Join(s.params.ProjectDir, "go.mod"), []byte(contentString), 0o644))
|
||||
}
|
||||
|
||||
func (s StarterCreator) executeGoModTidy() {
|
||||
goCommand := s.getGoCommand()
|
||||
cmd := exec.Command(goCommand, "mod", "tidy")
|
||||
cmd.Dir = s.params.ProjectDir
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
must(cmd.Run())
|
||||
}
|
||||
|
||||
func (s StarterCreator) getGoCommand() string {
|
||||
goCommand := "go"
|
||||
if s.params.GoPath != "" {
|
||||
goCommand = s.params.GoPath
|
||||
}
|
||||
return goCommand
|
||||
}
|
||||
|
||||
func (s StarterCreator) executeGetPrismaClient() {
|
||||
goCommand := s.getGoCommand()
|
||||
cmd := exec.Command(goCommand, "get", "github.com/steebchen/prisma-client-go")
|
||||
cmd.Dir = s.params.ProjectDir
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
must(cmd.Run())
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
Reference in New Issue
Block a user