Skip to content

Commit

Permalink
feat(serve): Persist serve options in angular-cli.json (#3908)
Browse files Browse the repository at this point in the history
Closes #1156
  • Loading branch information
delasteve authored and hansl committed Jan 30, 2017
1 parent 5852783 commit da255b0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { BuildOptions } from '../models/webpack-config';
import { BaseBuildCommandOptions } from './build';

import { CliConfig } from '../models/config';
const PortFinder = require('portfinder');
const Command = require('../ember-cli/lib/models/command');
const config = CliConfig.fromProject() || CliConfig.fromGlobal();

PortFinder.basePort = 49152;

const defaultPort = process.env.PORT || 4200;
const defaultPort = process.env.PORT || config.get('defaults.serve.port');
const defaultHost = config.get('defaults.serve.host');

export interface ServeTaskOptions extends BuildOptions {
port?: number;
Expand Down Expand Up @@ -34,9 +36,9 @@ const ServeCommand = Command.extend({
{
name: 'host',
type: String,
default: 'localhost',
default: defaultHost,
aliases: ['H'],
description: 'Listens only on localhost by default'
description: `Listens only on ${defaultHost} by default`
},
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },
Expand Down
16 changes: 16 additions & 0 deletions packages/angular-cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@
"default": true
}
}
},
"serve": {
"description": "Properties to be passed to the serve command",
"type": "object",
"properties": {
"port": {
"description": "The port the application will be served on",
"type": "number",
"default": 4200
},
"host": {
"description": "The host the application will be served on",
"type": "string",
"default": "localhost"
}
}
}
},
"additionalProperties": false
Expand Down
20 changes: 20 additions & 0 deletions tests/e2e/tests/misc/default-port.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { request } from '../../utils/http';
import { killAllProcesses } from '../../utils/process';
import { ngServe } from '../../utils/project';
import { updateJsonFile } from '../../utils/project';

export default function() {
return Promise.resolve()
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson.defaults;
app.serve = { port: 4201 };
}))
.then(() => ngServe())
.then(() => request('http://localhost:4201/'))
.then(body => {
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
throw new Error('Response does not match expected value.');
}
})
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
}

0 comments on commit da255b0

Please sign in to comment.