mirror of
https://github.com/thegeeklab/wp-plugin-go.git
synced 2024-11-22 00:20:38 +00:00
feat: add sprig template functions to docs helper (#41)
This commit is contained in:
parent
4d62198740
commit
5e20ca049e
63
Makefile
63
Makefile
@ -3,54 +3,15 @@ GOFUMPT_PACKAGE_VERSION := v0.5.0
|
|||||||
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
||||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.55.2
|
GOLANGCI_LINT_PACKAGE_VERSION := v1.55.2
|
||||||
|
|
||||||
EXECUTABLE := wp-plugin-go
|
|
||||||
|
|
||||||
DIST := dist
|
|
||||||
DIST_DIRS := $(DIST)
|
|
||||||
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
|
|
||||||
|
|
||||||
GO ?= go
|
GO ?= go
|
||||||
CWD ?= $(shell pwd)
|
|
||||||
PACKAGES ?= $(shell go list ./...)
|
PACKAGES ?= $(shell go list ./...)
|
||||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||||
|
|
||||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
||||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
|
||||||
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
||||||
|
|
||||||
GENERATE ?=
|
GENERATE ?=
|
||||||
XGO_VERSION := go-1.21.x
|
|
||||||
XGO_TARGETS ?= linux/amd64,linux/arm64,linux/arm-6,linux/arm-7
|
|
||||||
|
|
||||||
TARGETOS ?= linux
|
|
||||||
TARGETARCH ?= amd64
|
|
||||||
ifneq ("$(TARGETVARIANT)","")
|
|
||||||
GOARM ?= $(subst v,,$(TARGETVARIANT))
|
|
||||||
endif
|
|
||||||
TAGS ?= netgo
|
|
||||||
|
|
||||||
ifndef VERSION
|
|
||||||
ifneq ($(CI_COMMIT_TAG),)
|
|
||||||
VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
|
|
||||||
else
|
|
||||||
VERSION ?= $(shell git rev-parse --short HEAD)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef DATE
|
|
||||||
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
|
|
||||||
endif
|
|
||||||
|
|
||||||
LDFLAGS += -s -w -X "main.BuildVersion=$(VERSION)" -X "main.BuildDate=$(DATE)"
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: clean build
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
$(GO) clean -i ./...
|
|
||||||
rm -rf $(DIST_DIRS)
|
|
||||||
|
|
||||||
.PHONY: fmt
|
.PHONY: fmt
|
||||||
fmt:
|
fmt:
|
||||||
@ -71,33 +32,9 @@ generate:
|
|||||||
test:
|
test:
|
||||||
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build: $(DIST)/$(EXECUTABLE)
|
|
||||||
|
|
||||||
$(DIST)/$(EXECUTABLE): $(SOURCES)
|
|
||||||
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
|
|
||||||
|
|
||||||
$(DIST_DIRS):
|
|
||||||
mkdir -p $(DIST_DIRS)
|
|
||||||
|
|
||||||
.PHONY: xgo
|
|
||||||
xgo: | $(DIST_DIRS)
|
|
||||||
$(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
|
|
||||||
cp /build/* $(CWD)/$(DIST)
|
|
||||||
ls -l $(CWD)/$(DIST)
|
|
||||||
|
|
||||||
.PHONY: checksum
|
|
||||||
checksum:
|
|
||||||
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
|
||||||
ls -l $(CWD)/$(DIST)
|
|
||||||
|
|
||||||
.PHONY: release
|
|
||||||
release: xgo checksum
|
|
||||||
|
|
||||||
.PHONY: deps
|
.PHONY: deps
|
||||||
deps:
|
deps:
|
||||||
$(GO) mod download
|
$(GO) mod download
|
||||||
$(GO) install $(GOFUMPT_PACKAGE)
|
$(GO) install $(GOFUMPT_PACKAGE)
|
||||||
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
||||||
$(GO) install $(XGO_PACKAGE)
|
|
||||||
$(GO) install $(GOTESTSUM_PACKAGE)
|
$(GO) install $(GOTESTSUM_PACKAGE)
|
||||||
|
@ -7,6 +7,8 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
wp_template "github.com/thegeeklab/wp-plugin-go/template"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +36,7 @@ var templateFs embed.FS
|
|||||||
func ToMarkdown(app *cli.App) (string, error) {
|
func ToMarkdown(app *cli.App) (string, error) {
|
||||||
var w bytes.Buffer
|
var w bytes.Buffer
|
||||||
|
|
||||||
tpls, err := template.New("cli").ParseFS(templateFs, "**/*.tmpl")
|
tpls, err := template.New("cli").Funcs(wp_template.LoadFuncMap()).ParseFS(templateFs, "**/*.tmpl")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/Masterminds/sprig/v3"
|
"github.com/Masterminds/sprig/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadFuncMap() template.FuncMap {
|
func LoadFuncMap() template.FuncMap {
|
||||||
sprigFuncs := sprig.GenericFuncMap()
|
sprigFuncs := sprig.GenericFuncMap()
|
||||||
customFuncs := template.FuncMap{}
|
customFuncs := template.FuncMap{}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
func Render(ctx context.Context, client http.Client, templateString string, payload interface{}) (string, error) {
|
func Render(ctx context.Context, client http.Client, templateString string, payload interface{}) (string, error) {
|
||||||
var outString bytes.Buffer
|
var outString bytes.Buffer
|
||||||
|
|
||||||
tpl := new(template.Template).Funcs(loadFuncMap())
|
tpl := new(template.Template).Funcs(LoadFuncMap())
|
||||||
|
|
||||||
templateURL, err := url.Parse(templateString)
|
templateURL, err := url.Parse(templateString)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user