-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodejs_tab.py
More file actions
205 lines (171 loc) · 8.85 KB
/
nodejs_tab.py
File metadata and controls
205 lines (171 loc) · 8.85 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
from base_tab import BaseTab
import tkinter as tk
from tkinter import ttk, messagebox
import subprocess
import json
import os
import logging
class NodejsTab(BaseTab):
def setup_ui(self):
self.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# Node.js Bilgileri
info_frame = ttk.LabelFrame(self, text="Node.js Bilgileri", padding="10")
info_frame.pack(fill=tk.X, pady=5)
# Sürüm listesi
columns = ("Sürüm", "Durum", "npm", "Konum")
self.node_list = ttk.Treeview(info_frame, columns=columns, show="headings")
for col in columns:
self.node_list.heading(col, text=col)
self.node_list.pack(fill=tk.X, pady=5)
# NVM Yönetimi
nvm_frame = ttk.LabelFrame(self, text="NVM (Node Version Manager)", padding="10")
nvm_frame.pack(fill=tk.X, pady=5)
# Yüklenebilir sürümler
ttk.Label(nvm_frame, text="Yüklenebilir Sürümler:").pack(anchor=tk.W)
self.version_combo = ttk.Combobox(nvm_frame, width=20, state="readonly")
self.version_combo.pack(pady=5)
# Butonlar
button_frame = ttk.Frame(self)
button_frame.pack(pady=10)
ttk.Button(button_frame, text="Sürümleri Tara",
command=self.scan_versions).pack(side=tk.LEFT, padx=5)
ttk.Button(button_frame, text="Seçili Sürümü Yükle",
command=self.install_version).pack(side=tk.LEFT, padx=5)
ttk.Button(button_frame, text="Seçili Sürümü Varsayılan Yap",
command=self.set_default).pack(side=tk.LEFT, padx=5)
ttk.Button(button_frame, text="npm Cache Temizle",
command=self.clean_npm_cache).pack(side=tk.LEFT, padx=5)
ttk.Button(button_frame, text="Kullanılmayan Sürümleri Kaldır",
command=self.cleanup_versions).pack(side=tk.LEFT, padx=5)
def scan_versions(self):
"""Node.js sürümlerini tara"""
try:
# Listeyi temizle
for item in self.node_list.get_children():
self.node_list.delete(item)
# Olası Node.js dizinleri
nodejs_paths = [
"E:\\Program Files\\nodejs",
"C:\\Program Files\\nodejs",
"C:\\Program Files (x86)\\nodejs",
os.path.expandvars("%NODE_HOME%")
]
# PATH'ten Node.js dizinlerini bul
path_dirs = os.environ.get('PATH', '').split(';')
for dir in path_dirs:
if 'node' in dir.lower():
base_dir = dir.rstrip('\\')
if os.path.exists(os.path.join(base_dir, 'node.exe')):
if base_dir not in nodejs_paths:
nodejs_paths.append(base_dir)
# Bulunan dizinlerdeki Node.js'leri kontrol et
for node_dir in nodejs_paths:
if node_dir and os.path.exists(node_dir):
node_exe = os.path.join(node_dir, 'node.exe')
npm_cmd = os.path.join(node_dir, 'npm.cmd')
if os.path.exists(node_exe):
try:
# Node.js sürümünü al
node_version = subprocess.run([node_exe, '--version'],
capture_output=True, text=True).stdout.strip()
# npm sürümünü al
npm_version = "?"
if os.path.exists(npm_cmd):
npm_version = subprocess.run([npm_cmd, '--version'],
capture_output=True, text=True).stdout.strip()
# PATH'te aktif mi kontrol et
is_active = node_dir.lower() in [p.lower() for p in path_dirs]
self.node_list.insert("", tk.END, values=(
node_version,
"✅ Aktif" if is_active else "⚪ Pasif",
f"npm {npm_version}",
node_dir
))
except Exception as e:
logging.error(f"Node.js sürüm kontrolü hatası ({node_dir}): {e}")
# NVM yüklü mü kontrol et
nvm_dir = os.path.expanduser("~\\AppData\\Roaming\\nvm")
if os.path.exists(nvm_dir):
for dir in os.listdir(nvm_dir):
if dir.startswith('v'):
node_path = os.path.join(nvm_dir, dir)
try:
result = subprocess.run([os.path.join(node_path, 'node.exe'), '--version'],
capture_output=True, text=True)
version = result.stdout.strip()
# npm sürümünü kontrol et
npm_result = subprocess.run([os.path.join(node_path, 'npm.cmd'), '--version'],
capture_output=True, text=True)
npm_version = npm_result.stdout.strip()
self.node_list.insert("", tk.END, values=(
version,
"⚪ Pasif",
f"npm {npm_version}",
node_path
))
except:
continue
# Yüklenebilir sürümleri güncelle
try:
nvm_list = subprocess.run(['nvm', 'list', 'available'],
capture_output=True, text=True)
if nvm_list.returncode == 0:
versions = [v.strip() for v in nvm_list.stdout.split('\n') if v.strip()]
self.version_combo['values'] = versions
except:
pass
except Exception as e:
logging.error(f"Node.js tarama hatası: {e}")
messagebox.showerror("Hata", str(e))
def install_version(self):
"""Seçili sürümü yükle"""
version = self.version_combo.get()
if not version:
messagebox.showwarning("Uyarı", "Lütfen bir sürüm seçin!")
return
try:
subprocess.run(['nvm', 'install', version], check=True)
messagebox.showinfo("Başarılı", f"Node.js {version} yüklendi!")
self.scan_versions()
except Exception as e:
logging.error(f"Node.js yükleme hatası: {e}")
messagebox.showerror("Hata", str(e))
def set_default(self):
"""Seçili sürümü varsayılan yap"""
selected = self.node_list.selection()
if not selected:
messagebox.showwarning("Uyarı", "Lütfen bir sürüm seçin!")
return
try:
version = self.node_list.item(selected[0])['values'][0]
subprocess.run(['nvm', 'use', version], check=True)
messagebox.showinfo("Başarılı", f"Node.js {version} varsayılan yapıldı!")
self.scan_versions()
except Exception as e:
logging.error(f"Node.js varsayılan yapma hatası: {e}")
messagebox.showerror("Hata", str(e))
def clean_npm_cache(self):
"""npm önbelleğini temizle"""
try:
subprocess.run(['npm', 'cache', 'clean', '--force'], check=True)
messagebox.showinfo("Başarılı", "npm önbelleği temizlendi!")
except Exception as e:
logging.error(f"npm temizleme hatası: {e}")
messagebox.showerror("Hata", str(e))
def cleanup_versions(self):
"""Kullanılmayan Node.js sürümlerini kaldır"""
if not messagebox.askyesno("Onay",
"Bu işlem aktif olmayan Node.js sürümlerini kaldıracak.\n"
"Devam etmek istiyor musunuz?"):
return
try:
for item in self.node_list.get_children():
values = self.node_list.item(item)['values']
if values[1] == "⚪ Pasif":
version = values[0]
subprocess.run(['nvm', 'uninstall', version], check=True)
messagebox.showinfo("Başarılı", "Kullanılmayan sürümler kaldırıldı!")
self.scan_versions()
except Exception as e:
logging.error(f"Node.js temizleme hatası: {e}")
messagebox.showerror("Hata", str(e))