const fs = require("fs");
const path = require("path");

// 写入 updateScript.js
const writeUpdateScript = () => {
  // 读取编译后的文件
  const filePath = path.join(__dirname, "dist/index.js");
  let content = fs.readFileSync(filePath, "utf8");
  // 替换 module.exports = PluginUpdate 为 window.PluginUpdate = PluginUpdate
  content = content.replace(
    /module\.exports\s*=\s*PluginUpdate/g,
    "window.PluginUpdate = PluginUpdate",
  );

  // 如果还有其他的导出，也一并处理
  content = content.replace(/module\.exports\s*=\s*([^;]+)/g, "window.$1 = $1");

  const targetPath = path.join(__dirname, "./dist/updateScript.js");
  // 写入修改后的文件
  fs.writeFileSync(targetPath, content);
  console.log("已替换 module.exports 为 window 全局变量");
};
writeUpdateScript();

const file = path.join(__dirname, "./public/install.vbs");
const targetPath = path.join(__dirname, "./dist/install.vbs");
fs.copyFileSync(file, targetPath);
