Skip to content

Commit 76eea90

Browse files
authored
tools: regenerate scripts skips dirs that contains diff exec command (#1987)
1 parent 7bc053e commit 76eea90

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

scripts/regenerate/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"log"
67
"os"
@@ -9,6 +10,27 @@ import (
910
"strings"
1011
)
1112

13+
func parseExecCommand(path string) (string, error) {
14+
var exec = struct {
15+
Command string `json:"command"`
16+
}{
17+
Command: "generate",
18+
}
19+
20+
execJsonPath := filepath.Join(path, "exec.json")
21+
if _, err := os.Stat(execJsonPath); !os.IsNotExist(err) {
22+
blob, err := os.ReadFile(execJsonPath)
23+
if err != nil {
24+
return "", err
25+
}
26+
if err := json.Unmarshal(blob, &exec); err != nil {
27+
return "", err
28+
}
29+
}
30+
31+
return exec.Command, nil
32+
}
33+
1234
func regenerate(dir string) error {
1335
return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
1436
if err != nil {
@@ -19,6 +41,15 @@ func regenerate(dir string) error {
1941
}
2042
if strings.HasSuffix(path, "sqlc.json") || strings.HasSuffix(path, "sqlc.yaml") {
2143
cwd := filepath.Dir(path)
44+
command, err := parseExecCommand(cwd)
45+
if err != nil {
46+
return fmt.Errorf("failed to parse exec.json: %w", err)
47+
}
48+
49+
if command != "generate" {
50+
return nil
51+
}
52+
2253
cmd := exec.Command("sqlc-dev", "generate", "--experimental")
2354
cmd.Dir = cwd
2455
out, failed := cmd.CombinedOutput()

0 commit comments

Comments
 (0)