Skip to content

Commit

Permalink
feat(scripts): make build output style consistent
Browse files Browse the repository at this point in the history
Use the same header for error and warnings.
  • Loading branch information
swashata committed Apr 29, 2019
1 parent 3bf18dd commit b355d9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
22 changes: 14 additions & 8 deletions packages/scripts/src/bin/build.ts
Expand Up @@ -12,6 +12,9 @@ import {
resolveCWD,
watchEllipsis,
wpackLogoSmall,
printErrorHeading,
printSuccessHeading,
printWarningHeading,
} from './utils';

/**
Expand Down Expand Up @@ -53,28 +56,31 @@ export function build(options: ProgramOptions | undefined): void {
const builder: Build = new Build(projectConfig, cwd);
builder
.build()
.then(({ status, log }) => {
.then(({ status, log, warnings }) => {
if (status === 'success') {
spinner.succeed(`${wpackLogoSmall} build successful.`);
} else {
spinner.warn(`${wpackLogoSmall} built with warnings.`);
}
console.log('');
console.log(
`${chalk.bgGreenBright(
chalk.bold.hex('#000000')(' OUTPUT ')
)}`
);
console.log('');
printSuccessHeading('OUTPUT');
console.log(log);
console.log('');
if (status === 'warn' && Array.isArray(warnings)) {
printWarningHeading('WARNINGS');
warnings.forEach(w => {
console.log(w);
console.log('');
});
}
endBuildInfo();
console.log('');
process.exit(0);
})
.catch(err => {
spinner.fail(`${wpackLogoSmall} build failed.`);
printErrorHeading('ERROR');
console.error(err);
console.log('');
process.exit(1);
});
} catch (e) {
Expand Down
8 changes: 8 additions & 0 deletions packages/scripts/src/bin/utils.ts
Expand Up @@ -199,6 +199,14 @@ export function printWarningHeading(msg: string = 'WARNING'): void {
console.log('');
}

export function printSuccessHeading(msg: string = 'OUTPUT'): void {
console.log('');
console.log(
`${chalk.bgGreenBright(chalk.bold.hex('#000000')(` ${msg} `))}`
);
console.log('');
}

export const bulletSymbol = chalk.magenta(figures.pointer);

export const wpackLink = `${chalk.blue.underline('https://wpack.io')}`;
Expand Down
8 changes: 6 additions & 2 deletions packages/scripts/src/scripts/Build.ts
Expand Up @@ -23,6 +23,7 @@ export class Build {
public build(): Promise<{
status: 'error' | 'warn' | 'success';
log: string;
warnings?: string[];
}> {
return new Promise((resolve, reject) => {
const config = new CreateWebpackConfig(
Expand All @@ -47,6 +48,8 @@ export class Build {
modules: false,
builtAt: false,
timings: false,
warnings: false,
errors: false,
});

if (!messages.errors.length && !messages.warnings.length) {
Expand All @@ -57,11 +60,12 @@ export class Build {
});
}
if (messages.errors.length) {
reject(messages.errors.join('\n'));
reject(messages.errors.join('\n\n'));
}
resolve({
status: 'warn',
log: `${outputLog}\n\n${messages.warnings.join('\n')}`,
log: outputLog,
warnings: messages.warnings,
});
});
});
Expand Down

0 comments on commit b355d9d

Please sign in to comment.