Skip to content

Commit e349d30

Browse files
authored
Do not create template file if the content is empty (#1072)
1 parent 3897031 commit e349d30

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

boilingcore/output.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func executeTemplates(e executeTemplateData) error {
140140
writeImports(out, imps)
141141
}
142142

143+
prevLen := out.Len()
143144
for _, tplName := range tplNames {
144145
if err := executeTemplate(out, e.templates.Template, tplName, e.data); err != nil {
145146
return err
@@ -152,6 +153,12 @@ func executeTemplates(e executeTemplateData) error {
152153
fName = filepath.Join(dir, fName)
153154
}
154155

156+
// Skip writing the file if the content is empty
157+
if out.Len()-prevLen < 1 {
158+
fmt.Fprintf(os.Stderr, "skipping empty file: %s/%s\n", e.state.Config.OutFolder, fName)
159+
continue
160+
}
161+
155162
if err := writeFile(e.state.Config.OutFolder, fName, out, isGo); err != nil {
156163
return err
157164
}

0 commit comments

Comments
 (0)