0
0
Fork 0

also copy static files to output directory

This commit is contained in:
Gibheer 2022-08-29 21:26:04 +02:00
parent b20da12456
commit 6d25cc80d5
1 changed files with 34 additions and 0 deletions

View File

@ -102,6 +102,40 @@ func main() {
f.Close()
}
staticFiles, err := filepath.Glob(*staticDir + "/**")
if err != nil {
log.Fatalf("could not get all static files from '%s': %s", *staticDir, err)
}
buf := []byte{}
for _, fileName := range staticFiles {
filePath := path.Join(*outputDir, fileName)
dir := path.Dir(filePath)
isDir := false
if info, err := os.Stat(fileName); err != nil {
log.Fatalf("could not stat file '%s': %s", fileName, err)
} else {
isDir = info.IsDir()
if isDir {
dir = filePath
}
}
if _, found := dirsCreated[dir]; !found {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Fatalf("could not create directory '%s': %s", dir, err)
}
}
if isDir {
continue
}
buf, err = os.ReadFile(fileName)
if err != nil {
log.Fatalf("could not read static file '%s': %s", fileName, err)
}
if err := os.WriteFile(path.Join(*outputDir, fileName), buf, 0755); err != nil {
log.Fatalf("could not write static file '%s': %s", fileName, err)
}
}
}
if *listen != "" {