import "./styles.css";
const state = {
tab: "structure",
info: null,
};
const tabs = [
{ id: "structure", label: "目录解剖" },
{ id: "modes", label: "开发 vs 生产" },
{ id: "scripts", label: "构建脚本" },
];
function escapeHtml(value) {
return value
.replaceAll("&", "&")
.replaceAll("<", "<")
.replaceAll(">", ">")
.replaceAll('"', """);
}
function row(label, value, testid) {
return `
| ${escapeHtml(label)} | ${escapeHtml(value)} |
`;
}
function structure(info) {
const files = [
["forge.config.ts", "Forge 8 + Vite 插件"],
["vite.main.config.mts", "主进程构建"],
["vite.preload.config.mts", "preload 构建(preload.cjs)"],
["vite.renderer.config.mts", "渲染进程构建"],
["main/index.ts", "主进程入口"],
["preload/index.ts", "桥"],
["shared/ipc.ts", "通道与类型"],
["src/renderer.ts", "页面脚本"],
];
return `
应用信息
${row("名称", info.appName)}
${row("版本", info.appVersion)}
${row("appPath", info.appPath, "info-app-path")}
${row("resourcesPath", info.resourcesPath, "info-resources")}
关键文件
${files.map(([file, role]) => `
${escapeHtml(file)}${escapeHtml(role)}
`).join("")}
`;
}
function modes(info) {
return `
两种运行方式
| 项 | 当前值 |
${row("isPackaged", String(info.isPackaged))}
${row("有 dev server URL", String(info.hasDevServerUrl))}
${row("页面来源", info.hasDevServerUrl ? "http://localhost(Vite)" : "本地文件(.vite/renderer)")}
开发时 HMR 来自 Vite;打包后没有 dev server,路径与 CSP 都要按本地文件处理。
`;
}
function scripts(info) {
const entries = Object.entries(info.scripts);
return `
package.json scripts
| 脚本 | 命令 |
${entries.map(([name, command]) => `${escapeHtml(name)} | ${escapeHtml(command)} |
`).join("")}
start 走开发服务器;package 生成可运行目录;make 生成安装包(本章只用到 package)。
`;
}
function render() {
const root = document.querySelector("#app");
if (!root)
return;
const info = state.info;
const body = !info
? `正在读取应用信息…
`
: state.tab === "structure"
? structure(info)
: state.tab === "modes"
? modes(info)
: scripts(info);
root.innerHTML = `
${body}`;
for (const button of root.querySelectorAll("[data-tab]")) {
button.addEventListener("click", () => {
const tab = button.dataset.tab;
if (tab === "structure" || tab === "modes" || tab === "scripts") {
state.tab = tab;
render();
}
});
}
}
async function boot() {
state.info = await window.api.info();
render();
window.__setTab = (tab) => {
state.tab = tab;
render();
};
window.__snapshot = () => ({
tab: state.tab,
isPackaged: state.info?.isPackaged,
scripts: Object.keys(state.info?.scripts ?? {}).length,
});
}
void boot();
//# sourceMappingURL=renderer.js.map