Skip to content

Commit c292976

Browse files
committed
Cleans the 'static' folder when coping the assets
1 parent 59cb903 commit c292976

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

resources/files.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,24 @@ import (
99

1010
const defaultFileMask = 0740
1111
const baseFSDir = "build"
12+
const staticDir = "static"
1213

1314
//go:embed build
1415
var f embed.FS
1516

1617
// Writes all static asset files from the 'resources/build' folder (now in the binary) to the given folder
1718
func WriteTo(ospath string) error {
19+
20+
// Removes the 'static' directory to prevent old hashed asset files from piling up
21+
staticDirPath := filepath.Join(ospath, staticDir)
22+
if _, err := os.Stat(staticDirPath); !os.IsNotExist(err) {
23+
err := os.RemoveAll(staticDirPath)
24+
if err != nil {
25+
return err
26+
}
27+
}
28+
29+
// Copies all files from this binary to the disk
1830
return fs.WalkDir(f, baseFSDir, func(fspath string, d fs.DirEntry, err error) error {
1931
relPath, err := filepath.Rel(baseFSDir, filepath.FromSlash(fspath))
2032
fPath := filepath.Join(ospath, relPath)

0 commit comments

Comments
 (0)