mirror of
https://github.com/onyx-and-iris/gignore.git
synced 2025-04-01 19:23:51 +01:00
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Package main generates gitignore.io templates using the gogi library.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/cuonglm/gogi"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func main() {
|
|
log.Info("Generating gitignore.io templates...")
|
|
|
|
gogiClient, _ := gogi.NewHTTPClient()
|
|
|
|
templates, err := fetchTemplates(gogiClient)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
for _, template := range templates {
|
|
err := createTemplate(template)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to create template %s: %v\n", template.Name, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func fetchTemplates(gogiClient *gogi.Client) (map[string]*gogi.ListJsonItem, error) {
|
|
data, err := gogiClient.ListJson()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return data, nil
|
|
}
|
|
|
|
func createTemplate(template *gogi.ListJsonItem) error {
|
|
file, err := os.Create(
|
|
fmt.Sprintf("internal/registry/templates/gitignoreio/%s.gitignore", strings.ToLower(template.Name)),
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer file.Close()
|
|
|
|
_, err = file.Write([]byte(template.Contents))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|