feat(cli): option to open the project in the browser (#4930)

This commit is contained in:
Ricardo Gobbo de Souza 2019-02-05 19:37:59 -02:00 committed by Pooya Parsa
parent 3147823dee
commit 4c7bd9c507
2 changed files with 19 additions and 3 deletions

View File

@ -19,6 +19,7 @@
"esm": "^3.2.0",
"execa": "^1.0.0",
"minimist": "^1.2.0",
"opener": "1.5.1",
"pretty-bytes": "^5.1.0",
"std-env": "^2.2.1",
"wrap-ansi": "^4.0.0"

View File

@ -1,5 +1,6 @@
import consola from 'consola'
import chalk from 'chalk'
import opener from 'opener'
import { common, server } from '../options'
import { showBanner, eventsMapping, formatPath } from '../utils'
@ -9,17 +10,31 @@ export default {
usage: 'dev <dir>',
options: {
...common,
...server
...server,
open: {
alias: 'o',
type: 'boolean',
description: 'Opens the server listeners url in the default browser'
}
},
async run(cmd) {
const { argv } = cmd
await this.startDev(cmd, argv)
const nuxt = await this.startDev(cmd, argv)
// Opens the server listeners url in the default browser
if (argv.open) {
for (const listener of nuxt.server.listeners) {
await opener(listener.url)
}
}
},
async startDev(cmd, argv) {
try {
await this._startDev(cmd, argv)
const nuxt = await this._startDev(cmd, argv)
return nuxt
} catch (error) {
consola.error(error)
}