Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds standard output flag #1206

Merged
merged 4 commits into from
Feb 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/groups/StatsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StatsGroup extends GroupHelper {

resolveOptions() {
Object.keys(this.args).forEach(arg => {
if (['quiet', 'verbose', 'json', 'silent'].includes(arg)) {
if (['quiet', 'verbose', 'json', 'silent', 'standard'].includes(arg)) {
this.opts.outputOptions[arg] = this.args[arg];
} else {
this.opts.options[arg] = this.args[arg];
Expand Down
18 changes: 11 additions & 7 deletions lib/utils/Compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ class Compiler {
}

generateOutput(outputOptions, stats, statsErrors, processingMessageBuffer) {
const statsObj = stats.toJson(outputOptions);
if (statsObj.children && statsObj.children.length) {
statsObj.children.forEach(child => {
this.output.generateFancyOutput(child, statsErrors, processingMessageBuffer);
});
return;
if (outputOptions.standard) {
this.output.generateRawOutput(stats);
} else {
const statsObj = stats.toJson(outputOptions);
if (statsObj.children && statsObj.children.length) {
statsObj.children.forEach(child => {
this.output.generateFancyOutput(child, statsErrors, processingMessageBuffer);
});
return;
}
this.output.generateFancyOutput(statsObj, statsErrors, processingMessageBuffer);
}
this.output.generateFancyOutput(statsObj, statsErrors, processingMessageBuffer);
process.stdout.write('\n');
if (outputOptions.watch) {
logger.info('watching files for updates...');
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/CompilerOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class CompilerOutput {
return statsObj;
}

generateRawOutput() {}
generateRawOutput(stats) {
process.stdout.write(stats.toString());
}

generateJsonOutput() {}

Expand Down
7 changes: 7 additions & 0 deletions lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ module.exports = {
description: 'Prints result as JSON',
group: DISPLAY_GROUP,
},
{
name: 'standard',
usage: '--standard',
type: Boolean,
description: 'Prints standard output',
group: DISPLAY_GROUP,
},
{
name: 'dev',
usage: '--dev',
Expand Down
1 change: 1 addition & 0 deletions test/help/__snapshots__/help-single-arg.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Options
-s, --sourcemap string Determine source maps to use
--prefetch string Prefetch this request
-j, --json Prints result as JSON
--standard Prints standard output
-d, --dev Run development build
-p, --prod Run production build
--version Get current version
Expand Down
1 change: 1 addition & 0 deletions test/standard/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Test");
13 changes: 13 additions & 0 deletions test/standard/standard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { run } = require('../utils/test-utils');

describe('standard flag', () => {
it('should print standard output', () => {
const { stdout, stderr } = run(__dirname, ['--standard']);
expect(stdout).toBeTruthy();
expect(stdout).toContain('Hash');
expect(stdout).toContain('Version');
expect(stdout).toContain('Built at');
expect(stdout).toContain('Time');
expect(stderr).toBeFalsy();
});
});