UAT/build_hub.mjs

302 lines
16 KiB
JavaScript

import fs from "fs";
const BASE = "/Users/paige.petrone/messingaround";
const rm = fs.readFileSync(`${BASE}/Web Team ServiceMeow - Roadmap.html`, "utf8");
const ut = fs.readFileSync(`${BASE}/UAT-Outreach-Tracker.html`, "utf8");
const newMid = fs.readFileSync(`${BASE}/uat_new_section.js`, "utf8");
const extract = html => {
const style = html.match(/<style>([\s\S]*?)<\/style>/)[1];
const body = html.match(/<body>([\s\S]*?)<script>/)[1];
const script = html.match(/<script>([\s\S]*?)<\/script>/g).pop().replace(/<\/?script>/g, "");
return { style, body, script };
};
const R = extract(rm), U = extract(ut);
// drop the redundant per-pane title (hub bar + tabs already say which tab you're on)
R.body = R.body.replace(
"<h1>📋 ServiceMeow — Daily &amp; Roadmap <span class=\"wk-pill\" id=\"wkPill\"></span></h1>\n <div class=\"date\" id=\"today\"></div>",
"<span class=\"wk-pill\" id=\"wkPill\"></span>\n <div class=\"date\" id=\"today\" hidden></div>");
// ---- UAT CSS tweaks ----
let cs = U.style
.replace(" padding: 32px 16px 64px;\n", "")
.replace("h1 { font-size: 24px; font-weight: 700; }", "#tab-uat h1 { font-size: 22px; font-weight: 700; }")
.replace("header { display: flex;", "#tab-uat header { display: flex;")
.replace("button, select, label.filebtn {", "#tab-uat button, #tab-uat select, #tab-uat label.filebtn {")
.replace("button:hover, select:hover {", "#tab-uat button:hover, #tab-uat select:hover {")
.replace(".chip {", ".uchip {").replace(".chip .n", ".uchip .n").replace(".chip .l", ".uchip .l");
for (let i = 0; i < 5; i++) cs = cs.split(`.chip.s${i}`).join(`.uchip.s${i}`);
cs = cs.replace(".empty { text-align: center;", ".uempty { text-align: center;");
cs = cs.replace(
".rowwrap { border-bottom: 1px solid #f0f2f8; display: grid; grid-template-columns: 30px 1fr; gap: 2px 6px; align-items: center; }",
".rowwrap { border-bottom: 1px solid #f0f2f8; display: grid; grid-template-columns: 30px 30px 1fr; gap: 2px 6px; align-items: center; }");
cs = cs.replace(".rowwrap .uat-line { grid-column: 2; }", ".rowwrap .uat-line { grid-column: 3; }");
cs += `
/* launch-aware additions */
.uat-banner { display:flex; align-items:center; gap:10px; flex-wrap:wrap; background:#fff8ef; border:1px solid #f3c18f; color:#7a4d12; border-radius:12px; padding:12px 16px; margin:14px 0; font-size:14px; font-weight:600; }
.uat-banner .b-sub { font-weight:400; font-size:12.5px; color:#a06a20; }
.launch-cards { display:flex; gap:12px; flex-wrap:wrap; margin:16px 0 18px; }
.lcard { background:var(--card); border:1px solid var(--border); border-radius:14px; padding:12px 16px; min-width:230px; flex:1; box-shadow:0 1px 3px rgba(20,30,60,.05); }
.lcard h3 { font-size:13.5px; margin-bottom:2px; }
.lcard .rule { font-size:11.5px; color:var(--muted); margin-bottom:8px; }
.lcard .lnext { font-size:14.5px; font-weight:700; }
.lcard .lnext .fz { color:#b0721f; }
.lcard .lcount { margin-top:6px; font-size:12px; color:var(--muted); }
.lcard .lcount b { color:var(--text); }
.lcard .lmore { margin-top:4px; font-size:11.5px; color:var(--muted); }
.lcard.hot { border-color:#f3c18f; background:linear-gradient(180deg,#fffaf2,#fff); }
.bottombtn { width:26px; height:26px; border-radius:50%; padding:0; border:1.5px solid var(--border); background:#fff; color:var(--muted); font-size:11px; line-height:1; cursor:pointer; display:flex; align-items:center; justify-content:center; transition:all .12s; }
.bottombtn:hover { border-color:var(--accent); color:var(--accent); background:var(--accent-soft); }
.bottombtn.on { background:#4a5266; border-color:#4a5266; color:#fff; }
.bsec { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.bsec .blaunch { font-size:13.5px; font-weight:700; color:var(--text); }
.bsec .bfreeze { font-size:12.5px; font-weight:600; color:#b0721f; background:#fff3e0; border-radius:999px; padding:3px 10px; }
.bsec .bdays { font-size:11.5px; font-weight:700; border-radius:999px; padding:3px 10px; }
.bdays.urgent { background:#fdecea; color:#c0392b; }
.bdays.soon { background:#fff3e0; color:#b0721f; }
.bdays.later { background:#eef1f8; color:#5a6478; }
.bsec .bsub { font-size:11.5px; color:var(--muted); }
.bsec .count { margin-left:auto; font-weight:500; color:var(--muted); font-size:11px; }
.bottom-zone { margin-top:8px; border-top:1.5px dashed #e3e6ef; padding-top:2px; }
.bottom-zone .bz-label { font-size:10.5px; text-transform:uppercase; letter-spacing:.07em; color:var(--muted); padding:8px 10px 0; }
.secbody .row.dimmed { opacity:.82; }
/* nearest-launch section = most prominent */
.section.next { border:1.5px solid #f3c18f; background:linear-gradient(180deg,#fffaf2 0%,#fff 55%); box-shadow:0 2px 12px rgba(180,110,20,.14); }
.bnext { font-size:10.5px; font-weight:800; letter-spacing:.06em; color:#b0721f; background:#fff3e0; border:1px solid #f3c18f; border-radius:999px; padding:3px 10px; }
`;
// ---- UAT HTML tweaks ----
let ub = U.body
.replace(/class="chip s(\d)"/g, 'class="uchip s$1"')
.replace(/class="empty"/g, 'class="uempty"')
.replace(
"Statuses and field edits are saved in this browser per ticket ID",
"Use ⬇ to send a story to the bottom of its launch section (⬆ brings it back). Statuses and field edits are saved in this browser per ticket ID");
ub = ub.replace('<div class="summary">',
'<div class="uat-banner" id="uatBanner" style="display:none"></div>\n <div class="launch-cards" id="launchCards"></div>\n\n <div class="summary">');
// ---- UAT JS renames (avoid collisions with roadmap globals) ----
let us = U.script
.replace(/(?<![\w$])esc\(/g, "escUat(")
.replace(/(?<![\w$])setStatus\b/g, "setUatStatus")
.replace(/(?<![\w$])statusOf\b/g, "uatStatusOf")
.replace(/(?<![\w$])render\b/g, "uatRender");
us = us.replace('["dragenter", "dragover"].forEach(ev => document.addEventListener(ev, e => {',
'const uatPane = document.getElementById("tab-uat");\n["dragenter", "dragover"].forEach(ev => uatPane.addEventListener(ev, e => {');
us = us.replace('document.addEventListener("drop", e => {', 'uatPane.addEventListener("drop", e => {');
// wire up the send-to-bottom / restore button
us = us.replace(' const holdBtn = e.target.closest("[data-hold]");',
' const botBtn = e.target.closest("[data-bottom]");\n if (botBtn) { moveBottom(botBtn.dataset.bottom); return; }\n const holdBtn = e.target.closest("[data-hold]");');
// ---- replace Grouping..Events region with the launch-cycle implementation ----
const start = us.indexOf("// ---------- Grouping ----------");
const end = us.indexOf("// ---------- Events ----------");
if (start === -1 || end === -1) throw new Error("UAT script regions not found");
us = us.slice(0, start) + newMid + "\n" + us.slice(end);
const defs = (us.match(/function escUat\(/g) || []).length;
if (defs !== 1) throw new Error("escUat defined " + defs + " times");
// sanity: no leftover un-renamed globals that collide with the roadmap script
for (const bad of ["function esc(", "function setStatus(", "function statusOf(", "function render("]) {
if (us.includes(bad)) throw new Error("leftover collision: " + bad);
}
// ---- tab bar ----
const tabCss = `
/* ---------- hub tabs ---------- */
.hubbar { max-width: 1760px; margin: 0 auto; padding: 12px 20px 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hubbar .hub-title { font-size: 17px; font-weight: 800; letter-spacing: .01em; }
.hubbar .hub-date { color: var(--muted); font-size: 13px; }
.tabbar { display: flex; gap: 6px; margin: 10px 0 0; }
.tabbtn { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 13.5px; font-weight: 700;
border: 1.5px solid var(--border); background: #fff; color: #4a5266; border-radius: 10px; padding: 7px 16px; cursor: pointer; transition: all .12s; }
.tabbtn:hover { border-color: var(--accent); color: var(--accent); }
.tabbtn.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(74,108,247,.3); }
.tabbtn .tbadge { font-size: 11px; font-weight: 800; background: #fdecea; color: #c0392b; border-radius: 999px; padding: 2px 8px; }
.tabbtn.active .tbadge { background: rgba(255,255,255,.28); color: #fff; }
.tabpane { display: none; }
.tabpane.active { display: block; }
#tab-uat .container { max-width: 1760px; padding: 4px 20px 48px; }
#tab-uat .section-head { padding: 14px 12px 6px; }
/* Web Alignment tab */
.wa-wrap { max-width: 1100px; margin: 0 auto; }
.wa-when { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--accent-soft); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin: 4px 0 14px; font-size: 14px; }
.wa-when .wa-sub { color: var(--muted); font-size: 12.5px; }
.wa-when.today { background: #fff8ef; border-color: #f3c18f; font-weight: 600; }
.wa-added { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
/* WA sub-items */
.wa-subs { margin: 1px 0 6px 36px; }
.wa-subrow { font-size: 13px !important; padding: 4px 6px !important; background: #fbfcff; }
.wa-subrow input { width: 15px !important; height: 15px !important; min-width: 15px !important; }
.wa-subcnt { font-size: 10.5px; font-weight: 700; color: #5a6478; background: #eef1f8; border-radius: 999px; padding: 1px 7px; white-space: nowrap; }
.wa-addsub { font-size: 11px; font-weight: 600; border: 1px dashed #c4c9d9; background: #fff; color: var(--muted); border-radius: 7px; padding: 2px 9px; cursor: pointer; white-space: nowrap; font-family: inherit; }
.wa-addsub:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.wa-subadd { margin: 2px 0 4px; }
.wa-subadd input { width: 100%; padding: 6px 10px; border: 1.5px solid var(--accent); border-radius: 8px; font: inherit; font-size: 13px; }
/* Backup / restore */
.hub-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.hub-actions .mini-btn, .hub-actions label.mini-btn { cursor: pointer; }
/* de-clutter: the hub bar already carries the title & date */
#tab-roadmap .page-header { display: none; }
#tab-roadmap .page { padding-top: 4px; }
.hubbar .hub-wk { margin-left: 0; }
#tab-uat footer { margin-top: 16px; font-size: 11.5px; }
#tab-uat header h1 { display: none; }
#tab-uat .sub { margin-top: 0; }
`;
const tabHtml = `
<div class="hubbar">
<div class="hub-title">🐱 ServiceMeow HQ</div>
<div class="hub-date" id="hubDate"></div>
<div class="hub-actions">
<button class="mini-btn" onclick="exportBackup()" title="Download all ServiceMeow browser-saved data as a JSON file">⬇ Export backup</button>
<label class="mini-btn" title="Restore saved data from an exported JSON file (overwrites matching keys)">⬆ Import backup<input type="file" accept="application/json,.json" hidden onchange="if(this.files[0]){importBackup(this.files[0]);} this.value=''"></label>
</div>
<div class="tabbar">
<button class="tabbtn" id="tabbtn-roadmap" onclick="switchTab('roadmap')">📋 Roadmap &amp; Daily</button>
<button class="tabbtn" id="tabbtn-uat" onclick="switchTab('uat')">🧪 UAT Launches <span class="tbadge" id="uatBadge">🚀</span></button>
<button class="tabbtn" id="tabbtn-wa" onclick="switchTab('wa')">🤝 Web Alignment <span class="tbadge" id="waBadge">—</span></button>
</div>
</div>
`;
const tabJs = `
/* ================= HUB TABS ================= */
const HUB_TABS = ["roadmap", "uat", "wa"];
function switchTab(name) {
HUB_TABS.forEach(t => {
const pane = document.getElementById("tab-" + t), btn = document.getElementById("tabbtn-" + t);
if (pane) pane.classList.toggle("active", t === name);
if (btn) btn.classList.toggle("active", t === name);
});
localStorage.setItem("sm-hub-tab", name);
if (name === "roadmap" && window.refreshAll) refreshAll();
if (name === "uat" && window.uatRender) uatRender();
if (name === "wa" && window.renderWa) renderWa();
}
document.getElementById("hubDate").textContent =
new Date().toLocaleDateString(undefined, { weekday: "long", year: "numeric", month: "long", day: "numeric" });
// the week pill used to sit alone under a removed page header — pull it into the hub bar
const wkPill = document.getElementById("wkPill");
if (wkPill) { wkPill.classList.add("hub-wk"); document.getElementById("hubDate").insertAdjacentElement("afterend", wkPill); }
switchTab(localStorage.getItem("sm-hub-tab") || "roadmap");
/* ================= BACKUP / RESTORE ================= */
// All app data lives under these key prefixes (covers date-stamped keys too,
// e.g. sm-mydaily-YYYY-MM-DD and ba-checklist-v3-YYYY-MM-DD).
const BACKUP_PREFIXES = ["sm-", "smh-", "uat-", "ba-"];
function exportBackup() {
const data = {};
for (let i = 0; i < localStorage.length; i++) {
const k = localStorage.key(i);
if (BACKUP_PREFIXES.some(p => k.startsWith(p))) data[k] = localStorage.getItem(k);
}
const payload = {
app: "ServiceMeow-HQ",
version: 1,
exportedAt: new Date().toISOString(),
keyCount: Object.keys(data).length,
data
};
const blob = new Blob([JSON.stringify(payload, null, 2)], { type: "application/json" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
const d = new Date(), p2 = n => String(n).padStart(2, "0");
a.download = "servicemow-backup-" + d.getFullYear() + p2(d.getMonth() + 1) + p2(d.getDate()) + "-" + p2(d.getHours()) + p2(d.getMinutes()) + ".json";
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(() => URL.revokeObjectURL(a.href), 5000);
}
function importBackup(file) {
const reader = new FileReader();
reader.onerror = () => alert("Could not read that file.");
reader.onload = () => {
let payload;
try { payload = JSON.parse(reader.result); } catch (e) { alert("That file is not valid JSON."); return; }
const data = (payload && typeof payload === "object" && payload.data && typeof payload.data === "object") ? payload.data : payload;
if (!data || typeof data !== "object") { alert("No backup data found in that file."); return; }
// Resolve values: strings pass through, objects get re-stringified (raw
// localStorage values are strings, so both shapes round-trip safely).
const resolved = {};
Object.keys(data).forEach(k => {
const v = data[k];
if (v === null || v === undefined) return;
if (typeof v === "string") resolved[k] = v;
else { try { resolved[k] = JSON.stringify(v); } catch (e) { /* skip unserializable */ } }
});
const keys = Object.keys(resolved).filter(k => BACKUP_PREFIXES.some(p => k.startsWith(p))).sort();
if (!keys.length) { alert("No ServiceMeow keys found in that backup file."); return; }
if (!confirm("Restore " + keys.length + " saved values from " + file.name + "?\\n\\nValues with matching keys will be overwritten with the backup. New keys will be added. Unrelated data is left untouched.")) return;
keys.forEach(k => localStorage.setItem(k, resolved[k]));
alert("Restored " + keys.length + " values. Reloading to pick up the changes…");
location.reload();
};
reader.readAsText(file);
}
`;
const waHtml = `
<div id="tab-wa" class="tabpane">
<div class="page">
<div class="wa-wrap">
<div class="card">
<div class="card-head">
<div>
<h2>🤝 Web Alignment Team — bring up at Monday's sync</h2>
<div class="hint">Mondays 9:00 AM MT · check an item off once it's been raised — it moves to Covered until you clear it</div>
</div>
<button class="mini-btn" onclick="waClearCovered()" title="Remove all covered items">Clear covered</button>
</div>
<div class="wa-when" id="waWhen"></div>
<div class="add-row">
<input type="text" id="waInput" placeholder="What do you need to raise with the Web Alignment Team? (decision, blocker, ask, alignment needed…)" onkeydown="if(event.key==='Enter') addWaItem()">
<button onclick="addWaItem()">Add</button>
</div>
<div id="waList"></div>
</div>
</div>
</div>
</div>
`;
const waJs = fs.readFileSync(`${BASE}/wa_section.js`, "utf8");
const out = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ServiceMeow HQ — Roadmap + UAT Launches</title>
<style>
${R.style}
${tabCss}
${cs}
</style>
</head>
<body>
${tabHtml}
<div id="tab-roadmap" class="tabpane">
${R.body}
</div>
<div id="tab-uat" class="tabpane">
${ub}
</div>
${waHtml}
<script>
${R.script}
</script>
<script>
${us}
</script>
<script>
${tabJs}
</script>
<script>
${waJs}
</script>
</body>
</html>
`;
fs.writeFileSync(`${BASE}/ServiceMeow-HQ.html`, out);
console.log("wrote ServiceMeow-HQ.html", out.length, "bytes");