Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ import { t } from './utils/i18n';
import { getBooleanOption, getStringListOption } from './utils/options';
import { bundleLocationFields, locateZipEntry } from './utils/zip-range';

// parse* output is JSON so the bundleHash (content fingerprint) can be piped
// into jq; the raw bundle bytes are dropped — a Buffer preview is just noise.
function printPackageInfo({
bundleFile: _bundleFile,
...info
}: Record<string, unknown>) {
console.log(JSON.stringify(info, null, 2));
}

type PackageCommandOptions = Record<string, unknown> & {
appId?: string;
appKey?: string;
Expand Down Expand Up @@ -386,28 +395,28 @@ export const packageCommands = {
if (!fn?.endsWith('.app')) {
throw new Error(t('usageParseApp'));
}
console.log(await getAppInfo(fn));
printPackageInfo(await getAppInfo(fn));
},
parseIpa: async ({ args }: { args: string[] }) => {
const fn = args[0];
if (!fn?.endsWith('.ipa')) {
throw new Error(t('usageParseIpa'));
}
console.log(await getIpaInfo(fn));
printPackageInfo(await getIpaInfo(fn));
},
parseApk: async ({ args }: { args: string[] }) => {
const fn = args[0];
if (!fn?.endsWith('.apk')) {
throw new Error(t('usageParseApk'));
}
console.log(await getApkInfo(fn));
printPackageInfo(await getApkInfo(fn));
},
parseAab: async ({ args }: { args: string[] }) => {
const fn = args[0];
if (!fn?.endsWith('.aab')) {
throw new Error(t('usageParseAab'));
}
console.log(await getAabInfo(fn));
printPackageInfo(await getAabInfo(fn));
},
extractApk: async ({
args,
Expand Down
43 changes: 43 additions & 0 deletions tests/package.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, spyOn, test } from 'bun:test';
import { createHash } from 'crypto';
import fs from 'fs';
import os from 'os';
import path from 'path';
Expand Down Expand Up @@ -179,6 +180,48 @@ describe('packageCommands native upload', () => {
});
});

describe('packageCommands parse*', () => {
let tempDir: string;
let consoleSpy: ReturnType<typeof spyOn>;

beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rnu-parse-'));
consoleSpy = spyOn(console, 'log').mockImplementation(() => {});
});

afterEach(() => {
consoleSpy.mockRestore();
fs.rmSync(tempDir, { recursive: true, force: true });
});

test('prints JSON with bundleHash and without the bundle bytes', async () => {
const appPath = path.join(tempDir, 'demo.app');
await createZip(appPath, {
'resources/rawfile/bundle.harmony.js': 'console.log("hi");',
'resources/rawfile/meta.json': JSON.stringify({
versionName: '1.2.3',
pushy_build_time: 1700000000000,
}),
'resources/rawfile/update.json': JSON.stringify({
harmony: { appId: 7, appKey: 'k' },
}),
});

await packageCommands.parseApp({ args: [appPath] });

expect(consoleSpy).toHaveBeenCalledTimes(1);
expect(JSON.parse(consoleSpy.mock.calls[0][0])).toEqual({
versionName: '1.2.3',
buildTime: 1700000000000,
bundleHash: createHash('sha256')
.update('console.log("hi");')
.digest('hex'),
appId: 7,
appKey: 'k',
});
});
});

describe('choosePackage', () => {
afterEach(() => {
global.NO_INTERACTIVE = undefined;
Expand Down
Loading