From c6e0623f508b0c9d5c2b18b8550d0f90a47fa130 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 19 Jul 2018 20:51:46 -0500 Subject: [PATCH] write stats report,json into .embark --- lib/pipeline/webpackProcess.js | 50 +++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/lib/pipeline/webpackProcess.js b/lib/pipeline/webpackProcess.js index feb0dfea..b06460e9 100644 --- a/lib/pipeline/webpackProcess.js +++ b/lib/pipeline/webpackProcess.js @@ -96,18 +96,48 @@ class WebpackProcess extends ProcessWrapper { }; } - webpack(webpackOptions).run((err, stats) => { - if (err) { - console.error(err); - } - if (!detectErrors) { - return callback(); } - if (stats.hasErrors()) { - return callback(stats.toJson().errors.join("\n")); - } - callback(); + webpack(webpackOptions).run((err, stats) => { + async.waterfall([ + function checkStatsError(next) { + if (err) { + console.error(err); + return next(err); + } + if (!detectErrors) { + return next(); + } + if (stats.hasErrors()) { + return next( + stats.toJson(webpackOptions.stats).errors.join("\n") + ); + } + next(); + }, + function writeStatsReport(next) { + if (detectErrors) { + self._log('info', 'writing file '+ ('dist/stats.report').bold.dim); + } + fs.writeFile( + path.join(fs.dappPath('.embark'), 'stats.report'), + stats.toString(webpackOptions.stats), + next + ); + }, + function writeStatsJSON(next) { + if (detectErrors) { + self._log('info','writing file '+ ('dist/stats.json').bold.dim); + } + fs.writeFile( + path.join(fs.dappPath('.embark'), 'stats.json'), + JSON.stringify(stats.toJson(webpackOptions.stats)), + next + ); + } + ], (err) => { + callback(err); + }); }); } }