Skip to content

Commit b355d9d

Browse files
committed
feat(scripts): make build output style consistent
Use the same header for error and warnings.
1 parent 3bf18dd commit b355d9d

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

packages/scripts/src/bin/build.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import {
1212
resolveCWD,
1313
watchEllipsis,
1414
wpackLogoSmall,
15+
printErrorHeading,
16+
printSuccessHeading,
17+
printWarningHeading,
1518
} from './utils';
1619

1720
/**
@@ -53,28 +56,31 @@ export function build(options: ProgramOptions | undefined): void {
5356
const builder: Build = new Build(projectConfig, cwd);
5457
builder
5558
.build()
56-
.then(({ status, log }) => {
59+
.then(({ status, log, warnings }) => {
5760
if (status === 'success') {
5861
spinner.succeed(`${wpackLogoSmall} build successful.`);
5962
} else {
6063
spinner.warn(`${wpackLogoSmall} built with warnings.`);
6164
}
62-
console.log('');
63-
console.log(
64-
`${chalk.bgGreenBright(
65-
chalk.bold.hex('#000000')(' OUTPUT ')
66-
)}`
67-
);
68-
console.log('');
65+
printSuccessHeading('OUTPUT');
6966
console.log(log);
7067
console.log('');
68+
if (status === 'warn' && Array.isArray(warnings)) {
69+
printWarningHeading('WARNINGS');
70+
warnings.forEach(w => {
71+
console.log(w);
72+
console.log('');
73+
});
74+
}
7175
endBuildInfo();
7276
console.log('');
7377
process.exit(0);
7478
})
7579
.catch(err => {
7680
spinner.fail(`${wpackLogoSmall} build failed.`);
81+
printErrorHeading('ERROR');
7782
console.error(err);
83+
console.log('');
7884
process.exit(1);
7985
});
8086
} catch (e) {

packages/scripts/src/bin/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ export function printWarningHeading(msg: string = 'WARNING'): void {
199199
console.log('');
200200
}
201201

202+
export function printSuccessHeading(msg: string = 'OUTPUT'): void {
203+
console.log('');
204+
console.log(
205+
`${chalk.bgGreenBright(chalk.bold.hex('#000000')(` ${msg} `))}`
206+
);
207+
console.log('');
208+
}
209+
202210
export const bulletSymbol = chalk.magenta(figures.pointer);
203211

204212
export const wpackLink = `${chalk.blue.underline('https://wpack.io')}`;

packages/scripts/src/scripts/Build.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class Build {
2323
public build(): Promise<{
2424
status: 'error' | 'warn' | 'success';
2525
log: string;
26+
warnings?: string[];
2627
}> {
2728
return new Promise((resolve, reject) => {
2829
const config = new CreateWebpackConfig(
@@ -47,6 +48,8 @@ export class Build {
4748
modules: false,
4849
builtAt: false,
4950
timings: false,
51+
warnings: false,
52+
errors: false,
5053
});
5154

5255
if (!messages.errors.length && !messages.warnings.length) {
@@ -57,11 +60,12 @@ export class Build {
5760
});
5861
}
5962
if (messages.errors.length) {
60-
reject(messages.errors.join('\n'));
63+
reject(messages.errors.join('\n\n'));
6164
}
6265
resolve({
6366
status: 'warn',
64-
log: `${outputLog}\n\n${messages.warnings.join('\n')}`,
67+
log: outputLog,
68+
warnings: messages.warnings,
6569
});
6670
});
6771
});

0 commit comments

Comments
 (0)