Skip to content

Commit bd4d007

Browse files
committed
chore: use os.CopyFS when possible
1 parent 0384f27 commit bd4d007

File tree

1 file changed

+5
-24
lines changed
  • scripts/website/copy_jsonschema

1 file changed

+5
-24
lines changed

scripts/website/copy_jsonschema/main.go

+5-24
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88
"path/filepath"
9-
"strings"
109

1110
hcversion "github.com/hashicorp/go-version"
1211

@@ -28,24 +27,9 @@ func copySchemas() error {
2827
return fmt.Errorf("remove dir: %w", err)
2928
}
3029

31-
err = os.MkdirAll(dstDir, os.ModePerm)
30+
err = os.CopyFS(dstDir, os.DirFS("jsonschema"))
3231
if err != nil {
33-
return fmt.Errorf("make dir: %w", err)
34-
}
35-
36-
// The key is the destination file.
37-
// The value is the source file.
38-
files := map[string]string{}
39-
40-
entries, err := os.ReadDir("jsonschema")
41-
if err != nil {
42-
return fmt.Errorf("read dir: %w", err)
43-
}
44-
45-
for _, entry := range entries {
46-
if strings.HasSuffix(entry.Name(), ".jsonschema.json") {
47-
files[entry.Name()] = entry.Name()
48-
}
32+
return fmt.Errorf("copy FS: %w", err)
4933
}
5034

5135
latest, err := github.GetLatestVersion()
@@ -59,13 +43,10 @@ func copySchemas() error {
5943
}
6044

6145
versioned := fmt.Sprintf("golangci.v%d.%d.jsonschema.json", version.Segments()[0], version.Segments()[1])
62-
files[versioned] = "golangci.jsonschema.json"
6346

64-
for dst, src := range files {
65-
err := copyFile(filepath.Join("jsonschema", src), filepath.Join(dstDir, dst))
66-
if err != nil {
67-
return fmt.Errorf("copy files: %w", err)
68-
}
47+
err = copyFile(filepath.FromSlash("jsonschema/golangci.jsonschema.json"), filepath.Join(dstDir, versioned))
48+
if err != nil {
49+
return fmt.Errorf("copy files: %w", err)
6950
}
7051

7152
return nil

0 commit comments

Comments
 (0)