Skip to content

Commit e4c143d

Browse files
authored
feat(cli): add scheme and flavor options to run command (#5873)
* feat: add scheme and flavor options to run command * chore: no lodash merge/clone
1 parent 0f17177 commit e4c143d

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

cli/src/android/run.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ const debug = Debug('capacitor:android:run');
1212

1313
export async function runAndroid(
1414
config: Config,
15-
{ target: selectedTarget }: RunCommandOptions,
15+
{ target: selectedTarget, flavor: selectedFlavor }: RunCommandOptions,
1616
): Promise<void> {
1717
const target = await promptForPlatformTarget(
1818
await getPlatformTargets('android'),
1919
selectedTarget,
2020
);
2121

22-
const arg = `assemble${config.android?.flavor || ''}Debug`;
22+
const runFlavor = selectedFlavor || config.android?.flavor || '';
23+
24+
const arg = `assemble${runFlavor}Debug`;
2325
const gradleArgs = [arg];
2426

2527
debug('Invoking ./gradlew with args: %O', gradleArgs);

cli/src/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,28 @@ export function runProgram(config: Config): void {
137137
.description(
138138
`runs ${c.input('sync')}, then builds and deploys the native app`,
139139
)
140+
.option('--scheme <schemeName>', 'set the scheme of the iOS project')
141+
.option('--flavor <flavorName>', 'set the flavor of the Android project')
140142
.option('--list', 'list targets, then quit')
141143
// TODO: remove once --json is a hidden option (https://github.com/tj/commander.js/issues/1106)
142144
.allowUnknownOption(true)
143145
.option('--target <id>', 'use a specific target')
144146
.option('--no-sync', `do not run ${c.input('sync')}`)
145147
.action(
146148
wrapAction(
147-
telemetryAction(config, async (platform, { list, target, sync }) => {
148-
const { runCommand } = await import('./tasks/run');
149-
await runCommand(config, platform, { list, target, sync });
150-
}),
149+
telemetryAction(
150+
config,
151+
async (platform, { scheme, flavor, list, target, sync }) => {
152+
const { runCommand } = await import('./tasks/run');
153+
await runCommand(config, platform, {
154+
scheme,
155+
flavor,
156+
list,
157+
target,
158+
sync,
159+
});
160+
},
161+
),
151162
),
152163
);
153164

cli/src/ios/run.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ const debug = Debug('capacitor:ios:run');
1212

1313
export async function runIOS(
1414
config: Config,
15-
{ target: selectedTarget }: RunCommandOptions,
15+
{ target: selectedTarget, scheme: selectedScheme }: RunCommandOptions,
1616
): Promise<void> {
1717
const target = await promptForPlatformTarget(
1818
await getPlatformTargets('ios'),
1919
selectedTarget,
2020
);
2121

22+
const runScheme = selectedScheme || config.ios.scheme;
23+
2224
const derivedDataPath = resolve(
2325
config.ios.platformDirAbs,
2426
'DerivedData',
@@ -29,7 +31,7 @@ export async function runIOS(
2931
'-workspace',
3032
basename(await config.ios.nativeXcodeWorkspaceDirAbs),
3133
'-scheme',
32-
config.ios.scheme,
34+
runScheme,
3335
'-configuration',
3436
'Debug',
3537
'-destination',
@@ -46,7 +48,7 @@ export async function runIOS(
4648
}),
4749
);
4850

49-
const appName = `${config.ios.scheme}.app`;
51+
const appName = `${runScheme}.app`;
5052
const appPath = resolve(
5153
derivedDataPath,
5254
'Build/Products',

cli/src/tasks/run.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import { getPlatformTargets } from '../util/native-run';
1919
import { sync } from './sync';
2020

2121
export interface RunCommandOptions {
22+
scheme?: string;
23+
flavor?: string;
2224
list?: boolean;
2325
target?: string;
2426
sync?: boolean;

0 commit comments

Comments
 (0)