|
5 | 5 | * This file contains only wizard-ci specific utilities. |
6 | 6 | */ |
7 | 7 | import { spawn } from "child_process"; |
8 | | -import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs"; |
| 8 | +import { existsSync, readdirSync } from "fs"; |
9 | 9 | import { join } from "path"; |
10 | 10 |
|
11 | 11 | // Re-export git operations from shared service |
@@ -276,87 +276,3 @@ export function runEvaluatorOnBranch(options: EvaluateOnBranchOptions): Promise< |
276 | 276 | }); |
277 | 277 | } |
278 | 278 |
|
279 | | -// ============================================================================ |
280 | | -// Wizard Log Extraction |
281 | | -// ============================================================================ |
282 | | - |
283 | | -const WIZARD_LOG_PATH = "/tmp/posthog-wizard.log"; |
284 | | - |
285 | | -/** |
286 | | - * Extract logs from a specific wizard run based on start time. |
287 | | - * Parses the log file and returns only entries from the run that started |
288 | | - * at or after the given timestamp. |
289 | | - */ |
290 | | -export function extractWizardLogs(runStartTime: Date): string | null { |
291 | | - if (!existsSync(WIZARD_LOG_PATH)) { |
292 | | - return null; |
293 | | - } |
294 | | - |
295 | | - try { |
296 | | - const logContent = readFileSync(WIZARD_LOG_PATH, "utf-8"); |
297 | | - const lines = logContent.split("\n"); |
298 | | - |
299 | | - // Add 1 second buffer to account for timing differences between |
300 | | - // when we capture the start time and when the wizard writes its header |
301 | | - const bufferMs = 1000; |
302 | | - const adjustedStartTime = new Date(runStartTime.getTime() - bufferMs); |
303 | | - |
304 | | - // Find the run header that matches our start time (or is closest after it) |
305 | | - let captureStart = -1; |
306 | | - let captureEnd = lines.length; |
307 | | - |
308 | | - for (let i = 0; i < lines.length; i++) { |
309 | | - // Check for run header pattern (3 lines: separator, timestamp, separator) |
310 | | - if ( |
311 | | - lines[i]?.startsWith("=".repeat(60)) && |
312 | | - lines[i + 1]?.startsWith("PostHog Wizard Run:") && |
313 | | - lines[i + 2]?.startsWith("=".repeat(60)) |
314 | | - ) { |
315 | | - const timestampStr = lines[i + 1].replace("PostHog Wizard Run: ", "").trim(); |
316 | | - const headerTime = new Date(timestampStr); |
317 | | - |
318 | | - // If this header is at or after our adjusted start time, this could be our run |
319 | | - if (headerTime >= adjustedStartTime) { |
320 | | - if (captureStart === -1) { |
321 | | - // First matching header - start capturing from here |
322 | | - captureStart = i; |
323 | | - } else { |
324 | | - // Found another header after ours - stop capturing before this |
325 | | - captureEnd = i; |
326 | | - break; |
327 | | - } |
328 | | - } |
329 | | - } |
330 | | - } |
331 | | - |
332 | | - if (captureStart === -1) { |
333 | | - return null; |
334 | | - } |
335 | | - |
336 | | - // Extract the lines for this run |
337 | | - const runLines = lines.slice(captureStart, captureEnd); |
338 | | - return runLines.join("\n").trim(); |
339 | | - } catch { |
340 | | - return null; |
341 | | - } |
342 | | -} |
343 | | - |
344 | | -/** |
345 | | - * Save wizard logs for a run to a file in the app directory. |
346 | | - */ |
347 | | -export function saveWizardLogs(appPath: string, runStartTime: Date): string | null { |
348 | | - const logs = extractWizardLogs(runStartTime); |
349 | | - if (!logs) { |
350 | | - return null; |
351 | | - } |
352 | | - |
353 | | - const logFileName = "wizard-run.log"; |
354 | | - const logFilePath = join(appPath, logFileName); |
355 | | - |
356 | | - try { |
357 | | - writeFileSync(logFilePath, logs); |
358 | | - return logFilePath; |
359 | | - } catch { |
360 | | - return null; |
361 | | - } |
362 | | -} |
0 commit comments