#!/usr/bin/env node import { execFileSync } from 'node:child_process' import { readFileSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import path from 'node:path' import { fileURLToPath } from 'node:url' const cwd = fileURLToPath(new URL('..', import.meta.url)) const packOutput = process.platform === 'win32' ? execFileSync( process.env.ComSpec ?? 'cmd.exe', ['/d', '/s', '/c', 'npm.cmd pack --json --ignore-scripts'], { cwd, encoding: 'utf8', env: { ...process.env, npm_config_cache: path.join(tmpdir(), 'xuqm-rn-npm-cache') }, }, ) : execFileSync('npm', ['pack', '--json', '--ignore-scripts'], { cwd, encoding: 'utf8', env: { ...process.env, npm_config_cache: path.join(tmpdir(), 'xuqm-rn-npm-cache') }, }) const result = JSON.parse(packOutput)[0] const required = [ 'android/src/main/AndroidManifest.xml', 'android/src/main/java/com/xuqm/update/XuqmBundleModule.java', 'android/src/main/java/com/xuqm/update/XuqmAppUpdateModule.java', 'android/build.gradle', 'android/xuqm-bundles.gradle', 'scripts/xuqm-rn.mjs', 'scripts/xuqm-config.mjs', 'scripts/xuqm_release.mjs', 'src/UpdateSDK.ts', 'src/NativeBundle.ts', 'src/NativeAppUpdate.ts', 'src/releaseSet.ts', 'react-native.config.js', ] const files = new Set(result.files.map(file => file.path)) const missing = required.filter(file => !files.has(file)) rmSync(path.join(cwd, result.filename), { force: true }) if (missing.length) throw new Error(`Published package is missing:\n${missing.join('\n')}`) const pkg = JSON.parse(readFileSync(path.join(cwd, 'package.json'), 'utf8')) if (!pkg.bin?.['xuqm-rn']) throw new Error('package.json bin.xuqm-rn is missing') if (files.has('src/md5.ts') || [...files].some(file => file.startsWith('ios/'))) { throw new Error('Android-only package must not publish legacy MD5 or unverified iOS code') } console.log(`Package content verified (${result.files.length} files).`)