chore: prep 0.1.2 release, tidy repo
This commit is contained in:
38
pikit-web/assets/releases-utils.js
Normal file
38
pikit-web/assets/releases-utils.js
Normal file
@@ -0,0 +1,38 @@
|
||||
export function shorten(text, max = 90) {
|
||||
if (!text || typeof text !== "string") return text;
|
||||
return text.length > max ? `${text.slice(0, max - 3)}...` : text;
|
||||
}
|
||||
|
||||
export function createReleaseLogger(logUi = () => {}) {
|
||||
let lines = [];
|
||||
let lastMessage = null;
|
||||
const state = { el: null };
|
||||
|
||||
function render() {
|
||||
if (state.el) {
|
||||
state.el.textContent = lines.join("\n");
|
||||
state.el.scrollTop = 0;
|
||||
}
|
||||
}
|
||||
|
||||
function log(msg) {
|
||||
if (!msg) return;
|
||||
const plain = msg.trim();
|
||||
if (plain === lastMessage) return;
|
||||
lastMessage = plain;
|
||||
const ts = new Date().toLocaleTimeString();
|
||||
const line = `${ts} ${msg}`;
|
||||
lines.unshift(line);
|
||||
lines = lines.slice(0, 120);
|
||||
render();
|
||||
const lvl = msg.toLowerCase().startsWith("error") ? "error" : "info";
|
||||
logUi(`Update: ${msg}`, lvl);
|
||||
}
|
||||
|
||||
function attach(el) {
|
||||
state.el = el;
|
||||
render();
|
||||
}
|
||||
|
||||
return { log, attach, getLines: () => lines.slice() };
|
||||
}
|
||||
Reference in New Issue
Block a user