Skip to content
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

feat(serve): Persist serve options in angular-cli.json #3908

Merged
merged 1 commit into from
Jan 30, 2017
Merged
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
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add description for all new properties. We're going to do a full run through existing ones, but new properties should have proper descriptions. This is because we're going to add support for IDEs that support schema, and those descriptions will be shown to users. Also, the config documentation will be generated from these.

"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; });
}