From 5fc08bc92679fdc2020584b5a23c1bb5554c196a Mon Sep 17 00:00:00 2001 From: casianaoprut Date: Wed, 28 Feb 2024 19:14:25 +0200 Subject: [PATCH] legacy summary flow update --- src/report/legacy-report-extactor.ts | 5 +++-- src/runner/mission-summary-runner.ts | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/report/legacy-report-extactor.ts b/src/report/legacy-report-extactor.ts index e7740e1..a2f85e2 100644 --- a/src/report/legacy-report-extactor.ts +++ b/src/report/legacy-report-extactor.ts @@ -5,7 +5,7 @@ import {CommandSummary} from '../model/summary/CommandSummary' const MISSION_SUMMARY_HEADER = '------------------- Mission Summary -------------------' const MISSION_SUMMARY_FOOTER = '_______________________container_______________________' -export function buildLegacyMissionSummary(missionReportContent: string) { +export function buildLegacyMissionSummary(missionReportContent: string): MissionSummary { const missionSummary = new MissionSummary() missionSummary.missionName = extractMissionName(missionReportContent) const summaryText = extractSummaryText(missionReportContent) @@ -21,7 +21,8 @@ function extractMissionName(fileContent: string): string { } function extractSummaryText(fileContent: string): string { - let summaryText = fileContent.split(MISSION_SUMMARY_HEADER)[1] + const text = fileContent.split(MISSION_SUMMARY_HEADER) + let summaryText = text[text.length - 1] summaryText = summaryText.split(MISSION_SUMMARY_FOOTER)[0] if (!summaryText) { throw new Error('Summary text not found in the file.') diff --git a/src/runner/mission-summary-runner.ts b/src/runner/mission-summary-runner.ts index 4887181..d2a8e25 100644 --- a/src/runner/mission-summary-runner.ts +++ b/src/runner/mission-summary-runner.ts @@ -1,6 +1,6 @@ import AdmZip from 'adm-zip' import {MISSION_RESULT_ARCHIVE_NAME} from '../context/context-variable-provider' -import fs from 'fs' +import fs from 'fs-extra' import path from 'node:path' import {exec} from 'node:child_process' import {OS, osType} from '@dxworks/cli-common' @@ -48,10 +48,13 @@ export function buildAndOpenLegacySummary(zipPath: string): void { const fileContent = zip.readAsText(textFileEntry) const missionSummary = buildLegacyMissionSummary(fileContent) const legacyHtmlReport = generateHtmlReportContent(missionSummary) - const tempDir = fs.mkdtempSync('mission_summary-') - const tempHtmlPath = path.join(tempDir, 'MissionReport.html') + const summaryPath = path.resolve('./mission_summary') + if (fs.existsSync(summaryPath)) + fs.rmSync(summaryPath, {recursive: true, force: true}) + fs.mkdirSync(summaryPath) + const tempHtmlPath = path.join(summaryPath, 'MissionReport.html') fs.writeFileSync(tempHtmlPath, legacyHtmlReport) - const tempHtmlFolderPath = path.join(tempDir, 'html') + const tempHtmlFolderPath = path.join(summaryPath, 'html') fs.mkdirSync(tempHtmlFolderPath) const logFilesEntries = zip.getEntries().filter(entry => entry.entryName.endsWith('.log')).filter(entry => entry.entryName != 'mission-report.log')