Skip to content

Commit

Permalink
feat(cli): add scheme and flavor options to run command (#5873)
Browse files Browse the repository at this point in the history
* feat: add scheme and flavor options to run command

* chore: no lodash merge/clone
  • Loading branch information
IT-MikeS authored Sep 7, 2022
1 parent 0f17177 commit e4c143d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
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

0 comments on commit e4c143d

Please sign in to comment.