Skip to content

Commit

Permalink
fix(serve): support --platform for mode/platform selection
Browse files Browse the repository at this point in the history
fixes #3185
  • Loading branch information
imhoffd committed Jun 8, 2018
1 parent bb1c82a commit 15f2389
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions packages/@ionic/cli-utils/src/lib/project/angular/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ ${chalk.cyan('[1]')}: ${chalk.bold('https://github.com/angular/angular-cli/wiki/
};
}

platformToMode(platform: string): string {
if (platform === 'ios') {
return 'ios';
}

return 'md';
}

modifyOpenURL(url: string, options: AngularServeOptions): string {
return `${url}${options.browserOption ? options.browserOption : ''}${options.platform ? `?ionic:mode=${this.platformToMode(options.platform)}` : ''}`;
}

async serveProject(options: AngularServeOptions): Promise<ServeDetails> {
const [ externalIP, availableInterfaces ] = await this.selectExternalIP(options);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ export class ServeRunner extends BaseServeRunner<IonicAngularServeOptions> {
};
}

modifyOpenURL(url: string, options: IonicAngularServeOptions): string {
return `${url}${options.browserOption ? options.browserOption : ''}${options.platform ? `?ionicplatform=${options.platform}` : ''}`;
}

async serveProject(options: IonicAngularServeOptions): Promise<ServeDetails> {
const [ externalIP, availableInterfaces ] = await this.selectExternalIP(options);
const { port, livereloadPort, notificationPort } = await findOpenIonicPorts(options.address, options);
Expand Down
4 changes: 4 additions & 0 deletions packages/@ionic/cli-utils/src/lib/project/ionic1/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export class ServeRunner extends BaseServeRunner<Ionic1ServeOptions> {
};
}

modifyOpenURL(url: string, options: Ionic1ServeOptions): string {
return `${url}${options.browserOption ? options.browserOption : ''}${options.platform ? `?ionicplatform=${options.platform}` : ''}`;
}

async serveProject(options: Ionic1ServeOptions): Promise<ServeDetails> {
const [ externalIP, availableInterfaces ] = await this.selectExternalIP(options);
const { port, livereloadPort, notificationPort } = await findOpenIonicPorts(options.address, options);
Expand Down
6 changes: 2 additions & 4 deletions packages/@ionic/cli-utils/src/lib/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export abstract class ServeRunner<T extends ServeOptions> extends EventEmitter i

abstract getCommandMetadata(): Promise<Partial<CommandMetadata>>;
abstract serveProject(options: T): Promise<ServeDetails>;
abstract modifyOpenURL(url: string, options: T): string;

createOptionsFromCommandLine(inputs: CommandLineInputs, options: CommandLineOptions): ServeOptions {
const separatedArgs = options['--'];
Expand Down Expand Up @@ -236,10 +237,7 @@ export abstract class ServeRunner<T extends ServeOptions> extends EventEmitter i

if (options.open) {
const openAddress = labAddress ? labAddress : localAddress;
const openURL = [openAddress]
.concat(options.browserOption ? [options.browserOption] : [])
.concat(options.platform ? ['?ionicplatform=', options.platform] : [])
.join('');
const openURL = this.modifyOpenURL(openAddress, options);

const opn = await import('opn');
await opn(openURL, { app: options.browser, wait: false });
Expand Down

0 comments on commit 15f2389

Please sign in to comment.