Skip to content

Commit 81206d7

Browse files
committed
feat(serve): Persist serve options in angular-cli.json
1 parent 14666f4 commit 81206d7

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

packages/angular-cli/commands/serve.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { BuildOptions } from '../models/webpack-config';
22
import { BaseBuildCommandOptions } from './build';
3-
3+
import { CliConfig } from '../models/config';
44
const PortFinder = require('portfinder');
55
const Command = require('../ember-cli/lib/models/command');
6+
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
67

78
PortFinder.basePort = 49152;
89

9-
const defaultPort = process.env.PORT || 4200;
10+
const defaultPort = process.env.PORT || config.get('defaults.serve.port');
11+
const defaultHost = config.get('defaults.serve.host');
12+
1013

1114
export interface ServeTaskOptions extends BuildOptions {
1215
port?: number;
@@ -34,9 +37,9 @@ const ServeCommand = Command.extend({
3437
{
3538
name: 'host',
3639
type: String,
37-
default: 'localhost',
40+
default: defaultHost,
3841
aliases: ['H'],
39-
description: 'Listens only on localhost by default'
42+
description: `Listens only on ${defaultHost} by default`
4043
},
4144
{ name: 'proxy-config', type: 'Path', aliases: ['pc'] },
4245
{ name: 'live-reload', type: Boolean, default: true, aliases: ['lr'] },

packages/angular-cli/lib/config/schema.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,23 @@
247247
"default": true
248248
}
249249
}
250+
},
251+
"serve": {
252+
"type": "object",
253+
"properties": {
254+
"port": {
255+
"type": "number",
256+
"default": 4200
257+
},
258+
"liveReloadPort": {
259+
"type": "number",
260+
"default": 49152
261+
},
262+
"host": {
263+
"type": "string",
264+
"default": "localhost"
265+
}
266+
}
250267
}
251268
},
252269
"additionalProperties": false
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { request } from '../../utils/http';
2+
import { killAllProcesses } from '../../utils/process';
3+
import { ngServe } from '../../utils/project';
4+
import { updateJsonFile } from '../../utils/project';
5+
6+
export default function() {
7+
return Promise.resolve()
8+
.then(() => updateJsonFile('angular-cli.json', configJson => {
9+
const app = configJson.defaults;
10+
app.serve = { port: 4201 };
11+
}))
12+
.then(() => ngServe())
13+
.then(() => request('http://localhost:4201/'))
14+
.then(body => {
15+
if (!body.match(/<app-root>Loading...<\/app-root>/)) {
16+
throw new Error('Response does not match expected value.');
17+
}
18+
})
19+
.then(() => killAllProcesses(), (err) => { killAllProcesses(); throw err; });
20+
}

0 commit comments

Comments
 (0)