-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
build.go
66 lines (53 loc) · 1.35 KB
/
build.go
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
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
)
func main() {
// Read directory contents
iconsDir, err := os.ReadDir("./assets")
if err != nil {
panic(err)
}
// Initialize map for icons
icons := make(map[string]string)
// Iterate through directory contents
for _, fileInfo := range iconsDir {
if !fileInfo.IsDir() {
// Read file contents
data, err := os.ReadFile("./assets/" + fileInfo.Name())
if err != nil {
panic(err)
}
// Add file content to map
name := strings.TrimSuffix(strings.ToLower(fileInfo.Name()), ".svg")
icons[name] = string(data)
}
}
// Convert icons to JSON
iconsJSON, err := json.Marshal(icons)
if err != nil {
panic(err)
}
// Read content of api/index.go
indexFile, err := os.ReadFile("./api/index.go")
if err != nil {
panic(err)
}
// Convert content to string
indexContent := string(indexFile)
// Split the content by newlines
lines := strings.Split(indexContent, "\n")
// Insert the iconsJSON into line 18
lines[17] = fmt.Sprintf("\n\tvar iconsJSON = `%s`\n", iconsJSON)
// Join the lines back into a single string
modifiedContent := strings.Join(lines, "\n")
// Write the modified content back to the file
err = os.WriteFile("./api/index.go", []byte(modifiedContent), 0644)
if err != nil {
panic(err)
}
fmt.Println("Modified content saved to api/index.go")
}