chore: prettier & eslint

This commit is contained in:
endiliey 2018-07-29 01:14:32 +08:00
parent 56dfec19ea
commit e8e1d5e097
7 changed files with 55 additions and 45 deletions

View file

@ -15,5 +15,7 @@ module.exports = {
'func-names': OFF,
'react/jsx-filename-extension': OFF,
'react/jsx-one-expression-per-line': OFF,
'import/no-unresolved': WARNING, // because it couldn't resolve webpack alias
'react/prefer-stateless-function': WARNING,
},
};

View file

@ -1,4 +1,5 @@
module.exports = async function build(sourceDir, cliOptions = {}) {
process.env.NODE_ENV = 'production';
console.log(cliOptions);
console.log('Build');
};

View file

@ -12,7 +12,7 @@ const serveStatic = require('koa-static');
const history = require('connect-history-api-fallback');
const load = require('./loader');
const createDevConfig = require('./webpack/dev');
const logPlugin = require('./webpack/plugin/log')
const logPlugin = require('./webpack/log');
module.exports = async function dev(sourceDir, cliOptions = {}) {
const logger = ora(chalk.blue('Start development server')).start();
@ -40,13 +40,14 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
let config = createDevConfig(props);
const port = cliOptions.port || 8080;
const {publicPath} = props;
config
.plugin('blogi-log')
.use(logPlugin, [{
config.plugin('blogi-log').use(logPlugin, [
{
port,
publicPath: props.publicPath
}]);
publicPath
}
]);
// create compiler from generated webpack config
config = config.toConfig();
@ -62,7 +63,7 @@ module.exports = async function dev(sourceDir, cliOptions = {}) {
open: true,
devMiddleware: {
logLevel: 'warn',
publicPath: props.publicPath
publicPath
},
hotClient: {
port: port + 1,

View file

@ -1,3 +1,3 @@
module.exports = function theme() {
return 'theme';
return 'themes';
};

View file

@ -3,7 +3,7 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = function createBaseConfig(props) {
const {outDir, themePath, sourceDir} = props;
const {outDir, themePath, sourceDir, publicPath} = props;
const config = new Config();
const isProd = process.env.NODE_ENV === 'production';
@ -18,6 +18,7 @@ module.exports = function createBaseConfig(props) {
.set('symlinks', true)
.alias.set('@theme', themePath)
.set('@source', sourceDir)
.set('@generated', path.resolve(__dirname, '../generated'))
.set('@core', path.resolve(__dirname, '../core'))
.end();

34
lib/webpack/log.js Normal file
View file

@ -0,0 +1,34 @@
const chalk = require('chalk');
const ora = require('ora');
function clearScreen() {
process.stdout.write('\x1Bc');
}
module.exports = class LogPlugin {
constructor(options) {
this.options = options;
}
apply(compiler) {
const logger = ora();
compiler.hooks.done.tap('blogi-log', stats => {
clearScreen();
const {port, publicPath} = this.options;
const time = new Date().toTimeString().match(/^[\d:]+/)[0];
logger.succeed(
`${chalk.gray(`[${time}]`)} Build ${chalk.green(
stats.hash.slice(0, 8)
)} finished in ${chalk.green(stats.endTime - stats.startTime)} ms!`
);
console.log(
`\n${chalk.blue('Development server available at ')}${chalk.cyan(
`http://localhost:${port}${publicPath}`
)}`
);
});
compiler.hooks.invalid.tap('blogi-log', clearScreen);
}
};

View file

@ -1,29 +0,0 @@
const chalk = require('chalk');
const ora = require('ora');
module.exports = class LogPlugin {
constructor (options) {
this.options = options
}
apply (compiler) {
const logger = ora();
let isFirst = true
compiler.hooks.done.tap('blogi-log', stats => {
clearScreen()
const { port, publicPath } = this.options
const time = new Date().toTimeString().match(/^[\d:]+/)[0]
logger.succeed(`${chalk.gray(`[${time}]`)} Build ${chalk.yellow(stats.hash.slice(0, 6))} finished in ${chalk.green(stats.endTime - stats.startTime)} ms!`)
if (isFirst) {
isFirst = false
console.log(`\n${chalk.gray('>')} Blogi dev server listening at ${chalk.cyan(`http://localhost:${port}${publicPath}`)}`)
}
})
compiler.hooks.invalid.tap('blogi-log', clearScreen)
}
}
function clearScreen () {
process.stdout.write('\x1Bc')
}