Skip to content

Commit d08e873

Browse files
committed
support cli option open
1 parent d206d44 commit d08e873

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

packages/@vuepress/core/lib/dev.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = async (sourceDir, cliOptions = {}, ctx) => {
77
console.log(err)
88
}
99
})
10+
return { host, port }
1011
}
1112

1213
module.exports.prepare = prepareServer

packages/vuepress/lib/registerCoreCommands.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
const { dev, build, eject } = require('@vuepress/core')
88
const { path, logger, env } = require('@vuepress/shared-utils')
99
const { wrapCommand } = require('./util')
10+
const opn = require('opn')
11+
const url = require('url')
1012

1113
/**
1214
* Expose registerCoreCommands function.
@@ -24,7 +26,7 @@ module.exports = function (cli, options) {
2426
.option('--silent', 'start development server in silent mode')
2527
.option('--open', 'open browser when ready')
2628
.action((sourceDir = '.', commandOptions) => {
27-
const { debug, silent } = commandOptions
29+
const { debug, silent, open } = commandOptions
2830

2931
logger.setOptions({ logLevel: silent ? 1 : debug ? 4 : 3 })
3032
logger.debug('global_options', options)
@@ -34,6 +36,13 @@ module.exports = function (cli, options) {
3436
wrapCommand(dev)(path.resolve(sourceDir), {
3537
...options,
3638
...commandOptions
39+
}).then((urlObject) => {
40+
if (!open) return
41+
opn(url.format({
42+
protocol: 'http',
43+
hostname: urlObject.host,
44+
port: urlObject.port
45+
}))
3746
})
3847
})
3948

packages/vuepress/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"dependencies": {
3232
"@vuepress/core": "^1.0.0-alpha.39",
3333
"@vuepress/theme-default": "^1.0.0-alpha.39",
34-
"cac": "^6.3.9"
34+
"cac": "^6.3.9",
35+
"opn": "^5.4.0"
3536
},
3637
"engines": {
3738
"node": ">=8"

yarn.lock

+7
Original file line numberDiff line numberDiff line change
@@ -7369,6 +7369,13 @@ opn@^5.1.0:
73697369
dependencies:
73707370
is-wsl "^1.1.0"
73717371

7372+
opn@^5.4.0:
7373+
version "5.4.0"
7374+
resolved "https://registry.yarnpkg.com/opn/-/opn-5.4.0.tgz#cb545e7aab78562beb11aa3bfabc7042e1761035"
7375+
integrity sha512-YF9MNdVy/0qvJvDtunAOzFw9iasOQHpVthTCvGzxt61Il64AYSGdK+rYwld7NAfk9qJ7dt+hymBNSc9LNYS+Sw==
7376+
dependencies:
7377+
is-wsl "^1.1.0"
7378+
73727379
optimist@^0.6.1:
73737380
version "0.6.1"
73747381
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"

0 commit comments

Comments
 (0)