1
.profile/scripts/gen-readme/main.go

135 lines
2.5 KiB
Go
Raw Normal View History

// Copyright (C) 2023 The Licensing Authors
// SPDX-License-Identifier: MIT
package main
import (
"flag"
"os"
"text/template"
"github.com/Masterminds/sprig/v3"
)
const readme = `
{{- $gitea := .BaseURL.Gitea -}}
{{- $woodpecker := .BaseURL.Woodpecker -}}
<br/>
<br/>
<h3 align="center"> Libraries </h3>
<div align="center">
| Language | Repository | Build Pipeline |
|----------|------------|----------------|
{{- range .Libraries }}
| {{ .Language }} | [{{ .Repository }}]({{ $gitea }}/{{ .Repository }}) | [![status-badge]({{ $woodpecker }}/api/badges/{{ .Build }}/status.svg)]({{ $woodpecker }}/repos/{{ .Build }}) |
{{- end }}
</div>
<br/>
<h3 align="center"> Tools and Technologies </h3>
<p align="center">
{{- range .Tools }}
{{- range . }}
<img width="96" height="64" alt="{{ .Name }}" title="{{ .Name }}" src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/{{ .Devicon }}.svg" />&nbsp;
{{- end }}
<br/>
{{- end }}
</p>
2023-12-31 17:13:50 +00:00
<br/>
<br/>
`
type BaseURL struct {
Gitea string
Woodpecker string
}
type Library struct {
Language string
Repository string
Build string
}
type Tool struct {
Name string
Devicon string
}
type TemplateData struct {
BaseURL BaseURL
Libraries []Library
Tools [][]Tool
}
func main() {
cli := flag.NewFlagSet("gen-readme", flag.ExitOnError)
cli.SetOutput(os.Stderr)
output := cli.String("", "-", "")
err := cli.Parse(os.Args[1:])
if err != nil {
panic(err)
}
out := os.Stdout
if output != nil && *output != "" && *output != "-" {
out, err = os.Create(*output)
if err != nil {
panic(err)
}
defer out.Close()
}
t := template.Must(
template.New("readme").
Funcs(sprig.TxtFuncMap()).
Parse(readme),
)
err = t.Execute(out, TemplateData{
BaseURL: BaseURL{
Gitea: "https://code.pitz.tech",
Woodpecker: "https://build.pitz.tech",
},
Libraries: []Library{
{"Protobuf", "licensing/proto", "1"},
{"Golang", "licensing/api-go", "2"},
{"Rust", "licensing/api-rust", ""},
{"NodeJS", "licensing/api-node", ""},
},
Tools: [][]Tool{
{
{"Git", "git/git-plain"},
},
{
{"Go", "go/go-original"},
{"Rust", "rust/rust-plain"},
{"NodeJS", "nodejs/nodejs-original"},
{"TypeScript", "typescript/typescript-original"},
},
{
{"SQLite", "sqlite/sqlite-original"},
{"PostgreSQL", "postgresql/postgresql-original"},
{"Redis", "redis/redis-original"},
},
{
{"Prometheus", "prometheus/prometheus-original"},
{"Grafana", "grafana/grafana-original"},
},
},
})
if err != nil {
panic(err)
}
}