mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: add icons.json file (#10085)
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func generateIconList(path string) int {
|
||||
if path == "" {
|
||||
return 0 // skip
|
||||
}
|
||||
|
||||
files, err := os.ReadDir("site/static/icon/")
|
||||
if err != nil {
|
||||
_, _ = fmt.Println("failed to read site/static/icon/ directory")
|
||||
_, _ = fmt.Println("err:", err.Error())
|
||||
return 71 // OSERR
|
||||
}
|
||||
|
||||
icons := make([]string, len(files))
|
||||
i := 0
|
||||
for _, file := range files {
|
||||
if !file.Type().IsRegular() {
|
||||
continue
|
||||
}
|
||||
|
||||
icons[i] = file.Name()
|
||||
i++
|
||||
}
|
||||
icons = icons[:i]
|
||||
|
||||
outputFile, err := os.Create(path)
|
||||
if err != nil {
|
||||
_, _ = fmt.Println("failed to create file")
|
||||
_, _ = fmt.Println("err:", err.Error())
|
||||
return 73 // CANTCREAT
|
||||
}
|
||||
defer outputFile.Close()
|
||||
|
||||
iconsJSON, err := json.Marshal(icons)
|
||||
if err != nil {
|
||||
_, _ = fmt.Println("failed to serialize JSON")
|
||||
_, _ = fmt.Println("err:", err.Error())
|
||||
return 70 // SOFTWARE
|
||||
}
|
||||
|
||||
written, err := outputFile.Write(iconsJSON)
|
||||
if err != nil || written != len(iconsJSON) {
|
||||
_, _ = fmt.Println("failed to write JSON")
|
||||
if err != nil {
|
||||
_, _ = fmt.Println("err:", err.Error())
|
||||
}
|
||||
return 74 // IOERR
|
||||
}
|
||||
|
||||
_, _ = fmt.Println(green.Sprintf("==>"), path)
|
||||
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
var green = color.New(color.FgGreen).Add(color.Bold)
|
||||
|
||||
func main() {
|
||||
var iconsPath string
|
||||
flag.StringVar(&iconsPath, "icons", "", "the path to place icons.json at")
|
||||
flag.Parse()
|
||||
|
||||
status := generateIconList(iconsPath)
|
||||
os.Exit(status)
|
||||
}
|
||||
Reference in New Issue
Block a user