const fs = require('fs'); const path = require('path'); const outputsRoot = path.resolve(__dirname, '..', 'outputs'); const dashboardStatePath = path.join(outputsRoot, 'dashboard', 'dashboard-state.json'); const roomsLatestPath = path.join(outputsRoot, 'groups', 'rooms-latest.json'); function timestamp() { return new Date().toISOString().replace(/[:.]/g, '-'); } function backup(filePath) { const backupPath = `${filePath}.backup-${timestamp()}`; fs.copyFileSync(filePath, backupPath); console.log(`Backed up: ${filePath} -> ${backupPath}`); return backupPath; } function cleanDashboardState() { const data = JSON.parse(fs.readFileSync(dashboardStatePath, 'utf8')); const before = Object.keys(data.customers || {}).length; delete data.customers['wx-u-1']; const after = Object.keys(data.customers || {}).length; data.updatedAt = new Date().toISOString(); fs.writeFileSync(dashboardStatePath, JSON.stringify(data, null, 2), 'utf8'); console.log(`Dashboard state: removed ${before - after} mock customer(s)`); } function cleanRoomsLatest() { const rooms = JSON.parse(fs.readFileSync(roomsLatestPath, 'utf8')); const mockIds = new Set(['r-1', 'r-2', 'r-3']); const before = rooms.length; const cleaned = rooms.filter(room => !mockIds.has(room.roomId)); const after = cleaned.length; fs.writeFileSync(roomsLatestPath, JSON.stringify(cleaned, null, 2), 'utf8'); console.log(`Rooms latest: removed ${before - after} mock group(s)`); } backup(dashboardStatePath); backup(roomsLatestPath); cleanDashboardState(); cleanRoomsLatest(); console.log('Cleanup complete.');