From 08be35893bf7c7aba464313d69bee28b5d684631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damien=20Gu=C3=A9rin?= Date: Fri, 17 Jan 2020 14:38:16 +0100 Subject: [PATCH 1/2] Serve several static paths --- lib/commands/serve.js | 62 +++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/lib/commands/serve.js b/lib/commands/serve.js index 13de4b8..397d103 100644 --- a/lib/commands/serve.js +++ b/lib/commands/serve.js @@ -25,48 +25,58 @@ module.exports = function ( livereloadPort = p }) .then(_ => { - path = resolve(path || '.') - const indexFile = resolve(path, indexName || 'index.html') + const server = connect(); + server.use( + livereload({ + port: livereloadPort + }) + ); + + let indexFileFound = false; + let indexFile; + path.split(",").forEach((path)=> { + path = resolve(path || "."); + indexFile = resolve(path, indexName || "index.html"); + if (exists(indexFile)) { + indexFileFound = true + } + server.use(serveStatic(path, { index: indexName })); + }); - if (!exists(indexFile)) { + if (!indexFileFound) { const msg = - '\nNo docs found ' + + "\nNo docs found " + indexFile + - '\nPlease run ' + - chalk.green('docsify init') + - ' first.\n' - console.log(msg) - process.exit(0) + "\nPlease run " + + chalk.green("docsify init") + + " first.\n"; + console.log(msg); + process.exit(0); } - const server = connect() - server.use( - livereload({ - port: livereloadPort - }) - ) - server.use(serveStatic(path, {index: indexName})) - server.listen(port) + + + server.listen(port); lrserver .createServer({ - extraExts: ['md'], - exclusions: ['node_modules/'], + extraExts: ["md"], + exclusions: ["node_modules/"], port: livereloadPort }) - .watch(path) + .watch(path.split(",")); if (openInBrowser) { - open(`http://localhost:${port}`) + open(`http://localhost:${port}`); } const msg = - '\nServing ' + + "\nServing " + chalk.green(`${path}`) + - ' now.\n' + - 'Listening at ' + + " now.\n" + + "Listening at " + chalk.green(`http://localhost:${port}`) + - '\n' - console.log(msg) + "\n"; + console.log(msg); }) .catch(err => { console.error(err.message) From e74b9d8e55b01deafc16fc65b9189dfe227c8987 Mon Sep 17 00:00:00 2001 From: Damien Guerin Date: Fri, 17 Jan 2020 16:19:56 +0100 Subject: [PATCH 2/2] Fix lint issues --- lib/commands/serve.js | 53 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/lib/commands/serve.js b/lib/commands/serve.js index 397d103..2d008bb 100644 --- a/lib/commands/serve.js +++ b/lib/commands/serve.js @@ -25,58 +25,57 @@ module.exports = function ( livereloadPort = p }) .then(_ => { - const server = connect(); + const server = connect() server.use( livereload({ port: livereloadPort }) - ); + ) - let indexFileFound = false; - let indexFile; - path.split(",").forEach((path)=> { - path = resolve(path || "."); - indexFile = resolve(path, indexName || "index.html"); + let indexFileFound = false + let indexFile + path.split(',').forEach(path => { + path = resolve(path || ',') + indexFile = resolve(path, indexName || 'index.html') if (exists(indexFile)) { indexFileFound = true } - server.use(serveStatic(path, { index: indexName })); - }); + + server.use(serveStatic(path, {index: indexName})) + }) if (!indexFileFound) { const msg = - "\nNo docs found " + + '\nNo docs found ' + indexFile + - "\nPlease run " + - chalk.green("docsify init") + - " first.\n"; - console.log(msg); - process.exit(0); + '\nPlease run ' + + chalk.green('docsify init') + + ' first.\n' + console.log(msg) + process.exit(0) } - - - server.listen(port); + server.listen(port) lrserver .createServer({ - extraExts: ["md"], - exclusions: ["node_modules/"], + extraExts: ['md'], + exclusions: ['node_modules/'], port: livereloadPort }) - .watch(path.split(",")); + .watch(path.split(',')) if (openInBrowser) { - open(`http://localhost:${port}`); + open(`http://localhost:${port}`) } const msg = - "\nServing " + + '\nServing ' + chalk.green(`${path}`) + - " now.\n" + - "Listening at " + + ' now.\n' + + 'Listening at ' + chalk.green(`http://localhost:${port}`) + - "\n"; - console.log(msg); + '\n' + console.log(msg) }) .catch(err => { console.error(err.message)