Skip to content

Commit

Permalink
feat(build/serve): expose engine and platform
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Jun 8, 2018
1 parent 606973d commit bb1c82a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
19 changes: 16 additions & 3 deletions packages/@ionic/cli-utils/src/lib/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseError } from '@ionic/cli-framework';
import { BaseError, OptionGroup } from '@ionic/cli-framework';
import chalk from 'chalk';

import { PROJECT_FILE } from '../constants';
Expand All @@ -19,11 +19,12 @@ export const COMMON_BUILD_COMMAND_OPTIONS: ReadonlyArray<CommandMetadataOption>
{
name: 'engine',
summary: `Target engine (e.g. ${['browser', 'cordova'].map(e => chalk.green(e)).join(', ')})`,
default: 'browser',
groups: [OptionGroup.Advanced],
},
{
name: 'platform',
summary: `Target platform on chosen engine (e.g. ${['ios', 'android'].map(e => chalk.green(e)).join(', ')})`,
groups: [OptionGroup.Advanced],
},
];

Expand Down Expand Up @@ -78,11 +79,23 @@ export abstract class BuildRunner<T extends BuildOptions<any>> implements Runner
createBaseOptionsFromCommandLine(inputs: CommandLineInputs, options: CommandLineOptions): BaseBuildOptions {
const separatedArgs = options['--'];
const platform = options['platform'] ? String(options['platform']) : undefined;
const engine = options['engine'] ? String(options['engine']) : 'browser';
const engine = this.determineEngineFromCommandLine(options);

return { '--': separatedArgs ? separatedArgs : [], engine, platform };
}

determineEngineFromCommandLine(options: CommandLineOptions): string {
if (options['engine']) {
return String(options['engine']);
}

if (options['cordova']) {
return 'cordova';
}

return 'browser';
}

async beforeBuild(options: T): Promise<void> {
const hook = new BuildBeforeHook({ config: this.config, project: this.project, shell: this.shell });

Expand Down
24 changes: 23 additions & 1 deletion packages/@ionic/cli-utils/src/lib/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export const COMMON_SERVE_COMMAND_OPTIONS: ReadonlyArray<CommandMetadataOption>
type: Boolean,
default: true,
},
{
name: 'engine',
summary: `Target engine (e.g. ${['browser', 'cordova'].map(e => chalk.green(e)).join(', ')})`,
groups: [OptionGroup.Advanced],
},
{
name: 'platform',
summary: `Target platform on chosen engine (e.g. ${['ios', 'android'].map(e => chalk.green(e)).join(', ')})`,
groups: [OptionGroup.Advanced],
},
];

export interface ServeRunnerDeps {
Expand Down Expand Up @@ -127,7 +137,7 @@ export abstract class ServeRunner<T extends ServeOptions> extends EventEmitter i
options['devapp'] = false;
}

const engine = options['engine'] ? String(options['engine']) : 'browser';
const engine = this.determineEngineFromCommandLine(options);
const address = options['address'] ? String(options['address']) : BIND_ALL_ADDRESS;
const labPort = str2num(options['lab-port'], DEFAULT_LAB_PORT);
const port = str2num(options['port'], DEFAULT_SERVER_PORT);
Expand All @@ -152,6 +162,18 @@ export abstract class ServeRunner<T extends ServeOptions> extends EventEmitter i
};
}

determineEngineFromCommandLine(options: CommandLineOptions): string {
if (options['engine']) {
return String(options['engine']);
}

if (options['cordova']) {
return 'cordova';
}

return 'browser';
}

async displayDevAppMessage(options: T) {
const pkg = await this.project.requirePackageJson();

Expand Down
5 changes: 0 additions & 5 deletions packages/ionic/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,6 @@ export class ServeCommand extends Command implements CommandPreRun {
type: Boolean,
aliases: ['l'],
},
{
name: 'platform',
summary: `Start serve with a specific platform (${['android', 'ios'].map(t => chalk.green(t)).join(', ')})`,
aliases: ['t'],
},
{
name: 'auth',
summary: 'HTTP Basic Auth password to secure the server on your local network',
Expand Down

0 comments on commit bb1c82a

Please sign in to comment.