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

feat(cli): add scheme and flavor options to run command #5873

Merged
merged 3 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 4 additions & 2 deletions cli/src/android/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ const debug = Debug('capacitor:android:run');

export async function runAndroid(
config: Config,
{ target: selectedTarget }: RunCommandOptions,
{ target: selectedTarget, flavor: selectedFlavor }: RunCommandOptions,
): Promise<void> {
const target = await promptForPlatformTarget(
await getPlatformTargets('android'),
selectedTarget,
);

const arg = `assemble${config.android?.flavor || ''}Debug`;
const runFlavor = selectedFlavor || config.android?.flavor || '';

const arg = `assemble${runFlavor}Debug`;
const gradleArgs = [arg];

debug('Invoking ./gradlew with args: %O', gradleArgs);
Expand Down
19 changes: 15 additions & 4 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,28 @@ export function runProgram(config: Config): void {
.description(
`runs ${c.input('sync')}, then builds and deploys the native app`,
)
.option('--scheme <schemeName>', 'set the scheme of the iOS project')
.option('--flavor <flavorName>', 'set the flavor of the Android project')
.option('--list', 'list targets, then quit')
// TODO: remove once --json is a hidden option (https://github.com/tj/commander.js/issues/1106)
.allowUnknownOption(true)
.option('--target <id>', 'use a specific target')
.option('--no-sync', `do not run ${c.input('sync')}`)
.action(
wrapAction(
telemetryAction(config, async (platform, { list, target, sync }) => {
const { runCommand } = await import('./tasks/run');
await runCommand(config, platform, { list, target, sync });
}),
telemetryAction(
config,
async (platform, { scheme, flavor, list, target, sync }) => {
const { runCommand } = await import('./tasks/run');
await runCommand(config, platform, {
scheme,
flavor,
list,
target,
sync,
});
},
),
),
);

Expand Down
8 changes: 5 additions & 3 deletions cli/src/ios/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ const debug = Debug('capacitor:ios:run');

export async function runIOS(
config: Config,
{ target: selectedTarget }: RunCommandOptions,
{ target: selectedTarget, scheme: selectedScheme }: RunCommandOptions,
): Promise<void> {
const target = await promptForPlatformTarget(
await getPlatformTargets('ios'),
selectedTarget,
);

const runScheme = selectedScheme || config.ios.scheme;

const derivedDataPath = resolve(
config.ios.platformDirAbs,
'DerivedData',
Expand All @@ -29,7 +31,7 @@ export async function runIOS(
'-workspace',
basename(await config.ios.nativeXcodeWorkspaceDirAbs),
'-scheme',
config.ios.scheme,
runScheme,
'-configuration',
'Debug',
'-destination',
Expand All @@ -46,7 +48,7 @@ export async function runIOS(
}),
);

const appName = `${config.ios.scheme}.app`;
const appName = `${runScheme}.app`;
const appPath = resolve(
derivedDataPath,
'Build/Products',
Expand Down
2 changes: 2 additions & 0 deletions cli/src/tasks/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { getPlatformTargets } from '../util/native-run';
import { sync } from './sync';

export interface RunCommandOptions {
scheme?: string;
flavor?: string;
list?: boolean;
target?: string;
sync?: boolean;
Expand Down