Skip to content

Commit b38438f

Browse files
committed
feat(serve): implement open browser option
Closes #1081
1 parent 2b6bfe7 commit b38438f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Diff for: packages/angular-cli/commands/serve.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ServeTaskOptions {
2626
sslKey?: string;
2727
sslCert?: string;
2828
aot?: boolean;
29+
open?: boolean;
2930
}
3031

3132
const ServeCommand = Command.extend({
@@ -79,7 +80,13 @@ const ServeCommand = Command.extend({
7980
{ name: 'ssl', type: Boolean, default: false },
8081
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
8182
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
82-
{ name: 'aot', type: Boolean, default: false }
83+
{ name: 'aot', type: Boolean, default: false },
84+
{
85+
name: 'open',
86+
description: 'Opens the url in default browser',
87+
type: Boolean,
88+
default: false
89+
},
8390
],
8491

8592
run: function(commandOptions: ServeTaskOptions) {

Diff for: packages/angular-cli/tasks/serve-webpack.ts

+7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
1111
import { ServeTaskOptions } from '../commands/serve';
1212
import { CliConfig } from '../models/config';
1313
import { oneLine } from 'common-tags';
14+
import * as url from 'url';
15+
const opn = require('opn');
1416

1517
export default Task.extend({
1618
run: function(commandOptions: ServeTaskOptions) {
@@ -78,6 +80,11 @@ export default Task.extend({
7880
console.error(err.stack || err);
7981
if (err.details) { console.error(err.details); }
8082
reject(err.details);
83+
} else {
84+
const { open, host, port } = commandOptions;
85+
if (open) {
86+
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() }));
87+
}
8188
}
8289
});
8390
});

Diff for: packages/angular-cli/utilities/completion.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ github_pages_deploy_opts='--base-href --environment --gh-token --gh-username --m
1313
help_opts='--json --verbose -v'
1414
init_opts='--dry-run inline-style inline-template --link-cli --mobile --name --prefix --routing --skip-bower --skip-npm --source-dir --style --verbose -d -is -it -lc -n -p -sb -sd -sn -v'
1515
new_opts='--directory --dry-run inline-style inline-template --link-cli --mobile --prefix --routing --skip-bower --skip-git --skip-npm --source-dir --style --verbose -d -dir -is -it -lc -p -sb -sd -sg -sn -v'
16-
serve_opts='--aot --environment --host --live-reload --live-reload-base-url --live-reload-host --live-reload-live-css --live-reload-port --port --proxy-config --ssl --ssl-cert --ssl-key --target --watcher -H -e -lr -lrbu -lrh -lrp -p -pc -t -w'
16+
serve_opts='--aot --environment --host --live-reload --live-reload-base-url --live-reload-host --live-reload-live-css --live-reload-port --open --port --proxy-config --ssl --ssl-cert --ssl-key --target --watcher -H -e -lr -lrbu -lrh -lrp -p -pc -t -w'
1717
set_opts='--global -g'
1818
test_opts='--browsers --build --colors --log-level --port --reporters --watch -w'
1919
version_opts='--verbose'

0 commit comments

Comments
 (0)