Skip to content

Commit 1357c5c

Browse files
committed
fix(capacitor): pass in project/package id during start
fixes #3519
1 parent 9e29235 commit 1357c5c

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

packages/@ionic/cli-utils/src/definitions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export interface IProject {
266266
}
267267

268268
export interface IIntegrationAddOptions {
269+
enableArgs?: string[];
269270
conflictHandler?(f: string, stats: fs.Stats): Promise<boolean>;
270271
onFileCreate?(f: string): void;
271272
}

packages/@ionic/cli-utils/src/lib/integrations/capacitor/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as lodash from 'lodash';
44
export const CAPACITOR_CONFIG_FILE = 'capacitor.config.json';
55

66
export interface CapacitorConfigFile {
7+
appId?: string;
8+
appName?: string;
79
webDir?: string;
810
server?: {
911
url?: string;

packages/@ionic/cli-utils/src/lib/integrations/capacitor/index.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1+
import * as path from 'path';
2+
13
import { BaseIntegration } from '../';
2-
import { IIntegrationAddOptions, InfoItem, IntegrationName } from '../../../definitions';
4+
import { IIntegrationAddOptions, InfoItem, IntegrationName, ProjectPersonalizationDetails } from '../../../definitions';
35
import { pkgManagerArgs } from '../../utils/npm';
46

7+
import { CAPACITOR_CONFIG_FILE, CapacitorConfig } from './config';
8+
59
export class Integration extends BaseIntegration {
610
readonly name: IntegrationName = 'capacitor';
711
readonly summary = `Target native iOS and Android with Capacitor, Ionic's new native layer`;
812
readonly archiveUrl = undefined;
913

1014
async add(options?: IIntegrationAddOptions): Promise<void> {
15+
let name = this.e.project.config.get('name');
16+
let packageId = 'io.ionic.starter';
17+
18+
if (options && options.enableArgs) {
19+
if (options.enableArgs[0]) {
20+
name = options.enableArgs[0];
21+
}
22+
23+
if (options.enableArgs[1]) {
24+
packageId = options.enableArgs[1];
25+
}
26+
}
27+
1128
await this.installCapacitorCore();
1229
await this.installCapacitorCLI();
1330

14-
await this.e.shell.run('capacitor', ['init', this.e.project.config.get('name'), 'io.ionic.starter'], { cwd: this.e.project.directory });
31+
await this.e.shell.run('capacitor', ['init', name, packageId], { cwd: this.e.project.directory });
1532

1633
await super.add(options);
1734
}
@@ -26,6 +43,16 @@ export class Integration extends BaseIntegration {
2643
await this.e.shell.run(manager, managerArgs, { cwd: this.e.project.directory });
2744
}
2845

46+
async personalize({ name, packageId }: ProjectPersonalizationDetails) {
47+
const conf = new CapacitorConfig(path.resolve(this.e.project.directory, CAPACITOR_CONFIG_FILE));
48+
49+
conf.set('appName', name);
50+
51+
if (packageId) {
52+
conf.set('appId', packageId);
53+
}
54+
}
55+
2956
async getInfo(): Promise<InfoItem[]> {
3057
const [
3158
[ capacitorCorePkg, capacitorCorePkgPath ],

packages/ionic/src/commands/integrations/enable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Integrations can be re-added with the ${chalk.green('--add')} option.
6060
try {
6161
if (!integrationConfig || add) {
6262
await integration.add({
63+
enableArgs: options['--'] ? options['--'] : undefined,
6364
conflictHandler: async (f, stats) => {
6465
const isDirectory = stats.isDirectory();
6566
const filename = `${path.basename(f)}${isDirectory ? '/' : ''}`;

packages/ionic/src/commands/start.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://ionicframework.com/docs/cli/starters
439439
}
440440

441441
if (options['capacitor']) {
442-
await runCommand(runinfo, ['integrations', 'enable', 'capacitor', '--quiet']);
442+
await runCommand(runinfo, ['integrations', 'enable', 'capacitor', '--quiet', '--', this.schema.name, packageId ? packageId : 'io.ionic.starter']);
443443
}
444444

445445
await this.project.personalize({ name: this.schema.name, projectId, packageId });

0 commit comments

Comments
 (0)