-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
serve.js
41 lines (33 loc) · 1.04 KB
/
serve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
'use strict'
const serveStatic = require('serve-static')
const connect = require('connect')
const livereload = require('connect-livereload')
const lrserver = require('livereload')
const open = require('open')
const chalk = require('chalk')
const util = require('../util/index')
var exists = util.exists
var resolve = util.resolve
module.exports = function (path, openInBrowser, port) {
path = resolve(path || '.')
var indexFile = resolve(path, 'index.html')
if (!exists(indexFile)) {
const msg = '\nNo docs found, please run ' + chalk.green('docsify init') + ' first.\n'
console.log(msg)
process.exit(0)
}
var server = connect()
server.use(livereload())
server.use(serveStatic(path))
server.listen(port)
lrserver.createServer({
exts: ['md'],
exclusions: ['node_modules/']
}).watch(path)
if (openInBrowser) {
open(`http://localhost:${port}`)
}
const msg = '\nServing ' + chalk.green(`${path}`) + ' now.\n' +
'Listening at ' + chalk.green(`http://localhost:${port}`) + '\n'
console.log(msg)
}