/
makefile.go
44 lines (34 loc) · 963 Bytes
/
makefile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package mage
import (
"context"
"fmt"
"os"
"strings"
)
// Makefile analog: clean the artifacts (and .makefiles).
func Clean(ctx context.Context) error {
LogPrintF("[global] Cleaning ...")
if IsVerbose() {
LogPrintF("\tremoving directory ./.makefiles ...")
}
if err := os.RemoveAll("./.makefiles"); err != nil {
return fmt.Errorf("unable to remove makefiles directory (./.makefiles): %w", err)
}
dirEntry, dirErr := os.ReadDir("./artifacts")
if dirErr != nil {
return fmt.Errorf("unable to read directory (./artifacts): %w", dirErr)
}
for _, entry := range dirEntry {
if strings.EqualFold(entry.Name(), "data") || !entry.IsDir() {
continue
}
dirName := fmt.Sprintf("./artifacts/%s", entry.Name())
if IsVerbose() {
LogPrintF("\tremoving directory %s ...", dirName)
}
if err := os.RemoveAll(dirName); err != nil {
return fmt.Errorf("unable to remove artifacts directory (%s): %w", dirName, err)
}
}
return nil
}