-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
81 lines (70 loc) · 1.9 KB
/
Copy pathmain.go
File metadata and controls
81 lines (70 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
// "fmt"
"log"
"os"
"github.com/flowdev/flow-dsl/draw"
"github.com/flowdev/flow-dsl/parser"
)
type linkGenerator struct {
baseDir string
}
func (lg linkGenerator) GenerateLink(imprt, lastImportPart, typ string, isData bool) (link string, isLinkToFlow bool) {
if isData {
if typ == "data.Data" {
return "data/data.go#L3-L8", true
}
return "", false
}
switch typ {
case "validateMIWU":
// log.Printf("DEBUG: returning: %q + '.md', true", typ)
return typ + ".md", true
case "checkBasicMIWU":
// log.Printf("DEBUG: returning: %q + '.md', true", typ)
return typ + ".md", true
}
return "", false
}
func main() {
if len(os.Args) < 2 {
log.Println("FATAL: Flow file needed as input")
os.Exit(1)
}
flowFileName := os.Args[1]
flowFile, err := parser.ParseFile(flowFileName, &linkGenerator{baseDir: "."})
if err != nil {
log.Printf("ERROR: Can't convert to data format: %v", err)
os.Exit(2)
}
drawFlows := ConvertFlowsToDraw(flowFile)
// flowFileExt := path.Ext(flowFileName)
// baseFlowFile := flowFileName[0 : len(flowFileName)-len(flowFileExt)]
// mdFile := baseFlowFile + "-links"
// flowMode := draw.FlowModeNoLinks
flowMode := draw.FlowModeMDLinks
width := 1900
darkMode := false
for _, drawFlow := range drawFlows {
// imdFile := fmt.Sprintf("%s-no-links", drawFlow.Name)
imdFile := drawFlow.Name
drawFlow.ChangeConfig(imdFile, flowMode, width, darkMode)
svgContents, mdContent, err := drawFlow.Draw()
if err != nil {
log.Printf("unexpected draw error: %v", err)
os.Exit(3)
}
for svgFile, svgContent := range svgContents {
err = os.WriteFile(svgFile, svgContent, 0666)
if err != nil {
log.Printf("ERROR: unable to write file %q: %v", svgFile, err)
os.Exit(4)
}
}
err = os.WriteFile(imdFile+".md", mdContent, 0666)
if err != nil {
log.Printf("ERROR: unable to write file %q: %v", imdFile+".md", err)
os.Exit(5)
}
}
}