3
0

Reimplement doc-generator for options

This commit is contained in:
Denis Arh
2022-03-18 09:30:26 +01:00
parent 9b5586719e
commit 4437627eb3
4 changed files with 53 additions and 106 deletions

View File

@@ -4,15 +4,20 @@ DEF_ALL = *.cue
DEF_SERVER = server.*.cue
DEF_DOCS = docs.*.cue
all: $(DEF_ALL)
server: $(DEF_SERVER)
docs: $(DEF_DOCS)
all: $(DEF_SERVER) $(DEF_DOCS)
include ../Makefile.inc
$(DEF_ALL): $(CUE) $(JSONTPLEXEC)
@ echo "$(COLOUR_GREEN)Generating from $@$(COLOUR_END)"
@ $(CUE) eval $@ --out json | $(JSONTPLEXEC) -v -p ../codegen/assets/templates -b ../
$(DEF_SERVER): $(CUE) $(JSONTPLEXEC)
@ echo "$(COLOUR_GREEN)Generating server files from $@$(COLOUR_END)"
@ $(CUE) eval $@ --out json | $(JSONTPLEXEC) -v -p $(ROOT_DIR)/codegen/assets/templates -b $(ROOT_DIR)
$(DEF_DOCS): $(CUE) $(JSONTPLEXEC)
@[ "${DOCS_DIR}" ] || ( echo "DOCS_DIR is not set, run make like this: make docs DOCS_DIR=/path/to/corteza-docs"; exit 1 )
@ echo "$(COLOUR_GREEN)Generating doc files from $@$(COLOUR_END) $(COLOUR_BLUE)(dst: $(DOCS_DIR))$(COLOUR_END)"
@ $(CUE) eval $@ --out json | $(JSONTPLEXEC) -v -p $(ROOT_DIR)/codegen/assets/templates -b $(DOCS_DIR)
gen:
@ rm $(JSONTPLEXEC)

View File

@@ -0,0 +1,39 @@
//
// This file is auto-generated.
//
include::ROOT:partial$variables.adoc[]
{{- range .groups }}
= {{ .title }}
{{- if .intro }}
{{ .intro }}
#
{{ end -}}
{{ range .options }}
== *{{ .env }}*
=== Type
`{{ .type }}`
{{ if .defaultValue }}
=== Default
[source]
----
{{ .defaultValue }}
----
{{- end }}
{{- if .description }}
=== Description
{{ .description }}
{{- end }}
{{- end }}
{{- end }}

View File

@@ -1,39 +0,0 @@
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
{{- range .Definitions }}
// - {{ .Source }}
{{- end }}
include::ROOT:partial$variables.adoc[]
{{ range .Definitions }}
= {{ .Docs.Title }}
{{ if .Docs.Intro }}
{{ .Docs.Intro }}
{{ end }}
{{- range .Properties }}
== *{{ toUpper .Env }}*
=== Type
`{{ .Type }}`
{{ if or .Default .Description -}}
{{ if .Default -}}
=== Default
[source]
----
{{ .Default }}
----
{{ end -}}
{{ if .Description -}}
=== Description
{{ .Description }}
{{ end -}}{{ end -}}
{{ end }}{{ end }}

View File

@@ -1,7 +1,6 @@
package codegen
import (
"strings"
"github.com/cortezaproject/corteza-server/app"
"github.com/cortezaproject/corteza-server/codegen/schema"
)
@@ -9,72 +8,15 @@ import (
[...schema.#codegen] &
[
{
template: "gocode/options/options.go.tpl"
output: "pkg/options/options.gen.go"
payload: {
package: "options"
// make unique list of packages we'll import
imports: [ for i in {for g in app.corteza.options for i in g.imports {"\(i)": i}} {i}]
groups: [
for g in app.corteza.options {
func: g.expIdent
struct: g.expIdent + "Opt"
options: [
for o in g.options {
o
default?: string
if (o.defaultGoExpr != _|_) {
default: o.defaultGoExpr
}
if (o.defaultGoExpr == _|_ && o.defaultValue != _|_) {
default: "\"" + o.defaultValue + "\""
}
},
]
},
]
}
},
]+
[
{
template: "docs/.env.example.tpl"
output: ".env.example"
syntax: ".env"
template: "docs/options.adoc.tpl"
output: "src/modules/generated/partials/env-options.gen.adoc"
payload: {
groups: [
for g in app.corteza.options {
title: "# " + strings.Join(strings.Split(g.title, "\n"), "\n# ")
title: g.title
intro?: g.intro
if (g.intro != _|_) {
intro: "# " + strings.Join(strings.Split(g.intro, "\n"), "\n# ")
}
options: [
for o in g.options {
handle: o.handle
env: o.env
type: o.type
defaultGoExpr?: string
if (o.defaultGoExpr != _|_) {
defaultGoExpr: o.defaultGoExpr
}
defaultValue?: string
if (o.defaultValue != _|_) {
defaultValue: o.defaultValue
}
if (o.description != _|_) {
description: "# " + strings.Join(strings.Split(o.description, "\n"), "\n# ")
}
},
]
options: g.options
},
]
}