/** * 确认 xelement 的坐标/版本,并打印 XElementBehaviors 的真实签名。 * 用法: node scripts/xelement-probe.mjs [version] */ import { spawnSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; const VERSION = process.argv[2] || '4.1.0'; const WORK = 'C:\\Android\\probe'; const BASE = 'https://repo1.maven.org/maven2/org/lynxsdk/lynx'; async function listDir(url) { const res = await fetch(url, { signal: AbortSignal.timeout(60000) }); if (!res.ok) return { status: res.status, files: [] }; const html = await res.text(); const files = [...html.matchAll(/href="([^"]+)"/g)] .map((m) => m[1]) .filter((x) => !x.startsWith('..') && !x.startsWith('http') && !x.endsWith('/')); return { status: res.status, files }; } const root = await listDir(`${BASE}/`); console.log('== org/lynxsdk/lynx 下的 artifact:'); console.log(root.files.join(' ')); for (const artifact of ['xelement', 'xelement-behaviors', 'x-element']) { const info = await listDir(`${BASE}/${artifact}/${VERSION}/`); console.log(`\n== ${artifact}/${VERSION} → HTTP ${info.status}`); const aar = info.files.find((f) => f.endsWith('.aar')); if (!aar) { console.log(' 没有 aar:', info.files.slice(0, 8).join(' ')); continue; } const filePath = path.join(WORK, aar); if (!fs.existsSync(filePath)) { console.log(' 下载', aar); const res = await fetch(`${BASE}/${artifact}/${VERSION}/${aar}`, { signal: AbortSignal.timeout(600000) }); fs.writeFileSync(filePath, Buffer.from(await res.arrayBuffer())); } const dir = path.join(WORK, `x-${artifact}`); fs.rmSync(dir, { recursive: true, force: true }); fs.mkdirSync(dir, { recursive: true }); spawnSync('tar', ['-xf', filePath, '-C', dir]); const classesJar = path.join(dir, 'classes.jar'); const res = spawnSync('jar', ['tf', classesJar], { encoding: 'utf8' }); const classes = (res.stdout || '').split('\n').filter((c) => /Behaviors?\.class$/.test(c)); console.log(' Behaviors 类:', classes.slice(0, 5).join(' ') || '(没找到)'); for (const cls of classes.slice(0, 2)) { const name = cls.replace(/\.class$/, '').replace(/\//g, '.'); console.log(`\n===== ${name} =====`); const jp = spawnSync('javap', ['-classpath', classesJar, name], { encoding: 'utf8' }); console.log((jp.stdout || jp.stderr || '').split('\n').filter((l) => /public/.test(l)).slice(0, 20).join('\n')); } }