removed project node from output

This commit is contained in:
Martino Ferrari
2026-01-28 01:18:09 +01:00
parent 597fd3eddf
commit 776b1fddc3

View File

@@ -56,27 +56,44 @@ func (b *Builder) Build(f *os.File) error {
tree.AddFile(file, config) tree.AddFile(file, config)
} }
// Determine root node to print
rootNode := tree.Root
if expectedProject != "" {
if child, ok := tree.Root.Children[expectedProject]; ok {
rootNode = child
}
}
// Write entire root content (definitions and children) to the single output file // Write entire root content (definitions and children) to the single output file
b.writeNodeContent(f, tree.Root, 0) b.writeNodeBody(f, rootNode, 0)
return nil return nil
} }
func (b *Builder) writeNodeContent(f *os.File, node *index.ProjectNode, indent int) { func (b *Builder) writeNodeContent(f *os.File, node *index.ProjectNode, indent int) {
// 1. Sort Fragments: Class first
sort.SliceStable(node.Fragments, func(i, j int) bool {
return hasClass(node.Fragments[i]) && !hasClass(node.Fragments[j])
})
indentStr := strings.Repeat(" ", indent) indentStr := strings.Repeat(" ", indent)
// If this node has a RealName (e.g. +App), we print it as an object definition // If this node has a RealName (e.g. +App), we print it as an object definition
if node.RealName != "" { if node.RealName != "" {
fmt.Fprintf(f, "%s%s = {\n", indentStr, node.RealName) fmt.Fprintf(f, "%s%s = {\n", indentStr, node.RealName)
indent++ indent++
indentStr = strings.Repeat(" ", indent)
} }
b.writeNodeBody(f, node, indent)
if node.RealName != "" {
indent--
indentStr = strings.Repeat(" ", indent)
fmt.Fprintf(f, "%s}\n", indentStr)
}
}
func (b *Builder) writeNodeBody(f *os.File, node *index.ProjectNode, indent int) {
// 1. Sort Fragments: Class first
sort.SliceStable(node.Fragments, func(i, j int) bool {
return hasClass(node.Fragments[i]) && !hasClass(node.Fragments[j])
})
writtenChildren := make(map[string]bool) writtenChildren := make(map[string]bool)
// 2. Write definitions from fragments // 2. Write definitions from fragments
@@ -110,12 +127,6 @@ func (b *Builder) writeNodeContent(f *os.File, node *index.ProjectNode, indent i
child := node.Children[k] child := node.Children[k]
b.writeNodeContent(f, child, indent) b.writeNodeContent(f, child, indent)
} }
if node.RealName != "" {
indent--
indentStr = strings.Repeat(" ", indent)
fmt.Fprintf(f, "%s}\n", indentStr)
}
} }
func (b *Builder) writeDefinition(f *os.File, def parser.Definition, indent int) { func (b *Builder) writeDefinition(f *os.File, def parser.Definition, indent int) {