import { existsSync, readFileSync, writeFileSync } from "node:fs";

const iosConfigPath = "ios/App/App/capacitor.config.json";

if (existsSync(iosConfigPath)) {
  const config = JSON.parse(readFileSync(iosConfigPath, "utf8"));
  const classList = Array.isArray(config.packageClassList) ? config.packageClassList : [];
  config.packageClassList = [
    ...classList.filter((className) => className !== "FilesystemPlugin" && className !== "CraftLaunchFilesPlugin"),
    "CraftLaunchFilesPlugin"
  ];
  writeFileSync(iosConfigPath, `${JSON.stringify(config, null, "\t")}\n`);
}

console.log("Registered CraftLaunchFiles native plugin.");
