mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-09 03:30:48 +08:00
- 在 oclaw/ 下重新初始化 Git 仓库 - 补齐子仓库 .gitignore,避免提交本地运行态数据(_local、node_modules、logs 等) - 提交当前工程代码与配置 Made-with: Cursor
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
const fs = require("node:fs");
|
|
const path = require("node:path");
|
|
const { Resvg } = require("@resvg/resvg-js");
|
|
const pngToIcoModule = require("png-to-ico");
|
|
const pngToIco = typeof pngToIcoModule === "function" ? pngToIcoModule : pngToIcoModule.default;
|
|
|
|
async function main() {
|
|
const desktopRoot = path.resolve(__dirname, "..");
|
|
const svgPath = path.resolve(desktopRoot, "..", "src", "admin", "static", "oliver.svg");
|
|
const assetsDir = path.join(desktopRoot, "assets");
|
|
const icoPath = path.join(assetsDir, "oclaw.ico");
|
|
|
|
if (!fs.existsSync(svgPath)) {
|
|
throw new Error(`logo not found: ${svgPath}`);
|
|
}
|
|
fs.mkdirSync(assetsDir, { recursive: true });
|
|
const svg = fs.readFileSync(svgPath, "utf8");
|
|
|
|
const sizes = [16, 24, 32, 48, 64, 128, 256];
|
|
const pngBuffers = [];
|
|
for (const size of sizes) {
|
|
const resvg = new Resvg(svg, {
|
|
fitTo: { mode: "width", value: size },
|
|
background: "rgba(0,0,0,0)",
|
|
});
|
|
const pngData = resvg.render().asPng();
|
|
pngBuffers.push(Buffer.from(pngData));
|
|
}
|
|
|
|
const ico = await pngToIco(pngBuffers);
|
|
fs.writeFileSync(icoPath, ico);
|
|
process.stdout.write(`Generated ${icoPath}\n`);
|
|
}
|
|
|
|
main().catch((err) => {
|
|
process.stderr.write(`${String(err && err.message ? err.message : err)}\n`);
|
|
process.exit(1);
|
|
});
|