Skip to content

Commit

Permalink
feat: support --build-delimiter for opt-in output delimiter (#192) (#340
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bitpshr authored and evenstensberg committed Mar 14, 2018
1 parent e9c6800 commit d01af47
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
7 changes: 6 additions & 1 deletion bin/process-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ module.exports = function processOptions(yargs, argv) {
if (bool) outputOptions.cachedAssets = true;
});

ifArg("build-delimiter", function(value) {
outputOptions.buildDelimiter = value;
});

if (!outputOptions.exclude && !argv["display-modules"])
outputOptions.exclude = [
"node_modules",
Expand Down Expand Up @@ -175,8 +179,9 @@ module.exports = function processOptions(yargs, argv) {
);
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : "";
process.stdout.write("\n" + new Date() + "\n" + "\n");
process.stdout.write(stats.toString(outputOptions) + "\n");
process.stdout.write(`${stats.toString(outputOptions)}\n${delimiter}`);
if (argv.s) lastHash = null;
}
if (!options.watch && stats.hasErrors()) {
Expand Down
12 changes: 11 additions & 1 deletion bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@
group: DISPLAY_GROUP,
describe:
"Controls the output of lifecycle messaging e.g. Started watching files..."
},
"build-delimiter": {
type: "string",
group: DISPLAY_GROUP,
describe: "Display custom text after build output"
}
});

Expand Down Expand Up @@ -419,6 +424,10 @@
outputOptions.infoVerbosity = value;
});

ifArg("build-delimiter", function(value) {
outputOptions.buildDelimiter = value;
});

const webpack = require("webpack");

let lastHash = null;
Expand Down Expand Up @@ -473,7 +482,8 @@
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
const statsString = stats.toString(outputOptions);
if (statsString) stdout.write(statsString + "\n");
const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : "";
if (statsString) stdout.write(`${statsString}\n${delimiter}`);
}
if (!options.watch && stats.hasErrors()) {
process.exitCode = 2;
Expand Down
1 change: 1 addition & 0 deletions test/binCases/stats/build-delimiter/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "foo";
9 changes: 9 additions & 0 deletions test/binCases/stats/build-delimiter/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
const lastLines = stdout.slice(-2);
expect(code).toBe(0);
expect(lastLines[0]).toBe("success");
expect(lastLines[1]).toBe("");
expect(stderr).toHaveLength(0);
};
3 changes: 3 additions & 0 deletions test/binCases/stats/build-delimiter/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--entry ./index.js
--display normal
--build-delimiter success

0 comments on commit d01af47

Please sign in to comment.