From 187a46d9b617914fef271f1b8c194082ca8cbb94 Mon Sep 17 00:00:00 2001 From: endiliey Date: Sun, 5 Aug 2018 18:58:50 +0800 Subject: [PATCH] chore: prettier --- bin/munseo.js | 6 +++--- lib/commands/start.js | 40 +++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/bin/munseo.js b/bin/munseo.js index 927b884a85..75ad89e773 100644 --- a/bin/munseo.js +++ b/bin/munseo.js @@ -42,7 +42,7 @@ program wrapCommand(build)(path.resolve(siteDir), {skipImageCompression}); }); - program +program .command('init [projectDir]') .description('Initialize website') .action((projectDir = '.') => { @@ -61,5 +61,5 @@ program program.parse(process.argv); if (!process.argv.slice(2).length) { - program.outputHelp() -} \ No newline at end of file + program.outputHelp(); +} diff --git a/lib/commands/start.js b/lib/commands/start.js index ed47e49d4c..284bd45543 100644 --- a/lib/commands/start.js +++ b/lib/commands/start.js @@ -21,27 +21,29 @@ async function getPort(port) { } module.exports = async function start(siteDir, cliOptions = {}) { - // load site props from preprocessed files in source directory + // Preprocess whole files as a prop const props = await load(siteDir); - // Reload for any add/change/remove of file - const reload = () => { - load(siteDir).catch(err => { - console.error(chalk.red(err.stack)); + // (if enabled) live reload for any changes in file + if (!cliOptions.noWatch) { + const reload = () => { + load(siteDir).catch(err => { + console.error(chalk.red(err.stack)); + }); + }; + const fsWatcher = chokidar.watch(['../docs/**/*.md', 'siteConfig.js'], { + cwd: siteDir, + ignoreInitial: true }); - }; - const fsWatcher = chokidar.watch(['**/*.md', 'config.js'], { - cwd: siteDir, - ignoreInitial: true - }); - fsWatcher.on('add', reload); - fsWatcher.on('change', reload); - fsWatcher.on('unlink', reload); - fsWatcher.on('addDir', reload); - fsWatcher.on('unlinkDir', reload); + fsWatcher.on('add', reload); + fsWatcher.on('change', reload); + fsWatcher.on('unlink', reload); + fsWatcher.on('addDir', reload); + fsWatcher.on('unlinkDir', reload); + } const port = await getPort(cliOptions.port); - const {publicPath} = props; + const {baseUrl} = props; // resolve webpack config let config = createDevConfig(props); @@ -51,7 +53,7 @@ module.exports = async function start(siteDir, cliOptions = {}) { onDone: () => { console.log( `\n${chalk.blue('Development server available at ')}${chalk.cyan( - `http://localhost:${port}${publicPath}` + `http://localhost:${port}${baseUrl}` )}` ); } @@ -89,9 +91,9 @@ module.exports = async function start(siteDir, cliOptions = {}) { logLevel: 'error', port, add: (app, middleware, options) => { - const staticDir = path.resolve(siteDir, 'public'); + const staticDir = path.resolve(siteDir, 'static'); if (fs.existsSync(staticDir)) { - app.use(mount(publicPath, serveStatic(staticDir))); + app.use(mount(baseUrl, serveStatic(staticDir))); } app.use(range); // enable range request https://tools.ietf.org/html/rfc7233 app.use(