From 3bfd7355b06da90bc9f62f38ab626972f7a3f961 Mon Sep 17 00:00:00 2001 From: Jeroen Vinke Date: Sun, 4 Mar 2018 19:04:24 +0100 Subject: [PATCH] chore(bundlereport): small fixes --- lib/build/bundle.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/build/bundle.js b/lib/build/bundle.js index 2e6e60f05..11f8061b7 100644 --- a/lib/build/bundle.js +++ b/lib/build/bundle.js @@ -261,11 +261,12 @@ exports.Bundle = class { console.log(`Writing ${bundleFileName}...`); - if (buildOptions.bundleReport) { + if (buildOptions.isApplicable('bundleReport')) { let sbuffer = []; + let jsonRep = {}; sbuffer.push('>> ' + bundleFileName + ' total size : ' + (contents.length / 1024).toFixed(2) + 'kb, containing ' + files.length + ' files'); - let sortedFiles = files.sort(function (a, b) { + let sortedFiles = files.sort((a, b) => { if (a.contents.length > b.contents.length) { return -1; } @@ -276,9 +277,17 @@ exports.Bundle = class { }); for (let i = 0; i < sortedFiles.length; ++i) { let currentFile = sortedFiles[i]; - sbuffer.push(' > ' + (currentFile.contents.length / 1024).toFixed(2) + 'kb ('+ ((currentFile.contents.length / contents.length) * 100).toFixed(2)+'%) - ' + currentFile.path ); + sbuffer.push('> ' + (currentFile.contents.length / 1024).toFixed(2) + 'kb (' + ((currentFile.contents.length / contents.length) * 100).toFixed(2) + '%) - ' + (currentFile.path || currentFile.contents.substring(0, 200))); + if (currentFile.path) { + jsonRep[currentFile.path] = jsonRep[currentFile.path] || {}; + jsonRep[currentFile.path].file = currentFile.path; + jsonRep[currentFile.path].filesize = (currentFile.contents.length / 1024).toFixed(2); + } } - fs.writeFile('bundle-report-' + bundleFileName + '.txt', sbuffer.join('\n')); + + logger.info(`Writing bundle reports for ${bundleFileName}...`); + fs.writeFile(`bundle-report-${bundleFileName}.txt`, sbuffer.join('\n')); + fs.writeFile(`bundle-report-${bundleFileName}.json`, JSON.stringify(jsonRep, null, 2)); } if (buildOptions.isApplicable('minify')) {