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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Finder (MacOS) folder config
.DS_Store

# comparison output from scripts/compare-output.ts
.compare-output
94 changes: 94 additions & 0 deletions scripts/compare-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Compare script: generates projects for each platform and validates the
* pbxproj output from the Object API migration.
*
* Usage: bun scripts/compare-output.ts
*/

import { join } from "path";
import { rmSync, readdirSync, statSync } from "fs";

const ROOT = join(import.meta.dir, "..");
const OUT_DIR = join(ROOT, ".compare-output");

async function runCLI(platform: string, name: string): Promise<string> {
const outDir = join(OUT_DIR, platform);
const proc = Bun.spawnSync(
["bun", "src/cli.ts", name, "--platform", platform, "--org", "com.example", "--org-name", "Example Inc", "-y", "--output", outDir],
{ cwd: ROOT, stderr: "pipe", stdout: "pipe" }
);
const stdout = new TextDecoder().decode(proc.stdout as unknown as ArrayBuffer);
const stderr = new TextDecoder().decode(proc.stderr as unknown as ArrayBuffer);
if (proc.exitCode !== 0) {
throw new Error(`CLI failed for ${platform}:\n${stderr}\n${stdout}`);
}
return join(outDir, name);
}

async function main() {
rmSync(OUT_DIR, { recursive: true, force: true });

const platforms = ["ios", "macos", "tvos", "watchos", "visionos", "multiplatform"];
let allPass = true;

for (const platform of platforms) {
console.log(`\n--- ${platform} ---`);
try {
const projectDir = await runCLI(platform, "TestApp");
const pbxprojPath = join(projectDir, "TestApp.xcodeproj", "project.pbxproj");
const pbxproj = await Bun.file(pbxprojPath).text();

// Structural checks
const checks: Record<string, boolean> = {
hasPBXProject: pbxproj.includes("isa = PBXProject"),
hasPBXNativeTarget: pbxproj.includes("isa = PBXNativeTarget"),
hasSourcesBuildPhase: pbxproj.includes("isa = PBXSourcesBuildPhase"),
hasFrameworksBuildPhase: pbxproj.includes("isa = PBXFrameworksBuildPhase"),
hasResourcesBuildPhase: pbxproj.includes("isa = PBXResourcesBuildPhase"),
hasXCBuildConfiguration: pbxproj.includes("isa = XCBuildConfiguration"),
hasXCConfigurationList: pbxproj.includes("isa = XCConfigurationList"),
hasPBXGroup: pbxproj.includes("isa = PBXGroup"),
hasPBXFileReference: pbxproj.includes("isa = PBXFileReference"),
hasPBXBuildFile: pbxproj.includes("isa = PBXBuildFile"),
hasProductApp: pbxproj.includes("TestApp.app"),
hasBundleId: pbxproj.includes("com.example."),
hasSwiftVersion: pbxproj.includes("SWIFT_VERSION"),
hasDebugConfig: pbxproj.includes("name = Debug"),
hasReleaseConfig: pbxproj.includes("name = Release"),
hasArchiveVersion: pbxproj.includes("archiveVersion = 1"),
hasObjectVersion: pbxproj.includes("objectVersion = 56"),
hasCompatVersion: pbxproj.includes("Xcode 14.0"),
hasUpgradeCheck: pbxproj.includes("1620"),
};

const platformPass = Object.values(checks).every(Boolean);
if (!platformPass) allPass = false;
console.log(` Checks: ${platformPass ? "ALL PASS" : "FAILURES"}`);
for (const [key, value] of Object.entries(checks)) {
if (!value) console.log(` FAIL: ${key}`);
}

// Count objects
const isaCounts: Record<string, number> = {};
const isaRegex = /isa = (\w+)/g;
let match;
while ((match = isaRegex.exec(pbxproj)) !== null) {
const isa = match[1]!;
isaCounts[isa] = (isaCounts[isa] || 0) + 1;
}
console.log(" Objects:", JSON.stringify(isaCounts));

// Save for manual diff
await Bun.write(join(OUT_DIR, `${platform}.pbxproj`), pbxproj);
} catch (err: any) {
allPass = false;
console.log(` ERROR: ${err.message}`);
}
}

console.log(`\n${"=".repeat(50)}`);
console.log(allPass ? "ALL PLATFORMS PASS" : "SOME PLATFORMS FAILED");
console.log(`pbxproj files saved in ${OUT_DIR}/ for manual inspection`);
}

main().catch(console.error);
Loading
Loading