Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cordova): Adjust app paths for cordova-ios 7 #5065

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
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}`);
}