Skip to content

Commit b2474c6

Browse files
committed
feat: Add --clean flag for node directory cleanup and dynamic version-based directory naming with Makefile version sourcing.
1 parent 167bfca commit b2474c6

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

Apps/node_runner/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
BUILD_DIR=build
55

66
# Version info
7-
VERSION?=dev
7+
VERSION ?= v$(shell if [ -f ../../Framework/Version.txt ]; then grep -Eo "version[[:space:]]*=[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+" ../../Framework/Version.txt | head -n1 | sed 's/.*=//; s/ //g'; else echo dev; fi)
88
APPNAME=ZeuZ_Node
99
LDFLAGS=-X main.version=$(VERSION)
1010

Apps/node_runner/main.go

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ import (
1515
"github.com/automationsolutionz/Zeuz_Python_Node/Apps/node_runner/uv_installer"
1616
)
1717

18-
const (
19-
zeuzDir = "ZeuZ_Node"
20-
)
21-
2218
var (
2319
version = "dev"
2420
branch = flag.String("branch", "", "Branch to download (defaults to tagged version)")
21+
cleanFlag = flag.Bool("clean", false, "Remove ZeuZ Node directory and $HOME/.zeuz and exit")
2522
)
2623

27-
// downloadFile downloads a file from URL to a local path
2824
func downloadFile(url, destPath string) error {
2925
resp, err := http.Get(url)
3026
if err != nil {
@@ -135,8 +131,19 @@ func getZeuZNodeURL() string {
135131
return "https://github.com/AutomationSolutionz/Zeuz_Python_Node/archive/refs/heads/dev.zip"
136132
}
137133

134+
func getZeuZPostfix() string {
135+
if *branch != "" {
136+
return *branch
137+
}
138+
if version != "dev" && !strings.HasPrefix(version, "dev-") {
139+
return version
140+
}
141+
return "dev"
142+
}
143+
138144
// setupZeuzNode downloads and extracts the ZeuZ Node repository if not already present
139145
func setupZeuzNode() error {
146+
zeuzDir := fmt.Sprintf("Zeuz_Python_Node-%s", getZeuZPostfix())
140147
// Check if ZeuZ Node directory already exists and contains files
141148
if info, err := os.Stat(zeuzDir); err == nil && info.IsDir() {
142149
// Check if directory is not empty
@@ -265,6 +272,37 @@ func main() {
265272

266273
fmt.Printf("✅ ZeuZ Node %s\n", version)
267274

275+
zeuzDir := fmt.Sprintf("Zeuz_Python_Node-%s", getZeuZPostfix())
276+
277+
if *cleanFlag {
278+
var removedAny bool
279+
if err := os.RemoveAll(zeuzDir); err == nil {
280+
fmt.Printf("Removed %s\n", zeuzDir)
281+
removedAny = true
282+
} else if !os.IsNotExist(err) {
283+
fmt.Printf("Failed to remove %s: %v\n", zeuzDir, err)
284+
}
285+
286+
home, err := os.UserHomeDir()
287+
if err == nil {
288+
zeuzHome := filepath.Join(home, ".zeuz")
289+
if err := os.RemoveAll(zeuzHome); err == nil {
290+
fmt.Printf("Removed %s\n", zeuzHome)
291+
removedAny = true
292+
} else if !os.IsNotExist(err) {
293+
fmt.Printf("Failed to remove %s: %v\n", zeuzHome, err)
294+
}
295+
} else {
296+
fmt.Printf("Could not determine user home dir: %v\n", err)
297+
}
298+
299+
if !removedAny {
300+
fmt.Println("Nothing removed. No matching directories found.")
301+
} else {
302+
fmt.Println("Cleanup complete — proceeding to download & install a fresh copy.")
303+
}
304+
}
305+
268306
// Setup ZeuZ Node directory and change into it
269307
if err := setupZeuzNode(); err != nil {
270308
fmt.Printf("Error setting up ZeuZ Node: %v\n", err)

0 commit comments

Comments
 (0)