Skip to content
Merged
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
17 changes: 15 additions & 2 deletions internal/generate/generate_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func Generate(projectConfig projectconfig.ZeroProjectConfig) error {
type fileConfig struct {
source string
destination string
modeBits os.FileMode
}

// sortFileType walks the module directory to find and classify all files into bin / text/plain (non-bin) types.
Expand Down Expand Up @@ -94,6 +95,11 @@ func sortFileType(moduleDir string, outputDir string, overwrite bool) ([]*fileCo
}
}

fileInfo, err := os.Stat(path)
if err != nil {
panic(err)
}

// detect the file type
detectedMIME, err := mimetype.DetectFile(path)
if err != nil {
Expand All @@ -112,13 +118,15 @@ func sortFileType(moduleDir string, outputDir string, overwrite bool) ([]*fileCo
binTypeFiles = append(binTypeFiles, &fileConfig{
source: path,
destination: outputPath,
modeBits: fileInfo.Mode().Perm(),
})
continue
}

txtTypeFiles = append(txtTypeFiles, &fileConfig{
source: path,
destination: outputPath,
modeBits: fileInfo.Mode().Perm(),
})
}
return txtTypeFiles, binTypeFiles
Expand Down Expand Up @@ -169,6 +177,12 @@ func executeTemplates(templates []*fileConfig, data interface{}, delimiters []st
if err != nil {
flog.Errorf("Error initializing file '%s'", err)
}

err = f.Chmod(tmpltConfig.modeBits)
if err != nil {
flog.Errorf("Error changing mode bits '%s'", err)
}

// @TODO if strict mode then only copy file
name := path.Base(source)
template, err := template.New(name).Delims(leftDelim, rightDelim).Funcs(util.FuncMap).ParseFiles(source)
Expand All @@ -185,7 +199,6 @@ func executeTemplates(templates []*fileConfig, data interface{}, delimiters []st
}

func copyBinFiles(binTypeFiles []*fileConfig) {

for _, binFile := range binTypeFiles {
source := binFile.source
dest := binFile.destination
Expand All @@ -204,7 +217,7 @@ func copyBinFiles(binTypeFiles []*fileConfig) {
}
defer from.Close()

to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, 0666)
to, err := os.OpenFile(dest, os.O_RDWR|os.O_CREATE, binFile.modeBits)
if err != nil {
log.Fatal(err)
flog.Errorf("Error creating file '%s': %v", dest, err)
Expand Down