EmberClone/scripts/phase25_features.py

142 lines
5.7 KiB
Python

#!/usr/bin/env python3
"""Phase-25: saved-reports, role-perms, working-hours, holidays, default-project."""
from __future__ import annotations
import asyncio, datetime, json, sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from phase2_features import Feature, FileGen, ROOT, log, log_section
from phase3_features import run_feature_v2
PHASE_STATE = ROOT / ".phase25-state.json"
FEATURES: list[Feature] = [
Feature(
name="working-hours-config",
description="appSettings.workingHoursPerDay für Tagesziel-Anzeige",
files=[FileGen(
path="apps/api/src/db/schema.ts",
purpose=(
"WICHTIG: BEHALTE ALLE existierenden Tabellen/Spalten. "
"Füge nur Spalte `workingHoursPerDay: integer('working_hours_per_day').notNull().default(8)` zu appSettings. "
"BEHALTE: alle bisherigen Tabellen inkl. passwordResetTokens, apiKeys, timeEntryComments, savedViews, webhooks, "
"timeEntryAttachments, invitations, auditLog, documents, projectTemplates."
),
refs=["apps/api/src/db/schema.ts"],
), FileGen(
path="apps/web/src/pages/Settings.tsx",
purpose=(
"ERWEITERT — füge 'Arbeitsstunden pro Tag' Number-Input (default 8). Behalte alle bestehenden Fields."
),
refs=["apps/web/src/pages/Settings.tsx"],
)],
),
Feature(
name="default-project-per-customer",
description="Customer kann ein default-Project haben (für Quick-Entries)",
files=[FileGen(
path="apps/api/src/db/schema.ts",
purpose=(
"WICHTIG: BEHALTE ALLE existierenden Tabellen/Spalten. "
"Füge nur Spalte `defaultProjectId: uuid('default_project_id').references(() => projects.id, { onDelete: 'set null' })` zu customers."
),
refs=["apps/api/src/db/schema.ts"],
)],
),
Feature(
name="holiday-calendar",
description="Holiday-Tabelle + Page für admin (Feiertage definieren)",
files=[FileGen(
path="apps/api/src/db/schema.ts",
purpose=(
"WICHTIG: BEHALTE ALLE bisherigen Tabellen + Spalten. Füge nur Tabelle `holidays`: "
"id (uuid pk), date (date notnull), name (text notnull), createdAt."
),
refs=["apps/api/src/db/schema.ts"],
), FileGen(
path="apps/api/src/routes/holidays.ts",
purpose=(
"Fastify-Plugin /api/holidays. CRUD GET/POST/DELETE. Admin-only für POST/DELETE. Auth required."
),
refs=["apps/api/src/routes/customers.ts"],
), FileGen(
path="apps/web/src/pages/Holidays.tsx",
purpose=(
"Holidays-Page (admin-only). Liste + Create-Form (date, name). Tailwind."
),
refs=["apps/web/src/pages/Customers.tsx"],
)],
),
Feature(
name="role-permissions-page",
description="Admin-Page zum Anzeigen welche Permissions welche Rolle hat (Read-only Matrix)",
files=[FileGen(
path="apps/web/src/pages/RolePermissions.tsx",
purpose=(
"RolePermissions-Page (admin-only). Statische Tabelle: Spalten Admin/User, Reihen Permissions "
"(z.B. 'View dashboard', 'Edit own entries', 'Manage users', 'Configure settings', 'View audit log'). "
"Checkmarks zeigen wer was darf. Read-only Doku-View."
),
)],
),
Feature(
name="api-client-phase25",
description="API um holidays endpoints",
files=[FileGen(
path="apps/web/src/lib/api.ts",
purpose=(
"ERWEITERT — behalte ALLES. Füge: listHolidays(), createHoliday({date,name}), deleteHoliday(id)."
),
refs=["apps/web/src/lib/api.ts"],
)],
),
Feature(
name="router-phase25",
description="Mount /holidays + /role-permissions Routes",
files=[FileGen(
path="apps/api/src/routes/index.ts",
purpose="ERWEITERT — füge holidayRoutes ('/api/holidays'). Behalte alles.",
refs=["apps/api/src/routes/index.ts"],
), FileGen(
path="apps/web/src/App.tsx",
purpose="ERWEITERT — füge /holidays (admin) + /role-permissions (admin) Routes. Behalte alles.",
refs=["apps/web/src/App.tsx"],
)],
),
]
def load_state():
if PHASE_STATE.exists():
return json.loads(PHASE_STATE.read_text())
return {"completed_features": [], "current_feature": None, "started_at": datetime.datetime.now().isoformat()}
def save_state(state):
PHASE_STATE.write_text(json.dumps(state, indent=2))
async def main():
log_section("🚀 Phase-25 Codegen-Run gestartet")
state = load_state()
for feature in FEATURES:
if feature.name in state.get("completed_features", []):
continue
state["current_feature"] = feature.name; save_state(state)
try:
success = await run_feature_v2(feature)
state.setdefault("completed_features" if success else "attempted_features", []).append(feature.name)
save_state(state)
except Exception as e:
log(f"{feature.name} crashed: {e}", level="ERROR")
state.setdefault("attempted_features", []).append(feature.name); save_state(state)
log_section("Phase-25 Run beendet")
log(f"OK: {len(state.get('completed_features', []))}, Attempted: {len(state.get('attempted_features', []))}, Total: {len(FEATURES)}")
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main()))