Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BUILD_PATH=./bin
GOLANGCI_LINT=$(BUILD_PATH)/golangci-lint
GOLANGCI_LINT_VERSION=v2.1.6

.PHONY: build clean test lint examples help docker
.PHONY: build clean test lint examples single-page-mermaid-examples help docker

build: ## build app
$(GO) build -o $(BUILD_PATH)/messageflow ./cmd/messageflow
Expand Down Expand Up @@ -32,6 +32,12 @@ examples: ## create examples
--asyncapi-files pkg/schema/source/asyncapi/testdata/analytics_ver2.yaml,pkg/schema/source/asyncapi/testdata/campaign.yaml,pkg/schema/source/asyncapi/testdata/notification.yaml,pkg/schema/source/asyncapi/testdata/user.yaml \
--output examples/docs

single-page-mermaid-examples: ## create single page mermaid examples
$(GO) run cmd/messageflow/main.go gen-docs \
--asyncapi-files pkg/schema/source/asyncapi/testdata/analytics.yaml,pkg/schema/source/asyncapi/testdata/campaign.yaml,pkg/schema/source/asyncapi/testdata/notification.yaml,pkg/schema/source/asyncapi/testdata/user.yaml \
--output examples/single-page-mermaid-docs \
--format mermaid

$(GOLANGCI_LINT): ## install local golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh | sh -s -- -b $(BUILD_PATH) $(GOLANGCI_LINT_VERSION)

Expand Down
31 changes: 27 additions & 4 deletions cmd/messageflow/commands/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"strings"

"github.com/holydocs/messageflow/internal/docs"
"github.com/holydocs/messageflow/pkg/messageflow"
"github.com/holydocs/messageflow/pkg/schema"
"github.com/holydocs/messageflow/pkg/schema/target/d2"
"github.com/holydocs/messageflow/pkg/schema/target/mermaid"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
)
Expand All @@ -36,6 +38,7 @@ Example:
c.cmd.Flags().String("asyncapi-files", "", "Paths to asyncapi files separated by comma")
c.cmd.Flags().String("output", ".", "Output directory for generated documentation")
c.cmd.Flags().String("title", "Message Flow", "Title of the documentation")
c.cmd.Flags().String("format", "d2", "Diagram format: d2 or mermaid (default: d2)")

return c
}
Expand Down Expand Up @@ -65,19 +68,39 @@ func (c *Command) run(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("error creating output directory %s: %w", outputDir, err)
}

format, err := cmd.Flags().GetString("format")
if err != nil {
return fmt.Errorf("error getting format flag: %w", err)
}

if format != "d2" && format != "mermaid" {
return fmt.Errorf("invalid format: %s (must be 'd2' or 'mermaid')", format)
}

ctx := context.Background()

s, err := schema.Load(ctx, asyncAPIFilesPaths)
if err != nil {
return fmt.Errorf("error loading schema from files: %w", err)
}

d2Target, err := d2.NewTarget()
if err != nil {
return fmt.Errorf("error creating D2 target: %w", err)
var target messageflow.Target
switch format {
case "d2":
d2Target, err := d2.NewTarget()
if err != nil {
return fmt.Errorf("error creating D2 target: %w", err)
}
target = d2Target
case "mermaid":
mermaidTarget, err := mermaid.NewTarget()
if err != nil {
return fmt.Errorf("error creating Mermaid target: %w", err)
}
target = mermaidTarget
}

newChangelog, err := docs.Generate(ctx, s, d2Target, title, outputDir)
newChangelog, err := docs.Generate(ctx, s, target, title, outputDir)
if err != nil {
return fmt.Errorf("error generating documentation: %w", err)
}
Expand Down
Loading
Loading