storebound/cli/aab.ts

18 lines
1 KiB
TypeScript

// Offline: what an Android App Bundle says about itself, without a config or credentials (CI reads the version code
// before it uploads, instead of unzipping the AAB or asking the Play API).
// storebound aab <file.aab> [--json]
import { createHash } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import type { Args } from './lib/args';
import { aabInfo } from './lib/gradle';
import { log, printJson } from './lib/log';
export async function run(args: Args): Promise<void> {
const file = args._.find(x => x.endsWith('.aab'));
if (!file) throw new Error('usage: storebound aab <file.aab> [--json]');
const data = readFileSync(resolve(file));
const info = { ...aabInfo(data), sha256: createHash('sha256').update(data).digest('hex'), bytes: data.length };
if (args.has('json')) { printJson(info); return; }
log('aab', `${info.packageName} ${info.versionName ?? '?'} (${info.versionCode}) · minSdk ${info.minSdk ?? '?'} · targetSdk ${info.targetSdk ?? '?'} · ${(info.bytes / 1e6).toFixed(1)} MB`);
}