Skip to content

Commit

Permalink
build: avoid duplicate schema destination processing
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Jun 26, 2024
1 parent 5a81b2e commit ed99d44
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions magefiles/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ func (Build) Ts(schema string) error {

ensureTsCodegen()

name := strings.TrimPrefix(schema, "axone-")
dest := filepath.Join(TS_DIR, fmt.Sprintf("%s-schema", name))
name, dest := schemaDestination(schema)

err := sh.Run("ts-codegen", "generate",
"--schema", filepath.Join(SCHEMA_DIR, schema),
Expand All @@ -51,8 +50,8 @@ func (Build) Ts(schema string) error {
func (Build) Go(schema string) error {
fmt.Printf("⚙️ Generate go types for %s\n", schema)

name := strings.TrimPrefix(schema, "axone-")
dest := filepath.Join(GO_DIR, fmt.Sprintf("%s-schema", name))
_, dest := schemaDestination(schema)

if err := os.MkdirAll(dest, os.ModePerm); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
Expand All @@ -74,8 +73,13 @@ type Clean mg.Namespace
func (Clean) Ts(schema string) error {
fmt.Printf("🧹 Cleaning generated typescript files for %s\n", schema)

name := strings.TrimPrefix(schema, "axone-")
dest := filepath.Join(TS_DIR, fmt.Sprintf("%s-schema", name))
_, dest := schemaDestination(schema)

return sh.Run("yarn", "--cwd", dest, "clean")
}

func schemaDestination(schema string) (name string, destination string) {
name = strings.TrimPrefix(schema, "axone-")
destination = filepath.Join(TS_DIR, fmt.Sprintf("%s-schema", name))
return
}

0 comments on commit ed99d44

Please sign in to comment.