-
Notifications
You must be signed in to change notification settings - Fork 3
/
update.go
120 lines (95 loc) · 2.21 KB
/
update.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"bufio"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"regexp"
"strings"
)
const (
header = `<resources>
<string name="app_name">Font Awesome</string>
`
footer = `</resources>
`
)
func main() {
version := getVersion()
updateStringsResource(version)
updateFontFile()
}
type version struct {
Version string `json:"version"`
}
func getVersion() string {
res, err := http.Get("https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/package.json")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
var data version
if err := json.NewDecoder(res.Body).Decode(&data); err != nil {
log.Fatal(err)
}
return data.Version
}
func updateStringsResource(version string) {
output, err := os.Create("./fontawesome/src/main/res/values/strings.xml")
if err != nil {
log.Fatal(err)
}
defer output.Close()
fmt.Fprint(output, header)
fmt.Fprintf(output, " <!-- Font Awesome v%s -->\n", version)
printFontResources(output)
fmt.Fprint(output, footer)
}
func printFontResources(w io.Writer) {
res, err := http.Get("https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/src/icons.yml")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
var id, code string
scanner := bufio.NewScanner(res.Body)
for scanner.Scan() {
line := scanner.Text()
reID := regexp.MustCompile(`\s+id:\s+(.*)`)
matchID := reID.FindStringSubmatch(line)
if len(matchID) > 0 {
id = matchID[1]
}
reCode := regexp.MustCompile(`\s+unicode:\s+(.*)`)
matchCode := reCode.FindStringSubmatch(line)
if len(matchCode) > 0 {
code = matchCode[1]
if id != "" {
id = strings.Replace(id, "-", "_", -1)
fmt.Fprintf(w, " <string name=\"fa_%s\">&#x%s;</string>\n", id, code)
id = ""
}
}
}
}
func updateFontFile() {
res, err := http.Get("https://github.com/FortAwesome/Font-Awesome/blob/master/fonts/fontawesome-webfont.ttf?raw=true")
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
output, err := os.Create("./fontawesome/src/main/assets/fontawesome-webfont.ttf")
if err != nil {
log.Fatal(err)
}
defer output.Close()
output.Write(body)
}