Skip to content

Commit b05e5eb

Browse files
authored
feat(cli): adds standard output flag (#1206)
* chore: add standard output flag to list * chore: support standard output * chore: update help snapshot * test: add test for standard
1 parent 8046490 commit b05e5eb

File tree

7 files changed

+37
-9
lines changed

7 files changed

+37
-9
lines changed

lib/groups/StatsGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class StatsGroup extends GroupHelper {
1010

1111
resolveOptions() {
1212
Object.keys(this.args).forEach(arg => {
13-
if (['quiet', 'verbose', 'json', 'silent'].includes(arg)) {
13+
if (['quiet', 'verbose', 'json', 'silent', 'standard'].includes(arg)) {
1414
this.opts.outputOptions[arg] = this.args[arg];
1515
} else {
1616
this.opts.options[arg] = this.args[arg];

lib/utils/Compiler.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ class Compiler {
6767
}
6868

6969
generateOutput(outputOptions, stats, statsErrors, processingMessageBuffer) {
70-
const statsObj = stats.toJson(outputOptions);
71-
if (statsObj.children && statsObj.children.length) {
72-
statsObj.children.forEach(child => {
73-
this.output.generateFancyOutput(child, statsErrors, processingMessageBuffer);
74-
});
75-
return;
70+
if (outputOptions.standard) {
71+
this.output.generateRawOutput(stats);
72+
} else {
73+
const statsObj = stats.toJson(outputOptions);
74+
if (statsObj.children && statsObj.children.length) {
75+
statsObj.children.forEach(child => {
76+
this.output.generateFancyOutput(child, statsErrors, processingMessageBuffer);
77+
});
78+
return;
79+
}
80+
this.output.generateFancyOutput(statsObj, statsErrors, processingMessageBuffer);
7681
}
77-
this.output.generateFancyOutput(statsObj, statsErrors, processingMessageBuffer);
7882
process.stdout.write('\n');
7983
if (outputOptions.watch) {
8084
logger.info('watching files for updates...');

lib/utils/CompilerOutput.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ class CompilerOutput {
108108
return statsObj;
109109
}
110110

111-
generateRawOutput() {}
111+
generateRawOutput(stats) {
112+
process.stdout.write(stats.toString());
113+
}
112114

113115
generateJsonOutput() {}
114116

lib/utils/cli-flags.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,13 @@ module.exports = {
256256
description: 'Prints result as JSON',
257257
group: DISPLAY_GROUP,
258258
},
259+
{
260+
name: 'standard',
261+
usage: '--standard',
262+
type: Boolean,
263+
description: 'Prints standard output',
264+
group: DISPLAY_GROUP,
265+
},
259266
{
260267
name: 'dev',
261268
usage: '--dev',

test/help/__snapshots__/help-single-arg.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Options
4141
-s, --sourcemap string Determine source maps to use
4242
--prefetch string Prefetch this request
4343
-j, --json Prints result as JSON
44+
--standard Prints standard output
4445
-d, --dev Run development build
4546
-p, --prod Run production build
4647
--version Get current version

test/standard/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Test");

test/standard/standard.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { run } = require('../utils/test-utils');
2+
3+
describe('standard flag', () => {
4+
it('should print standard output', () => {
5+
const { stdout, stderr } = run(__dirname, ['--standard']);
6+
expect(stdout).toBeTruthy();
7+
expect(stdout).toContain('Hash');
8+
expect(stdout).toContain('Version');
9+
expect(stdout).toContain('Built at');
10+
expect(stdout).toContain('Time');
11+
expect(stderr).toBeFalsy();
12+
});
13+
});

0 commit comments

Comments
 (0)