/**
 * Перед `electron-builder --mac`: npm ставит sharp только под CPU хоста.
 * В release идут x64 и arm64 — в .app должны быть оба набора @img/sharp-darwin-*.
 */
import path from 'node:path';
import { fileURLToPath } from 'node:url';

import {
  ensureReleaseNativeDeps,
  MAC_SHARP_IMG_PACKAGES,
  sharpImgPackagesToInstall,
} from './release-native-prep.mjs';

/** @deprecated use sharpImgPackagesToInstall(root, MAC_SHARP_IMG_PACKAGES) */
export function macSharpImgPackagesToInstall(root) {
  return sharpImgPackagesToInstall(root, MAC_SHARP_IMG_PACKAGES);
}

/**
 * @param {string} root
 * @param {{ runInstall?: boolean }} [opts]
 */
export function ensureMacSharpBinaries(root, opts = {}) {
  ensureReleaseNativeDeps(root, 'mac', opts);
}

const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
if (isMain) {
  const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
  if (process.platform !== 'darwin') {
    console.warn('[release-mac-prep] skipped: not macOS (no dual-arch sharp prep needed here)');
    process.exit(0);
  }
  ensureMacSharpBinaries(root);
}
