front/scripts/postbuild-cleanup-dist.js
zzh b5edbb8447 feat: 页面背景预设与工作台增强,优化官网与登录体验
新增石米等淡色背景预设并设为默认,修复页面配置抽屉偶发不弹出问题,移除登录欢迎卡;同步 IDE 官网导航与背景样式,并扩展管理端工作台统计展示。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 10:59:10 +08:00

81 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const dist = path.join(root, 'dist');
const siteSrc = path.join(root, 'IDE官网');
const legacyLoginDir = path.join(dist, 'login');
const siteDir = path.join(dist, 'site');
/** Avoid fs.cpSync merge into dist/assets (conflicts with Vite + can crash on Windows). */
function copyDirSync(src, dest, options = {}) {
const { skipDirNames = new Set() } = options;
fs.mkdirSync(dest, { recursive: true });
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
if (entry.isDirectory() && skipDirNames.has(entry.name)) continue;
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirSync(srcPath, destPath, options);
continue;
}
if (entry.isFile()) {
fs.copyFileSync(srcPath, destPath);
}
}
}
/** 生产环境首页在 /,静态资源在 /site/assets/;勿用 base href(会把地址栏带到 /site/) */
function rewriteSiteAssetPaths(content) {
return content
.replace(/((?:href|src)=["'])assets\//g, '$1/site/assets/')
.replace(/(["'])assets\//g, '$1/site/assets/');
}
if (fs.existsSync(legacyLoginDir)) {
fs.rmSync(legacyLoginDir, { recursive: true, force: true });
console.log('[postbuild] removed dist/login (conflicts with SPA route /login)');
}
function copyOfficialSite() {
if (!fs.existsSync(siteSrc) || !fs.existsSync(dist)) {
return;
}
if (fs.existsSync(siteDir)) {
fs.rmSync(siteDir, { recursive: true, force: true });
}
copyDirSync(siteSrc, siteDir, {
skipDirNames: new Set(['.well-known']),
});
for (const rel of ['index.html', '404.html', '9610.html']) {
const filePath = path.join(siteDir, rel);
if (!fs.existsSync(filePath)) continue;
const html = fs.readFileSync(filePath, 'utf8');
fs.writeFileSync(filePath, rewriteSiteAssetPaths(html), 'utf8');
}
const jsDir = path.join(siteDir, 'assets', 'js');
if (fs.existsSync(jsDir)) {
for (const name of fs.readdirSync(jsDir)) {
if (!name.endsWith('.js')) continue;
const filePath = path.join(jsDir, name);
const js = fs.readFileSync(filePath, 'utf8');
if (!js.includes('assets/')) continue;
fs.writeFileSync(filePath, rewriteSiteAssetPaths(js), 'utf8');
}
}
const src9610 = path.join(siteSrc, '9610.html');
if (fs.existsSync(src9610)) {
fs.copyFileSync(src9610, path.join(dist, '9610.html'));
}
console.log('[postbuild] copied official site to dist/site (assets under /site/assets)');
}
copyOfficialSite();