Skip to content

Commit 2a312ab

Browse files
committed
feat(capacitor): document platform argument, prompt when required
1 parent 54c7d55 commit 2a312ab

File tree

5 files changed

+67
-17
lines changed

5 files changed

+67
-17
lines changed

packages/ionic/src/commands/capacitor/add.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chalk from 'chalk';
22

3+
import { validators } from '@ionic/cli-framework';
34
import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '@ionic/cli-utils';
45

56
import { CapacitorCommand } from './base';
@@ -14,15 +15,20 @@ export class AddCommand extends CapacitorCommand implements CommandPreRun {
1415
${chalk.green('ionic capacitor add')} will do the following:
1516
- Add a new platform specific folder to your project (ios, android, or electron)
1617
`,
17-
exampleCommands: [],
18-
inputs: [],
18+
inputs: [
19+
{
20+
name: 'platform',
21+
summary: `The platform to add (e.g. ${['android', 'ios', 'electron'].map(v => chalk.green(v)).join(', ')})`,
22+
validators: [validators.required],
23+
},
24+
],
1925
};
2026
}
2127

2228
async preRun(inputs: CommandLineInputs, options: CommandLineOptions, runinfo: CommandInstanceInfo): Promise<void> {
2329
await this.preRunChecks(runinfo);
2430

25-
if (inputs.length < 1) {
31+
if (!inputs[0]) {
2632
const platform = await this.env.prompt({
2733
type: 'list',
2834
name: 'platform',
@@ -36,10 +42,12 @@ ${chalk.green('ionic capacitor add')} will do the following:
3642

3743
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
3844
const [ platform ] = inputs;
39-
const args = [ 'add' ];
45+
const args = ['add'];
46+
4047
if (platform) {
4148
args.push(platform);
4249
}
50+
4351
await this.runCapacitor(args);
4452
}
4553
}

packages/ionic/src/commands/capacitor/copy.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ export class CopyCommand extends CapacitorCommand implements CommandPreRun {
99
return {
1010
name: 'copy',
1111
type: 'project',
12-
summary: 'Copies web assets to each Capacitor native platform',
12+
summary: 'Copies web assets to Capacitor native platforms',
1313
description: `
1414
${chalk.green('ionic capacitor copy')} will do the following:
1515
- Copy the ${chalk.bold('www/')} directory into your native platforms.
1616
`,
17-
exampleCommands: [],
18-
inputs: [],
17+
inputs: [
18+
{
19+
name: 'platform',
20+
summary: `The platform to copy (e.g. ${['android', 'ios', 'electron'].map(v => chalk.green(v)).join(', ')})`,
21+
},
22+
],
1923
};
2024
}
2125

@@ -24,6 +28,13 @@ ${chalk.green('ionic capacitor copy')} will do the following:
2428
}
2529

2630
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
27-
await this.runCapacitor(['copy']);
31+
const [ platform ] = inputs;
32+
const args = ['copy'];
33+
34+
if (platform) {
35+
args.push(platform);
36+
}
37+
38+
await this.runCapacitor(args);
2839
}
2940
}

packages/ionic/src/commands/capacitor/open.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chalk from 'chalk';
22

3+
import { validators } from '@ionic/cli-framework';
34
import { CommandInstanceInfo, CommandLineInputs, CommandLineOptions, CommandMetadata, CommandPreRun } from '@ionic/cli-utils';
45

56
import { CapacitorCommand } from './base';
@@ -14,21 +15,39 @@ export class OpenCommand extends CapacitorCommand implements CommandPreRun {
1415
${chalk.green('ionic capacitor open')} will do the following:
1516
- Open the IDE with your current native project for that specific platform. This means Xcode for iOS, and Android Studio for Android
1617
`,
17-
exampleCommands: [],
18-
inputs: [],
18+
inputs: [
19+
{
20+
name: 'platform',
21+
summary: `The platform to open (e.g. ${['android', 'ios'].map(v => chalk.green(v)).join(', ')})`,
22+
validators: [validators.required],
23+
},
24+
],
1925
};
2026
}
2127

2228
async preRun(inputs: CommandLineInputs, options: CommandLineOptions, runinfo: CommandInstanceInfo): Promise<void> {
2329
await this.preRunChecks(runinfo);
30+
31+
if (!inputs[0]) {
32+
const platform = await this.env.prompt({
33+
type: 'list',
34+
name: 'platform',
35+
message: 'What platform would you like to open?',
36+
choices: ['android', 'ios'],
37+
});
38+
39+
inputs[0] = platform.trim();
40+
}
2441
}
2542

2643
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
2744
const [ platform ] = inputs;
28-
const args = [ 'open' ];
45+
const args = ['open'];
46+
2947
if (platform) {
3048
args.push(platform);
3149
}
50+
3251
await this.runCapacitor(args);
3352
}
3453
}

packages/ionic/src/commands/capacitor/sync.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ ${chalk.green('ionic capacitor sync')} will do the following:
1616
- Update each Capacitor native platforms, such as any dependencies that need updating.
1717
- Install any discovered Capacitor or Cordova plugins.
1818
`,
19-
exampleCommands: [],
20-
inputs: [],
19+
inputs: [
20+
{
21+
name: 'platform',
22+
summary: `The platform to sync (e.g. ${['android', 'ios', 'electron'].map(v => chalk.green(v)).join(', ')})`,
23+
},
24+
],
2125
};
2226
}
2327

@@ -27,10 +31,12 @@ ${chalk.green('ionic capacitor sync')} will do the following:
2731

2832
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
2933
const [ platform ] = inputs;
30-
const args = [ 'sync' ];
34+
const args = ['sync'];
35+
3136
if (platform) {
3237
args.push(platform);
3338
}
39+
3440
await this.runCapacitor(args);
3541
}
3642
}

packages/ionic/src/commands/capacitor/update.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ ${chalk.green('ionic capacitor update')} will do the following:
1515
- Update each Capacitor native project, such as any dependencies that need updating.
1616
- Install any discovered Capacitor or Cordova plugins.
1717
`,
18-
exampleCommands: [],
19-
inputs: [],
18+
inputs: [
19+
{
20+
name: 'platform',
21+
summary: `The platform to update (e.g. ${['android', 'ios', 'electron'].map(v => chalk.green(v)).join(', ')})`,
22+
},
23+
],
2024
};
2125
}
2226

@@ -26,10 +30,12 @@ ${chalk.green('ionic capacitor update')} will do the following:
2630

2731
async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
2832
const [ platform ] = inputs;
29-
const args = [ 'update' ];
33+
const args = ['update'];
34+
3035
if (platform) {
3136
args.push(platform);
3237
}
38+
3339
await this.runCapacitor(args);
3440
}
3541
}

0 commit comments

Comments
 (0)