print nice build summaries

This commit is contained in:
Rich Harris
2018-08-29 15:03:10 -04:00
parent 458be49b35
commit 6393a30b13
5 changed files with 98 additions and 16 deletions

View File

@@ -2,6 +2,7 @@ import { build as _build } from '../api/build';
import colors from 'kleur';
import { locations } from '../config';
import validate_bundler from './utils/validate_bundler';
import { repeat } from '../utils';
export function build(opts: { bundler?: string }) {
const bundler = validate_bundler(opts.bundler);
@@ -18,7 +19,20 @@ export function build(opts: { bundler?: string }) {
});
emitter.on('build', event => {
console.log(colors.inverse(`\nbuilt ${event.type}`));
let banner = `built ${event.type}`;
let c = colors.cyan;
const { warnings } = event.result;
if (warnings.length > 0) {
banner += ` with ${warnings.length} ${warnings.length === 1 ? 'warning' : 'warnings'}`;
c = colors.yellow;
}
console.log();
console.log(c(`┌─${repeat('─', banner.length)}─┐`));
console.log(c(`${colors.bold(banner) }`));
console.log(c(`└─${repeat('─', banner.length)}─┘`));
console.log(event.result.print());
});
@@ -30,8 +44,7 @@ export function build(opts: { bundler?: string }) {
fulfil();
});
} catch (err) {
console.log(`${colors.bold.red(`> ${err.message}`)}`);
process.exit(1);
reject(err);
}
});
}