Skip to content

Commit 17f1438

Browse files
tlancinaimhoffd
authored andcommitted
feat(serve): support --consolelogs for cordova serve in angular projects (#3900)
1 parent 978d4b0 commit 17f1438

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/ionic/src/definitions.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ export interface ServeOptions {
580580
}
581581

582582
export interface AngularServeOptions extends ServeOptions {
583+
consolelogs?: boolean;
584+
consolelogsPort?: number;
583585
ssl?: boolean;
584586
configuration?: string;
585587
sourcemaps?: boolean;

packages/ionic/src/lib/project/angular/serve.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { MetadataGroup, ParsedArgs, unparseArgs } from '@ionic/cli-framework';
22
import { stripAnsi } from '@ionic/cli-framework/utils/format';
3+
import { str2num } from '@ionic/cli-framework/utils/string';
34
import { findClosestOpenPort } from '@ionic/utils-network';
45
import chalk from 'chalk';
56

67
import { AngularServeOptions, CommandLineInputs, CommandLineOptions, CommandMetadata, ServeDetails } from '../../../definitions';
78
import { input, strong, weak } from '../../color';
8-
import { BIND_ALL_ADDRESS, LOCAL_ADDRESSES, SERVE_SCRIPT, ServeCLI, ServeRunner, ServeRunnerDeps } from '../../serve';
9+
import { BIND_ALL_ADDRESS, DEFAULT_DEV_LOGGER_PORT as DEFAULT_CONSOLE_LOGS_PORT, LOCAL_ADDRESSES, SERVE_SCRIPT, ServeCLI, ServeRunner, ServeRunnerDeps } from '../../serve';
910

1011
import { AngularProject } from './';
1112

@@ -36,6 +37,22 @@ The dev server can use HTTPS via the ${input('--ssl')} option ${chalk.bold.red('
3637
},
3738
],
3839
options: [
40+
{
41+
name: 'consolelogs',
42+
summary: 'Print app console logs to the terminal',
43+
type: Boolean,
44+
groups: [MetadataGroup.ADVANCED, 'cordova'],
45+
// aliases: ['c'], Already used by ng cli for --configuration
46+
hint: weak('[ng]'),
47+
},
48+
{
49+
name: 'consolelogs-port',
50+
summary: 'Use specific port for console logs server',
51+
type: String,
52+
groups: [MetadataGroup.ADVANCED, 'cordova'],
53+
hint: weak('[ng]'),
54+
spec: { value: 'port' },
55+
},
3956
{
4057
name: 'ssl',
4158
summary: 'Use HTTPS for the dev server',
@@ -85,9 +102,19 @@ The dev server can use HTTPS via the ${input('--ssl')} option ${chalk.bold.red('
85102
const ssl = options['ssl'] ? Boolean(options['ssl']) : undefined;
86103
const configuration = options['configuration'] ? String(options['configuration']) : (prod ? 'production' : undefined);
87104
const sourcemaps = typeof options['source-map'] === 'boolean' ? Boolean(options['source-map']) : undefined;
105+
let consolelogs = typeof options['consolelogs'] === 'boolean' ? Boolean(options['consolelogs']) : undefined;
106+
let consolelogsPort = consolelogs ? str2num(options['consolelogs-port'], DEFAULT_CONSOLE_LOGS_PORT) : undefined;
107+
108+
// if not defined, default to true for devapp
109+
if (options.devapp) {
110+
consolelogs = consolelogs === undefined ? true : consolelogs;
111+
consolelogsPort = str2num(options['consolelogs-port'], DEFAULT_CONSOLE_LOGS_PORT);
112+
}
88113

89114
return {
90115
...baseOptions,
116+
consolelogs,
117+
consolelogsPort,
91118
ssl,
92119
configuration,
93120
sourcemaps,
@@ -215,6 +242,8 @@ export class AngularServeCLI extends ServeCLI<AngularServeOptions> {
215242
if (options.devapp) {
216243
args.cordovaMock = true;
217244
}
245+
args.consolelogs = options.consolelogs ? true : undefined;
246+
args['consolelogs-port'] = options.consolelogsPort ? String(options.consolelogsPort) : undefined;
218247
}
219248

220249
if (this.resolvedProgram !== this.program) {

0 commit comments

Comments
 (0)