refactor: start cli command

This commit is contained in:
endiliey 2018-08-08 00:45:58 +08:00
parent 7a69cff30c
commit 1150c45f9b

View file

@ -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)));