Skip to content

WIP:refactor(serve): cleanup command options #3910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 1 addition & 30 deletions packages/angular-cli/commands/serve.run.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as denodeify from 'denodeify';
const assign = require('lodash/assign');
const SilentError = require('silent-error');
const PortFinder = require('portfinder');
import ServeWebpackTask from '../tasks/serve-webpack';
Expand All @@ -11,7 +10,7 @@ PortFinder.basePort = 49152;
const getPort = <any>denodeify(PortFinder.getPort);

export default function serveRun(commandOptions: ServeTaskOptions) {
if (commandOptions.environment === '') {
if (!commandOptions.environment) {
if (commandOptions.target === 'development') {
commandOptions.environment = 'dev';
}
Expand All @@ -22,15 +21,9 @@ export default function serveRun(commandOptions: ServeTaskOptions) {

// Check angular version.
Version.assertAngularVersionIs2_3_1OrHigher(this.project.root);
commandOptions.liveReloadHost = commandOptions.liveReloadHost || commandOptions.host;

return checkExpressPort(commandOptions)
.then(() => autoFindLiveReloadPort(commandOptions))
.then((opts: ServeTaskOptions) => {
commandOptions = assign({}, opts, {
baseURL: this.project.config(commandOptions.target).baseURL || '/'
});

const serve = new ServeWebpackTask({
ui: this.ui,
project: this.project,
Expand All @@ -54,25 +47,3 @@ function checkExpressPort(commandOptions: ServeTaskOptions) {

});
}

function autoFindLiveReloadPort(commandOptions: ServeTaskOptions) {
return getPort({ port: commandOptions.liveReloadPort, host: commandOptions.liveReloadHost })
.then((foundPort: number) => {

// if live reload port matches express port, try one higher
if (foundPort === commandOptions.port) {
commandOptions.liveReloadPort = foundPort + 1;
return autoFindLiveReloadPort(commandOptions);
}

// port was already open
if (foundPort === commandOptions.liveReloadPort) {
return commandOptions;
}

// use found port as live reload port
commandOptions.liveReloadPort = foundPort;
return commandOptions;

});
}
44 changes: 6 additions & 38 deletions packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
const PortFinder = require('portfinder');
const Command = require('../ember-cli/lib/models/command');

PortFinder.basePort = 49152;

const defaultPort = process.env.PORT || 4200;

export interface ServeTaskOptions {
port?: number;
host?: string;
proxyConfig?: string;
watcher?: string;
liveReload?: boolean;
liveReloadHost?: string;
liveReloadPort?: number;
liveReloadBaseUrl?: string;
liveReloadLiveCss?: boolean;
target?: string;
environment?: string;
ssl?: boolean;
Expand Down Expand Up @@ -47,39 +39,15 @@ const ServeCommand = Command.extend({
description: 'Listens only on localhost by default'
},
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
{ name: 'watcher', type: String, default: 'events', aliases: ['w'] },
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
{
name: 'live-reload-host',
type: String,
aliases: ['lrh'],
description: 'Defaults to host'
},
{
name: 'live-reload-base-url',
type: String,
aliases: ['lrbu'],
description: 'Defaults to baseURL'
},
{
name: 'live-reload-port',
type: Number,
aliases: ['lrp'],
description: '(Defaults to port number within [49152...65535])'
},
{
name: 'live-reload-live-css',
type: Boolean,
default: true,
description: 'Whether to live reload CSS (default true)'
},
{ name: 'live-reload', type: Boolean, default: true },
{
name: 'target',
type: String,
values: ['development', 'production'],
default: 'development',
aliases: ['t', { 'dev': 'development' }, { 'prod': 'production' }]
},
{ name: 'environment', type: String, default: '', aliases: ['e'] },
{ name: 'environment', type: String, aliases: ['e'] },
{ name: 'ssl', type: Boolean, default: false },
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
Expand All @@ -101,9 +69,9 @@ const ServeCommand = Command.extend({
default: false,
description: 'Enable hot module replacement',
},
{ name: 'i18n-file', type: String, default: null },
{ name: 'i18n-format', type: String, default: null },
{ name: 'locale', type: String, default: null }
{ name: 'i18n-file', type: String },
{ name: 'i18n-format', type: String },
{ name: 'locale', type: String }
],

run: function(commandOptions: ServeTaskOptions) {
Expand Down