Skip to content

Commit

Permalink
fix(cordova): Adjust app paths for cordova-ios 7
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Nov 17, 2023
1 parent d09653d commit 9ccae11
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/@ionic/cli/src/commands/cordova/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMeta
import { COMMON_BUILD_COMMAND_OPTIONS } from '../../lib/build';
import { input, strong, weak } from '../../lib/color';
import { FatalException, RunnerException } from '../../lib/errors';
import { getPackagePath } from '../../lib/integrations/cordova/project';
import { getPackagePath, getPackagePathCordova } from '../../lib/integrations/cordova/project';
import { filterArgumentsForCordova, generateOptionsForCordovaBuild } from '../../lib/integrations/cordova/utils';
import { SUPPORTED_PLATFORMS, checkNativeRun, createNativeRunArgs, createNativeRunListArgs, getNativeTargets, runNativeRun } from '../../lib/native-run';
import { COMMON_SERVE_COMMAND_OPTIONS, LOCAL_ADDRESSES } from '../../lib/serve';
Expand Down Expand Up @@ -302,7 +302,14 @@ Just like with ${input('ionic cordova build')}, you can pass additional options

await this.runCordova(filterArgumentsForCordova({ ...metadata, name: 'build' }, options), buildOpts);

const packagePath = await getPackagePath(this.integration.root, conf.getProjectInfo().name, platform, { emulator: !options['device'], release: !!options['release'] });
const [ pkg ] = await this.project.getPackageJson(`cordova-${platform}`);
let packagePath = await getPackagePath(this.integration.root, conf.getProjectInfo().name, platform, { emulator: !options['device'], release: !!options['release'] });

if (pkg) {
const platformVersion = pkg.version;
packagePath = await getPackagePathCordova(this.integration.root, conf.getProjectInfo().name, platform, platformVersion, { emulator: !options['device'], release: !!options['release'] });
}

const forwardedPorts = details ? runner.getUsedPorts(runnerOpts, details) : [];

await this.runNativeRun(createNativeRunArgs({ packagePath, platform, forwardedPorts }, options));
Expand Down Expand Up @@ -337,10 +344,15 @@ Just like with ${input('ionic cordova build')}, you can pass additional options
if (options['native-run']) {
const conf = await loadCordovaConfig(this.integration);
const [ platform ] = inputs;

await this.runCordova(filterArgumentsForCordova({ ...metadata, name: 'build' }, options), { stdio: 'inherit' });

const packagePath = await getPackagePath(this.integration.root, conf.getProjectInfo().name, platform, { emulator: !options['device'], release: !!options['release'] });
const [ pkg ] = await this.project.getPackageJson(`cordova-${platform}`);
let packagePath = await getPackagePath(this.integration.root, conf.getProjectInfo().name, platform, { emulator: !options['device'], release: !!options['release'] });

if (pkg) {
const platformVersion = pkg.version;
packagePath = await getPackagePathCordova(this.integration.root, conf.getProjectInfo().name, platform, platformVersion, { emulator: !options['device'], release: !!options['release'] });
}

await this.runNativeRun(createNativeRunArgs({ packagePath, platform }, { ...options, connect: false }));
} else {
Expand Down
42 changes: 42 additions & 0 deletions packages/@ionic/cli/src/lib/integrations/cordova/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { filter } from '@ionic/utils-array';
import { readJson, readdirSafe, statSafe } from '@ionic/utils-fs';
import * as Debug from 'debug';
import * as path from 'path';
import * as semver from 'semver';

import { AndroidBuildOutput, LegacyAndroidBuildOutputEntry } from '../../../definitions';
import { isAndroidBuildOutputFile, isLegacyAndroidBuildOutputFile } from '../../../guards';
Expand All @@ -13,6 +14,7 @@ const debug = Debug('ionic:lib:cordova:project');
const CORDOVA_ANDROID_PACKAGE_PATH = 'platforms/android/app/build/outputs/apk/';
const CORDOVA_IOS_SIMULATOR_PACKAGE_PATH = 'platforms/ios/build/emulator';
const CORDOVA_IOS_DEVICE_PACKAGE_PATH = 'platforms/ios/build/device';
const CORDOVA_IOS_PACKAGE_PATH = 'platforms/ios/build';

export async function getPlatforms(projectDir: string): Promise<string[]> {
const platformsDir = path.resolve(projectDir, 'platforms');
Expand Down Expand Up @@ -83,3 +85,43 @@ export async function getPackagePath(root: string, appName: string, platform: st

throw new FatalException(`Unknown package path for ${input(appName)} on ${input(platform)}.`);
}


/**
* Get the relative path to most recently built APK or IPA file
*/
export async function getPackagePathCordova(root: string, appName: string, platform: string, platformVersion: any, { emulator = false, release = false }: GetPackagePathOptions = {}): Promise<string> {
if (platform === 'android') {
return getAndroidPackageFilePath(root, { emulator, release });
} else if (platform === 'ios') {
return getiOSPackageFilePath(root, { emulator, release, appName, platformVersion });
}

throw new FatalException(`Unknown package path for ${input(appName)} on ${input(platform)}.`);
}

interface iOSGetPackagePathOptions {
emulator?: boolean;
release?: boolean;
appName: string;
platformVersion: any;
}

async function getiOSPackageFilePath(root: string, { emulator = false, release = false, appName, platformVersion }: iOSGetPackagePathOptions): Promise<string> {
let defaultPath = "device";
let deviceType = "iphoneos";
let extension = "ipa";
if (emulator) {
defaultPath = "emulator";
deviceType = "iphonesimulator";
extension = "app";
}
if (semver.gte(platformVersion, '7.0.0')) {
let releaseType = "Debug";
if (release) {
releaseType = "Release";
}
defaultPath = `${releaseType}-${deviceType}`;
}
return path.join(CORDOVA_IOS_PACKAGE_PATH, defaultPath, `${appName}.${extension}`);
}

0 comments on commit 9ccae11

Please sign in to comment.