# 绕过 UI Pro 的 License 验证
set -euo pipefail
 
# 1. 禁用 module.mjs 的调用
MODULE="node_modules/@nuxt/ui-pro/dist/module.mjs"
if [[ -f $MODULE ]]; then
  sed -i.bak '/await validateLicense({.*rootDir })/s/^/\/\//; /^await validateLicense({.*rootDir })/s/^/\/\//' "$MODULE"
  rm -f "$MODULE.bak"
  echo "✅ module.mjs 已屏蔽"
fi
 
# 2. 直接“替换函数” fake 200
SHARED="node_modules/@nuxt/ui-pro/dist/shared"
JS=$(find "$SHARED" -maxdepth 1 -name 'ui-pro.*.mjs' | head -n1)
[[ -z $JS || ! -f $JS ]] && { echo "⚠️ ui-pro.*.mjs 未找到"; exit 0; }
 
cat <<'EOF' > tmp_func.mjs
async function validateLicense(opts) {
  /* --- patched --- */
  return { status: 200 }
}
EOF
 
sed -i.bak '/^async function validateLicense[^(]*(/,/^\}$/c\
async function validateLicense(opts) {\
  /* --- patched --- */\
  return { status: 200 }\
}\
' "$JS"
rm -f "$JS.bak" tmp_func.mjs
 
echo "✅ $JS 已 mock 完成"
echo "🎉  License ⛔ Done!"