// Command gen builds simple-icons.json.gz, the icon data the icons package // embeds. It downloads the pinned simple-icons npm tarball, checks its // sha256 and writes a gzipped JSON object {slug: svg path data}. The output // is deterministic. It writes into the current directory; run it with // // go generate ./internal/master/web/icons package main import ( "archive/tar" "bytes" "compress/gzip" "crypto/sha256" "encoding/hex" "encoding/json" "fmt" "io" "net/http" "os" "path" "regexp" "strings" ) const ( tarballURL = "https://registry.npmjs.org/simple-icons/-/simple-icons-16.35.0.tgz" tarballSHA256 = "20ebead4f6bc93464812a5e260d19fc4d84772e5eeff69a6fbea263ca2441c5f" ) var pathData = regexp.MustCompile(`, found %d", h.Name, len(m)) } icons[strings.TrimSuffix(path.Base(h.Name), ".svg")] = string(m[0][1]) } } if license == nil || len(icons) == 0 { return nil, nil, fmt.Errorf("tarball has no LICENSE.md or no icons") } return icons, license, nil }