chore: prettier

This commit is contained in:
endiliey 2018-08-05 18:58:50 +08:00
parent 05426d4e2c
commit 187a46d9b6
2 changed files with 24 additions and 22 deletions

View file

@ -42,7 +42,7 @@ program
wrapCommand(build)(path.resolve(siteDir), {skipImageCompression}); wrapCommand(build)(path.resolve(siteDir), {skipImageCompression});
}); });
program program
.command('init [projectDir]') .command('init [projectDir]')
.description('Initialize website') .description('Initialize website')
.action((projectDir = '.') => { .action((projectDir = '.') => {
@ -61,5 +61,5 @@ program
program.parse(process.argv); program.parse(process.argv);
if (!process.argv.slice(2).length) { if (!process.argv.slice(2).length) {
program.outputHelp() program.outputHelp();
} }

View file

@ -21,27 +21,29 @@ async function getPort(port) {
} }
module.exports = async function start(siteDir, cliOptions = {}) { 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); const props = await load(siteDir);
// Reload for any add/change/remove of file // (if enabled) live reload for any changes in file
const reload = () => { if (!cliOptions.noWatch) {
load(siteDir).catch(err => { const reload = () => {
console.error(chalk.red(err.stack)); load(siteDir).catch(err => {
console.error(chalk.red(err.stack));
});
};
const fsWatcher = chokidar.watch(['../docs/**/*.md', 'siteConfig.js'], {
cwd: siteDir,
ignoreInitial: true
}); });
}; fsWatcher.on('add', reload);
const fsWatcher = chokidar.watch(['**/*.md', 'config.js'], { fsWatcher.on('change', reload);
cwd: siteDir, fsWatcher.on('unlink', reload);
ignoreInitial: true 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 port = await getPort(cliOptions.port);
const {publicPath} = props; const {baseUrl} = props;
// resolve webpack config // resolve webpack config
let config = createDevConfig(props); let config = createDevConfig(props);
@ -51,7 +53,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
onDone: () => { onDone: () => {
console.log( console.log(
`\n${chalk.blue('Development server available at ')}${chalk.cyan( `\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', logLevel: 'error',
port, port,
add: (app, middleware, options) => { add: (app, middleware, options) => {
const staticDir = path.resolve(siteDir, 'public'); const staticDir = path.resolve(siteDir, 'static');
if (fs.existsSync(staticDir)) { 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(range); // enable range request https://tools.ietf.org/html/rfc7233
app.use( app.use(