@@ -188,6 +188,11 @@ module.exports = class DevProcess extends EventEmitter {
188
188
this . webpackConfig = config
189
189
}
190
190
191
+ /**
192
+ * Create dev server
193
+ * @returns {module.DevProcess }
194
+ */
195
+
191
196
createServer ( ) {
192
197
const contentBase = path . resolve ( this . context . sourceDir , '.vuepress/public' )
193
198
@@ -236,16 +241,30 @@ module.exports = class DevProcess extends EventEmitter {
236
241
return this
237
242
}
238
243
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 )
243
255
}
244
256
} )
245
257
return this
246
258
}
247
259
}
248
260
261
+ /**
262
+ * Resolve host.
263
+ *
264
+ * @param {string } host user's host
265
+ * @returns {{displayHost: string, host: string} }
266
+ */
267
+
249
268
function resolveHost ( host ) {
250
269
const defaultHost = 'localhost'
251
270
host = host || defaultHost
@@ -258,13 +277,28 @@ function resolveHost (host) {
258
277
}
259
278
}
260
279
280
+ /**
281
+ * Resolve port.
282
+ *
283
+ * @param {number } port user's port
284
+ * @returns {Promise<number> }
285
+ */
286
+
261
287
async function resolvePort ( port ) {
262
288
const portfinder = require ( 'portfinder' )
263
289
portfinder . basePort = parseInt ( port ) || 8080
264
290
port = await portfinder . getPortPromise ( )
265
291
return port
266
292
}
267
293
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
+
268
302
function normalizeWatchFilePath ( filepath , baseDir ) {
269
303
const { isAbsolute, relative } = require ( 'path' )
270
304
if ( isAbsolute ( filepath ) ) {
0 commit comments