diff --git a/packages/angular-cli/commands/serve.ts b/packages/angular-cli/commands/serve.ts index 936a341b4cfc..c30e5520f222 100644 --- a/packages/angular-cli/commands/serve.ts +++ b/packages/angular-cli/commands/serve.ts @@ -26,6 +26,7 @@ export interface ServeTaskOptions { sslKey?: string; sslCert?: string; aot?: boolean; + open?: boolean; } const ServeCommand = Command.extend({ @@ -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) { diff --git a/packages/angular-cli/tasks/serve-webpack.ts b/packages/angular-cli/tasks/serve-webpack.ts index f09e21de0dca..42d16c9c4712 100644 --- a/packages/angular-cli/tasks/serve-webpack.ts +++ b/packages/angular-cli/tasks/serve-webpack.ts @@ -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) { @@ -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() })); + } } }); }); diff --git a/packages/angular-cli/utilities/completion.sh b/packages/angular-cli/utilities/completion.sh index 907d724eaea4..250308ad371b 100644 --- a/packages/angular-cli/utilities/completion.sh +++ b/packages/angular-cli/utilities/completion.sh @@ -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'