File size: 6,063 Bytes
87d538c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python
"""
CofifoAIWO Setup-Skript
Dieses Skript bereitet die Anwendung für die Verwendung vor, indem es:
1. Die Abhängigkeiten installiert
2. Das Frontend erstellt
3. Die Anwendung startet
"""

import os
import sys
import subprocess
import shutil
from pathlib import Path

# Konstanten
BASE_DIR = Path(__file__).resolve().parent
FRONTEND_DIR = BASE_DIR / "frontend"
REQUIREMENTS_FILE = BASE_DIR / "requirements.txt"

def print_header(text):
    """Gibt eine formatierte Überschrift aus."""
    print("\n" + "=" * 60)
    print(f" {text}")
    print("=" * 60)

def run_command(command, cwd=None):
    """Führt einen Befehl aus und gibt die Ausgabe zurück."""
    print(f"Ausführen: {command}")
    
    try:
        process = subprocess.run(
            command,
            shell=True,
            check=True,
            cwd=cwd,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            universal_newlines=True
        )
        if process.stdout:
            print(process.stdout)
        return True
    except subprocess.CalledProcessError as e:
        print(f"Fehler bei der Ausführung von '{command}':")
        print(e.stderr)
        return False

def install_python_dependencies():
    """Installiert die Python-Abhängigkeiten."""
    print_header("Installiere Python-Abhängigkeiten")
    
    if not run_command(f"{sys.executable} -m pip install -r {REQUIREMENTS_FILE}"):
        print("Fehler beim Installieren der Python-Abhängigkeiten. Bitte prüfe die Fehlermeldung.")
        return False
    
    return True

def setup_frontend():
    """Richtet das Frontend ein und erstellt es."""
    print_header("Richte Frontend ein")
    
    # Überprüfe, ob npm oder yarn verfügbar ist
    npm_or_yarn = "yarn" if shutil.which("yarn") else "npm"
    
    if not os.path.exists(FRONTEND_DIR):
        print(f"Frontend-Verzeichnis nicht gefunden: {FRONTEND_DIR}")
        print("Erstelle Frontend-Verzeichnis...")
        os.makedirs(FRONTEND_DIR, exist_ok=True)
    
    # Erstelle package.json, wenn noch nicht vorhanden
    package_json = FRONTEND_DIR / "package.json"
    if not os.path.exists(package_json):
        print("Erstelle package.json...")
        with open(package_json, "w") as f:
            f.write("""
{
  "name": "cofifoaiwo-frontend",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "dependencies": {
    "axios": "^0.27.2",
    "core-js": "^3.25.0",
    "vue": "^3.2.38",
    "vue-router": "^4.1.5",
    "vuex": "^4.0.2"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "~5.0.8",
    "@vue/cli-plugin-eslint": "~5.0.8",
    "@vue/cli-plugin-router": "~5.0.8",
    "@vue/cli-plugin-vuex": "~5.0.8",
    "@vue/cli-service": "~5.0.8",
    "@vue/compiler-sfc": "^3.2.38",
    "eslint": "^8.23.0",
    "eslint-plugin-vue": "^9.4.0"
  }
}
            """.strip())
    
    # Installiere Frontend-Abhängigkeiten
    print(f"Installiere Frontend-Abhängigkeiten mit {npm_or_yarn}...")
    if not run_command(f"{npm_or_yarn} install", cwd=FRONTEND_DIR):
        print("Fehler beim Installieren der Frontend-Abhängigkeiten. Bitte prüfe die Fehlermeldung.")
        return False
    
    # Erstelle Frontend
    print(f"Erstelle Frontend mit {npm_or_yarn}...")
    if not run_command(f"{npm_or_yarn} run build", cwd=FRONTEND_DIR):
        print("Fehler beim Erstellen des Frontends. Bitte prüfe die Fehlermeldung.")
        return False
    
    return True

def start_application():
    """Startet die Anwendung."""
    print_header("Starte Anwendung")
    
    print("CofifoAIWO wird gestartet...")
    print("Die Anwendung ist unter http://localhost:5000 erreichbar.")
    
    run_command(f"{sys.executable} app.py")

def main():
    """Hauptfunktion."""
    print_header("CofifoAIWO Setup")
    
    print("Dieses Skript bereitet CofifoAIWO für die Verwendung vor.")
    print("Es installiert die Abhängigkeiten, erstellt das Frontend und startet die Anwendung.")
    
    # Frage nach Bestätigung
    choice = input("\nMöchtest du fortfahren? (j/n): ").lower()
    if choice != 'j' and choice != 'ja':
        print("Setup abgebrochen.")
        return
    
    # Führe alle Setup-Schritte aus
    if not install_python_dependencies():
        print("Fehler beim Installieren der Python-Abhängigkeiten. Setup wird abgebrochen.")
        return
    
    if not setup_frontend():
        print("Fehler beim Einrichten des Frontends. Setup wird abgebrochen.")
        return
    
    print("\nSetup erfolgreich abgeschlossen!")
    
    # Frage, welche Ausführungsart gewünscht ist
    print("\nWie möchtest du CofifoAIWO starten?")
    print("1: Webanwendung (GUI im Browser)")
    print("2: Kommandozeile (CLI)")
    print("3: Nicht jetzt starten")
    
    while True:
        choice = input("\nWähle eine Option (1-3): ")
        
        if choice == "1":
            start_application()
            break
        elif choice == "2":
            print("\nBeispiel-Befehle für die CLI-Nutzung:")
            print(f"  {sys.executable} combine_files.py --list")
            print(f"  {sys.executable} combine_files.py --add my_project /pfad/zum/verzeichnis")
            print(f"  {sys.executable} combine_files.py --use my_project output.txt --tree")
            
            cmd = input("\nGib deinen gewünschten CLI-Befehl ein (oder drücke Enter, um zu beenden): ")
            if cmd.strip():
                os.system(f"{sys.executable} combine_files.py {cmd}")
            break
        elif choice == "3":
            print("\nDu kannst die Anwendung später starten mit:")
            print(f"  GUI:  {sys.executable} app.py")
            print(f"  CLI:  {sys.executable} combine_files.py --help")
            print("\nDie Webanwendung ist dann unter http://localhost:5000 erreichbar.")
            break
        else:
            print("Ungültige Eingabe. Bitte wähle 1, 2 oder 3.")

if __name__ == "__main__":
    main()