Skip to content

Commit

Permalink
feat: support ios 17 launch
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Nov 18, 2023
1 parent 19d922d commit ad89da9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 59 deletions.
19 changes: 1 addition & 18 deletions packages/cli/src/application/buildIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function _buildIos(buildType?: string, platform: IosPlatform = iosBuildPlatforms

executeCommand(buildCommand);

if (platform.buildCmd === 'build') {
// todo handle Debug/release
const appFolder = getBuildFolder(getAppName(), false, buildFlavor.flavorDir, platform.name);
const source = `${iosFolder}/DerivedData/${appName}/build/Products/Debug-${platform.name}/${appFolder}`;
Expand All @@ -45,23 +44,7 @@ function _buildIos(buildType?: string, platform: IosPlatform = iosBuildPlatforms
const copyCommand = `cp -a '${source}' '${destination}'`;
executeCommand(copyCommand);
return destination;
} else {
const ipaFolder = path.join(iosFolder, 'build', 'Products', 'IPA');
const generateIpaCommand = `xcodebuild -exportArchive \
-archivePath '${archivePath}' \
-exportPath "${ipaFolder}" \
-exportOptionsPlist ${iosFolder}/${appName}/info.plist \
-allowProvisioningUpdates
`;
executeCommand(generateIpaCommand);
const { destinationDir, destination } = getIosBuildDestination(platform, buildFlavor.flavorDir);
executeCommand(`mkdir -p ${destinationDir}`);
executeCommand(`rm -rf ${destination}`);
const copyCommand = `cp -a '${ipaFolder}' '${destination}'`;
executeCommand(copyCommand);
executeCommand(`rm -rf ${ipaFolder}`);
return destination;
}

}

export function buildIos(buildType?: string, platform: IosPlatform = iosBuildPlatforms.simulator) {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/application/iosUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const iosBuildPlatforms = {
},
iphone: {
name: "iphoneos",
ext: "ipa",
buildCmd: "archive"
ext: "app",
buildCmd: "build"
}
} as const;

Expand All @@ -20,8 +20,8 @@ export type IosPlatform = {
buildCmd: 'build';
} | {
name: "iphoneos",
ext: "ipa",
buildCmd: "archive"
ext: "app",
buildCmd: "build"
};

export function getIosBuildDestination(platform: {
Expand Down
93 changes: 56 additions & 37 deletions packages/cli/src/application/runIos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ type Device = {
name: string;
udid: string;
type: 'simulator' | 'device'; // todo
iosVersion?: string;
};

export interface SimulatorDeviceType {
lastBootedAt: string
dataPath: string
dataPathSize: number
logPath: string
udid: string
isAvailable: boolean
logPathSize: number
deviceTypeIdentifier: string
state: 'Booted' | 'shutdown'
name: string
lastBootedAt: string;
dataPath: string;
dataPathSize: number;
logPath: string;
udid: string;
isAvailable: boolean;
logPathSize: number;
deviceTypeIdentifier: string;
state: 'Booted' | 'shutdown';
name: string;
}


function getIosSimulatorsDevices(): Device[] {
const devicesJson = JSON.parse(childProcess.execSync('xcrun simctl list -j devices', { encoding: 'utf-8' }));
return (Object.values(devicesJson.devices).flat() as SimulatorDeviceType[]).map(d=>({
return (Object.values(devicesJson.devices).flat() as SimulatorDeviceType[]).map(d => ({
type: 'simulator',
state: d.state,
udid: d.udid,
name: d.name,
name: d.name
}));
}

Expand All @@ -53,6 +53,7 @@ function getIosPhysicalDevices(): Device[] {
name: d.name,
udid: d.udid,
type: 'device',
iosVersion: d.version
};
});
}
Expand All @@ -68,28 +69,48 @@ function checkBuildPresent(
buildCmd: string;
name: string;
},
buildId?: string,
buildId?: string
) {
const { destination } = getIosBuildDestination(target, buildType, buildId);
return fs.existsSync(destination);
}

function isVersionGreaterThen17(iosVersion: string) {
return parseInt(iosVersion) >= 17;
}

function installApp(device: Device, destination: string) {
if (device.type === 'device') {
const ipaFile = fs.readdirSync(destination).find(f => f.endsWith('.ipa'));
if (!ipaFile) {
throw new Error('No ipa file found');
if (device.iosVersion && isVersionGreaterThen17(device.iosVersion)) {
// for ios version greater or equal 17 ios-deploy is not supporter we need to use the
// new devicectl tool inside xcrun
childProcess.execSync(`xcrun devicectl device install app --device ${device.udid} ${destination}`);
} else {
childProcess.execSync(`ios-deploy ${device.udid} --debug --bundle ${destination}`, {
encoding: 'utf-8'
});
}
childProcess.execSync(`ios-deploy ${device.udid} --debug --bundle ${path.join(destination, ipaFile)}`, {
encoding: 'utf-8',
});

} else {
const res = childProcess.execSync(`xcrun simctl install ${device.udid} ${destination}`, { encoding: 'utf-8' });
}
}

function launchApp(deviceUid: string, bundleId: string) {
childProcess.execSync(`xcrun simctl launch ${deviceUid} ${bundleId}`);
function launchApp(device: Device, bundleId: string, destination: string) {
console.log(device);
if (device.type === 'device') {
if (device.iosVersion && isVersionGreaterThen17(device.iosVersion)) {
// for ios version greater or equal 17 ios-deploy is not supporter we need to use the
// new devicectl tool inside xcrun
console.log(`xcrun devicectl device process launch --device ${device.udid} ${bundleId}`)
childProcess.execSync(`xcrun devicectl device process launch --device ${device.udid} ${bundleId}`);
} else {
// do nothing, ios-deploy will already launch the application
}

} else {
childProcess.execSync(`xcrun simctl launch ${device.udid} ${bundleId}`);
}
}

function isErrorWithStderr(e: unknown): e is { stderr: { toString(): string } } {
Expand Down Expand Up @@ -122,9 +143,9 @@ async function promptForDeviceSelection(allDevices: Device[]): Promise<Device[]>
title: `${chalk.bold(`(${d.type})`)} ${chalk.green(`${d.name}`)} (${
d.state === 'Booted' ? 'connected' : 'disconnected'
})`,
value: d,
value: d
})),
min: 1,
min: 1
});
return devices;
}
Expand Down Expand Up @@ -153,7 +174,7 @@ export async function runApp(
buildType?: string,
iosPlatform: IosPlatform = iosBuildPlatforms.simulator,
forceBuild?: boolean,
buildId?: string,
buildId?: string
) {
const buildFlavor = getIosFlavors(buildType);

Expand Down Expand Up @@ -183,7 +204,8 @@ export async function runApp(
executeCommand('open -a Simulator');
try {
await waitForBootedSimulatorOrTimeout();
} catch (e) {}
} catch (e) {
}
devices = getIosSimulatorsDevices();
}

Expand All @@ -208,17 +230,14 @@ export async function runApp(
const { destination } = getIosBuildDestination(iosPlatform, buildFlavor.scheme, buildId);

for (const device of devicesToRun) {
const id = device.udid;
installApp(device, destination);
if (device.type === 'simulator') {
const bundleID = execFileSync(
'/usr/libexec/PlistBuddy',
['-c', 'Print:CFBundleIdentifier', path.join(destination, 'Info.plist')],
{
encoding: 'utf8',
},
).trim();
launchApp(id, bundleID);
}
const bundleID = execFileSync(
'/usr/libexec/PlistBuddy',
['-c', 'Print:CFBundleIdentifier', path.join(destination, 'Info.plist')],
{
encoding: 'utf8'
}
).trim();
launchApp(device, bundleID, destination);
}
}

0 comments on commit ad89da9

Please sign in to comment.