This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (61 loc) · 1.51 KB
/
main.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
67
68
69
70
71
72
73
package main
import (
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"
)
type Icon struct {
Name string
Value string
}
func main() {
var icons []Icon
removeNewlines := regexp.MustCompile(`\r?\n`)
stripDoctype := regexp.MustCompile(`<\?xml.*><\!DOCTYPE.*><svg`)
iconNames := readIconNames("./icons.txt")
for _, v := range iconNames {
if v == "" {
continue
}
iconContent, err := ioutil.ReadFile(filepath.Join("MaterialDesign", "icons", "svg", v+".svg"))
if err != nil {
log.Fatalf("Could not read icon %s: %v\n", v, err)
return
}
iconContentString := string(iconContent)
iconContentString = removeNewlines.ReplaceAllString(iconContentString, "")
iconContentString = stripDoctype.ReplaceAllString(iconContentString, "<svg")
icons = append(icons, Icon{
Name: v,
// THE first three bytes are the BOM, which we need to skip
Value: iconContentString[3:],
})
}
applyIconsToTemplate(icons)
}
func readIconNames(path string) []string {
icns, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("Could not open icon list file: %v", err)
return nil
}
iconList := strings.Split(string(icns), "\n")
return iconList
}
func applyIconsToTemplate(icons []Icon) {
tmpl := template.Must(template.ParseFiles("./template.ts"))
f, err := os.Create("icons.ts")
if err != nil {
log.Fatalf("Could not open output file: %v\n", err)
return
}
err = tmpl.Execute(f, icons)
if err != nil {
log.Fatalf("Could not execute template: %v\n", err)
}
f.Close()
}