forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (72 loc) · 2.16 KB
/
main.go
File metadata and controls
88 lines (72 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"bytes"
"flag"
"fmt"
"io/fs"
"log"
"os"
"path/filepath"
"strings"
)
func main() {
flag.Parse()
// Assume it exists
loc := flag.Arg(0)
dir := filepath.Join("internal", "codegen", "golang")
err := filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
contents, err := os.ReadFile(path)
if err != nil {
return err
}
newdir := filepath.Join(loc, "internal")
newpath := strings.Replace(path, dir, newdir, 1)
os.MkdirAll(filepath.Dir(newpath), 0755)
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"`),
[]byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/opts"`))
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/plugin"`),
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/plugin"`))
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/codegen/sdk"`),
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/sdk"`))
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/metadata"`),
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/metadata"`))
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/pattern"`),
[]byte(`"github.com/sqlc-dev/plugin-sdk-go/pattern"`))
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/debug"`),
[]byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/debug"`))
contents = bytes.ReplaceAll(contents,
[]byte(`"github.com/sqlc-dev/sqlc/internal/inflection"`),
[]byte(`"github.com/sqlc-dev/sqlc-gen-go/internal/inflection"`))
if err := os.WriteFile(newpath, contents, 0644); err != nil {
return err
}
return nil
})
if err != nil {
fmt.Printf("error walking the path: %v\n", err)
return
}
{
path := filepath.Join("internal", "inflection", "singular.go")
contents, err := os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
newpath := filepath.Join(loc, "internal", "inflection", "singular.go")
if err := os.WriteFile(newpath, contents, 0644); err != nil {
log.Fatal(err)
}
}
}