Skip to content

Commit

Permalink
feat(serve): implement open browser option
Browse files Browse the repository at this point in the history
Closes #1081
Close #2489
  • Loading branch information
dzonatan authored and filipesilva committed Oct 10, 2016
1 parent f8defb5 commit 8bddabe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/angular-cli/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ServeTaskOptions {
sslKey?: string;
sslCert?: string;
aot?: boolean;
open?: boolean;
}

const ServeCommand = Command.extend({
Expand Down Expand Up @@ -79,7 +80,14 @@ const ServeCommand = Command.extend({
{ name: 'ssl', type: Boolean, default: false },
{ name: 'ssl-key', type: String, default: 'ssl/server.key' },
{ name: 'ssl-cert', type: String, default: 'ssl/server.crt' },
{ name: 'aot', type: Boolean, default: false }
{ name: 'aot', type: Boolean, default: false },
{
name: 'open',
type: Boolean,
default: false,
aliases: ['o'],
description: 'Opens the url in default browser',
},
],

run: function(commandOptions: ServeTaskOptions) {
Expand Down
7 changes: 7 additions & 0 deletions packages/angular-cli/tasks/serve-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { NgCliWebpackConfig } from '../models/webpack-config';
import { ServeTaskOptions } from '../commands/serve';
import { CliConfig } from '../models/config';
import { oneLine } from 'common-tags';
import * as url from 'url';
const opn = require('opn');

export default Task.extend({
run: function(commandOptions: ServeTaskOptions) {
Expand Down Expand Up @@ -78,6 +80,11 @@ export default Task.extend({
console.error(err.stack || err);
if (err.details) { console.error(err.details); }
reject(err.details);
} else {
const { open, host, port } = commandOptions;
if (open) {
opn(url.format({ protocol: 'http', hostname: host, port: port.toString() }));
}
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/angular-cli/utilities/completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github_pages_deploy_opts='--base-href --environment --gh-token --gh-username --m
help_opts='--json --verbose -v'
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'
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'
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'
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 -o -p -pc -t -w'
set_opts='--global -g'
test_opts='--browsers --build --colors --log-level --port --reporters --watch -w'
version_opts='--verbose'
Expand Down

0 comments on commit 8bddabe

Please sign in to comment.