mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
refactor: start cli command
This commit is contained in:
parent
7a69cff30c
commit
1150c45f9b
1 changed files with 115 additions and 114 deletions
|
@ -15,16 +15,16 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|||
const load = require('../load');
|
||||
const createDevConfig = require('../webpack/dev');
|
||||
|
||||
async function getPort(port) {
|
||||
portfinder.basePort = parseInt(port, 10) || 3000;
|
||||
return await portfinder.getPortPromise();
|
||||
async function getPort(reqPort) {
|
||||
portfinder.basePort = parseInt(reqPort, 10) || 3000;
|
||||
const port = await portfinder.getPortPromise();
|
||||
return port;
|
||||
}
|
||||
|
||||
module.exports = async function start(siteDir, cliOptions = {}) {
|
||||
// Preprocess whole files as a prop
|
||||
// Process all related files as a prop
|
||||
const props = await load(siteDir);
|
||||
|
||||
// (if enabled) live reload for any changes in file
|
||||
if (!cliOptions.noWatch) {
|
||||
const reload = () => {
|
||||
load(siteDir).catch(err => {
|
||||
|
@ -67,8 +67,9 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
{
|
||||
inject: false,
|
||||
hash: true,
|
||||
template: path.resolve(__dirname, '../core/index.html'),
|
||||
filename: 'index.html'
|
||||
template: path.resolve(__dirname, '../core/devTemplate.ejs'),
|
||||
filename: 'index.html',
|
||||
title: props.siteConfig.title
|
||||
}
|
||||
]);
|
||||
|
||||
|
@ -94,7 +95,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
|||
},
|
||||
logLevel: 'error',
|
||||
port,
|
||||
add: (app, middleware, options) => {
|
||||
add: app => {
|
||||
const staticDir = path.resolve(siteDir, 'static');
|
||||
if (fs.existsSync(staticDir)) {
|
||||
app.use(mount(baseUrl, serveStatic(staticDir)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue