Skip to content

Commit

Permalink
Do not create template file if the content is empty (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo authored Jan 28, 2022
1 parent 3897031 commit e349d30
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions boilingcore/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func executeTemplates(e executeTemplateData) error {
writeImports(out, imps)
}

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

// Skip writing the file if the content is empty
if out.Len()-prevLen < 1 {
fmt.Fprintf(os.Stderr, "skipping empty file: %s/%s\n", e.state.Config.OutFolder, fName)
continue
}

if err := writeFile(e.state.Config.OutFolder, fName, out, isGo); err != nil {
return err
}
Expand Down

0 comments on commit e349d30

Please sign in to comment.