mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Embed types-dnscontrol.d.ts into the binary instead of fetching it via HTTP (#1942)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -24,6 +24,6 @@ stack.sh
|
||||
.DS_Store
|
||||
.vscode/launch.json
|
||||
.jekyll-cache
|
||||
/dnscontrol.d.ts
|
||||
types-dnscontrol.d.ts
|
||||
|
||||
dist/
|
||||
|
@@ -16,13 +16,13 @@ func generateDTSFile(funcs string) error {
|
||||
"// WARNING: These type definitions are experimental and subject to change in future releases.",
|
||||
}
|
||||
for _, name := range names {
|
||||
content, err := os.ReadFile(join("types", "src", name+".d.ts"))
|
||||
content, err := os.ReadFile(join("commands", "types", name+".d.ts"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
combined = append(combined, string(content))
|
||||
}
|
||||
combined = append(combined, funcs)
|
||||
os.WriteFile(join("types", "dnscontrol.d.ts"), []byte(strings.Join(combined, "\n\n")), 0644)
|
||||
os.WriteFile(join("commands", "types", "dnscontrol.d.ts"), []byte(strings.Join(combined, "\n\n")), 0644)
|
||||
return nil
|
||||
}
|
||||
|
@@ -1,10 +1,8 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
_ "embed"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
versionInfo "github.com/StackExchange/dnscontrol/v3/pkg/version"
|
||||
"github.com/urfave/cli/v2"
|
||||
@@ -39,17 +37,10 @@ func (args *TypesArgs) flags() []cli.Flag {
|
||||
return flags
|
||||
}
|
||||
|
||||
//go:embed types/dnscontrol.d.ts
|
||||
var dtsContent string
|
||||
|
||||
func WriteTypes(args TypesArgs) error {
|
||||
url := "https://raw.githubusercontent.com/StackExchange/dnscontrol/" + strings.Replace(versionInfo.SHA, "[dirty]", "", 1) + "/types/dnscontrol.d.ts"
|
||||
print("Downloading " + url + " to " + args.DTSFile + "...")
|
||||
defer print("\n")
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
file, err := os.Create(args.DTSFile)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -59,12 +50,11 @@ func WriteTypes(args TypesArgs) error {
|
||||
file.WriteString("// This file was automatically generated by DNSControl. Do not edit it directly.\n")
|
||||
file.WriteString("// To update it, run `dnscontrol write-types`.\n\n")
|
||||
file.WriteString("// DNSControl version: " + versionInfo.Banner() + "\n")
|
||||
file.WriteString("// Source: " + url + "\n\n")
|
||||
_, err = io.Copy(file, resp.Body)
|
||||
file.WriteString(dtsContent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
print(" done.")
|
||||
print("Successfully wrote " + args.DTSFile + "\n")
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user