Skip to content

Commit

Permalink
refactor($core): add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Mar 10, 2019
1 parent 1a09252 commit 6bf2ceb
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions packages/@vuepress/core/lib/node/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ module.exports = class DevProcess extends EventEmitter {
this.webpackConfig = config
}

/**
* Create dev server
* @returns {module.DevProcess}
*/

createServer () {
const contentBase = path.resolve(this.context.sourceDir, '.vuepress/public')

Expand Down Expand Up @@ -236,16 +241,30 @@ module.exports = class DevProcess extends EventEmitter {
return this
}

listen () {
this.server.listen(this.port, this.host, err => {
if (err) {
console.log(err)
/**
* delegate listen call.
*
* @param callback handler when connection is ready.
* @returns {module.DevProcess}
*/

listen (callback) {
this.server.listen(this.port, this.host, (err) => {
if (callback) {
callback(err)
}
})
return this
}
}

/**
* Resolve host.
*
* @param {string} host user's host
* @returns {{displayHost: string, host: string}}
*/

function resolveHost (host) {
const defaultHost = 'localhost'
host = host || defaultHost
Expand All @@ -258,13 +277,28 @@ function resolveHost (host) {
}
}

/**
* Resolve port.
*
* @param {number} port user's port
* @returns {Promise<number>}
*/

async function resolvePort (port) {
const portfinder = require('portfinder')
portfinder.basePort = parseInt(port) || 8080
port = await portfinder.getPortPromise()
return port
}

/**
* Normalize file path and always return relative path,
*
* @param {string} filepath user's path
* @param {string} baseDir source directory
* @returns {string}
*/

function normalizeWatchFilePath (filepath, baseDir) {
const { isAbsolute, relative } = require('path')
if (isAbsolute(filepath)) {
Expand Down

0 comments on commit 6bf2ceb

Please sign in to comment.