Skip to content

Commit

Permalink
style(textlint-bundler): fix coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Takeharu Oshida committed Feb 17, 2020
1 parent c532d09 commit 26eba92
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
23 changes: 5 additions & 18 deletions packages/textlint-bundler/lib/bundle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs');
const path = require('path');
const chalk = require('chalk');
const webpack = require('webpack');

const readPkg = () => {
Expand Down Expand Up @@ -35,27 +34,15 @@ module.exports = (flags, spinner) => {
}
const webpackConfig = createWebpackConfig(textlint.preset, flags.debug);
return new Promise((resolve, reject) => {
const webpackCallback = (err, stats) => {
webpack(webpackConfig, (err, stats) => {
spinner.clear();
if (err) {
console.error(chalk.bold.red('Error'), err.stack || err);
console.log(err.details || '');
return reject('Bundle Error')
return reject(err);
}

const info = stats.toJson();
if (stats.hasErrors()) {
console.error(chalk.bold.red('Error'), 'webpack errors');
console.log(info.errors.join(""))
return reject('Bundle stats has errors')
}

if (stats.hasWarnings()) {
console.warn(chalk.keyword('orange')('Warning'), 'webpack warnings');
console.log(chalk.keyword('gray')(info.warnings.join("")))
return reject(stats);
}
resolve()
};
webpack(webpackConfig, webpackCallback);
return resolve(stats);
});
});
}
18 changes: 15 additions & 3 deletions packages/textlint-bundler/lib/textlint-bundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,24 @@ const run = () => {
console.log(chalk.bold.white('Start Bundling...'))
const spinner = ora().start();
bundle(cli.flags, spinner)
.then(() => {
.then((stats) => {
if (stats.hasWarnings()) {
const info = stats.toJson();
console.warn(chalk.keyword('orange')('Warning'), 'webpack warnings');
console.log(chalk.keyword('gray')(info.warnings.join("")));
}
console.log(chalk.bold.green('Success'));
console.log("Run `npx http-server ./dist -o /example.html` to see example");
})
.catch((e) => {
console.log(chalk.bold.red('Error'), e);
.catch((reason) => {
if (typeof reason.hasErrors === 'function' ) {
console.error(chalk.bold.red('Error'), 'webpack errors');
const info = reason.toJson();
console.log(info.errors.join(""));
} else {
console.error(chalk.bold.red('Error'), reason.stack || reason);
console.log(reason.details || '');
}
})
.finally(() => {
spinner.stop();
Expand Down

0 comments on commit 26eba92

Please sign in to comment.