function escapeHtml(text) { return text.replace(/[&<>"]/g, (char) => { if (char === "&") return "&"; if (char === "<") return "<"; if (char === ">") return ">"; return """; }); } function time(at) { return new Date(at).toLocaleTimeString("zh-CN", { hour12: false }); } function bytes(value) { return value < 1024 ? `${value} B` : `${(value / 1024).toFixed(1)} KB`; } function statusTag(status) { if (status === "pass") return 'PASS'; if (status === "fail") return 'FAIL'; if (status === "running") return 'RUN'; return 'PENDING'; } function stepRow(step, index) { return `
  • ${index + 1}
    ${escapeHtml(step.title)} ${statusTag(step.status)} ${step.ms ? `${step.ms}ms` : "—"}
    ${escapeHtml(step.log || "等待执行")}
  • `; } function artifactRow(row) { return ` ${escapeHtml(row.name)} ${bytes(row.bytes)} ${escapeHtml(row.sha256.slice(0, 16))}… `; } function checkRow(check) { return `
  • ${check.pass ? "PASS" : "FAIL"} ${escapeHtml(check.label)} ${escapeHtml(check.detail)}
  • `; } export function mountApp(root) { root.innerHTML = `

    发布流水线实验室

    预检 → 哈希 → 元数据 → feed → 报告(本地离线)
    offline —

    流水线

    —

      发布报告

      JSON

        产物与哈希

        —
        文件大小SHA-256

        生成的 feed

        releases.json
        
                  

        流水线自检

        —

          活动

          步骤 / 失败
            `; const score = root.querySelector('[data-testid="score"]'); const banner = root.querySelector('[data-testid="banner"]'); const stepSummary = root.querySelector('[data-testid="step-summary"]'); const stepsEl = root.querySelector('[data-testid="steps"]'); const reportEl = root.querySelector('[data-testid="report"]'); const artifactCount = root.querySelector('[data-testid="artifact-count"]'); const artifactsEl = root.querySelector('[data-testid="artifacts"]'); const feedEl = root.querySelector('[data-testid="feed"]'); const checksEl = root.querySelector('[data-testid="checks"]'); const checkCount = root.querySelector('[data-testid="check-count"]'); const eventsEl = root.querySelector('[data-testid="events"]'); let state = null; function renderSteps() { if (!state) return; if (stepsEl) stepsEl.innerHTML = state.steps.map(stepRow).join(""); if (stepSummary) { const summary = state.reportSummary; stepSummary.textContent = `${summary.passed}/${state.steps.length} 通过 · ${summary.failed} 失败 · ${summary.pending} 等待`; } if (banner) { banner.textContent = state.reportSummary.failed > 0 ? `流水线在失败步骤停止:${state.steps.find((step) => step.status === "fail")?.title ?? ""}` : `流水线通过:${state.currentVersion} → ${state.targetVersion},报告已写入`; banner.className = `banner ${state.reportSummary.failed ? "warn" : "ok"}`; } } function renderReport() { if (!state || !reportEl) return; reportEl.innerHTML = `
          • 报告路径${escapeHtml(state.reportPath)}
          • 当前版本${escapeHtml(state.currentVersion)}
          • 目标版本${escapeHtml(state.targetVersion)}
          • 步骤${state.steps.length}
          • 产物${state.artifacts.length}
          • `; } function renderArtifacts() { if (!state) return; if (artifactsEl) { artifactsEl.innerHTML = state.artifacts.map(artifactRow).join(""); } if (artifactCount) { artifactCount.textContent = `${state.artifacts.length} 个文件`; } if (feedEl) { feedEl.textContent = state.feedPreview || "(尚未生成)"; } } function renderChecks() { if (!state) return; if (checksEl) checksEl.innerHTML = state.checks.map(checkRow).join(""); if (checkCount) { const passed = state.checks.filter((check) => check.pass).length; checkCount.textContent = `${passed}/${state.checks.length} 通过`; } if (score) { score.textContent = `${state.score} / 100`; score.className = `pill ${state.score === 100 ? "ok-pill" : "bad-pill"}`; } } function renderEvents() { if (!eventsEl || !state) return; eventsEl.innerHTML = state.events.length === 0 ? `
          • 暂无活动
          • ` : state.events .slice(0, 8) .map((row) => `
          • ${time(row.at)} ${escapeHtml(row.kind)} ${escapeHtml(row.detail)}
          • `) .join(""); } function render(next) { state = next; renderSteps(); renderReport(); renderArtifacts(); renderChecks(); renderEvents(); } void window.api.pipeline.snapshot().then(render); window.api.pipeline.onEvent(() => { void window.api.pipeline.snapshot().then(render); }); root .querySelector('[data-testid="run"]') ?.addEventListener("click", async () => { render(await window.api.pipeline.run()); }); root .querySelector('[data-testid="inject"]') ?.addEventListener("click", async () => { render(await window.api.pipeline.inject()); }); window.__prepareShots = async (stage) => { document.body.dataset.shot = stage; if (stage === "failure") { render(await window.api.pipeline.inject()); document .querySelector(".pipeline-card") ?.scrollIntoView({ block: "start" }); return; } render(await window.api.pipeline.run()); if (stage === "artifacts") { document .querySelector(".artifacts-card") ?.scrollIntoView({ block: "start" }); } else { document .querySelector(".pipeline-card") ?.scrollIntoView({ block: "start" }); } }; window.__demo = async () => { const next = await window.api.pipeline.snapshot(); state = next; return { score: next.score, checks: next.checks.length, passed: next.checks.filter((check) => check.pass).length, steps: next.steps.length, passedSteps: next.steps.filter((step) => step.status === "pass").length, failedSteps: next.steps.filter((step) => step.status === "fail").length, pendingSteps: next.steps.filter((step) => step.status === "pending") .length, artifacts: next.artifacts.length, hashes: next.artifacts.filter((row) => row.sha256.length === 64).length, feedBytes: next.feedPreview.length, reportExists: next.checks.find((check) => check.id === "report")?.pass ?? false, reportSteps: next.checks.find((check) => check.id === "report-steps")?.detail === "5" ? 5 : 0, decision: next.steps.find((step) => step.id === "feed")?.status === "pass" ? "update" : "none", noNetwork: next.checks.find((check) => check.id === "offline")?.pass ?? false, }; }; } //# sourceMappingURL=App.js.map