Skip to content

Commit 6bf2ceb

Browse files
committed
refactor($core): add more comments
1 parent 1a09252 commit 6bf2ceb

File tree

1 file changed

+38
-4
lines changed
  • packages/@vuepress/core/lib/node/dev

1 file changed

+38
-4
lines changed

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

+38-4
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ module.exports = class DevProcess extends EventEmitter {
188188
this.webpackConfig = config
189189
}
190190

191+
/**
192+
* Create dev server
193+
* @returns {module.DevProcess}
194+
*/
195+
191196
createServer () {
192197
const contentBase = path.resolve(this.context.sourceDir, '.vuepress/public')
193198

@@ -236,16 +241,30 @@ module.exports = class DevProcess extends EventEmitter {
236241
return this
237242
}
238243

239-
listen () {
240-
this.server.listen(this.port, this.host, err => {
241-
if (err) {
242-
console.log(err)
244+
/**
245+
* delegate listen call.
246+
*
247+
* @param callback handler when connection is ready.
248+
* @returns {module.DevProcess}
249+
*/
250+
251+
listen (callback) {
252+
this.server.listen(this.port, this.host, (err) => {
253+
if (callback) {
254+
callback(err)
243255
}
244256
})
245257
return this
246258
}
247259
}
248260

261+
/**
262+
* Resolve host.
263+
*
264+
* @param {string} host user's host
265+
* @returns {{displayHost: string, host: string}}
266+
*/
267+
249268
function resolveHost (host) {
250269
const defaultHost = 'localhost'
251270
host = host || defaultHost
@@ -258,13 +277,28 @@ function resolveHost (host) {
258277
}
259278
}
260279

280+
/**
281+
* Resolve port.
282+
*
283+
* @param {number} port user's port
284+
* @returns {Promise<number>}
285+
*/
286+
261287
async function resolvePort (port) {
262288
const portfinder = require('portfinder')
263289
portfinder.basePort = parseInt(port) || 8080
264290
port = await portfinder.getPortPromise()
265291
return port
266292
}
267293

294+
/**
295+
* Normalize file path and always return relative path,
296+
*
297+
* @param {string} filepath user's path
298+
* @param {string} baseDir source directory
299+
* @returns {string}
300+
*/
301+
268302
function normalizeWatchFilePath (filepath, baseDir) {
269303
const { isAbsolute, relative } = require('path')
270304
if (isAbsolute(filepath)) {

0 commit comments

Comments
 (0)