diff --git a/build/assets.js b/build/assets.js index 0b57c46d80..11dc05bc09 100644 --- a/build/assets.js +++ b/build/assets.js @@ -6,6 +6,8 @@ const Table = require('cli-table'); const path = require('path'); const sh = require('shelljs'); +// find all js/css files in the dist dir +// but ignore any files in lang, example, or font directories const filepaths = sh.find(path.join(__dirname, '..', 'dist', '**', '*.{js,css}')).filter(function(filepath) { if ((/\/(lang|example|font)\//).test(filepath)) { return false; @@ -14,8 +16,9 @@ const filepaths = sh.find(path.join(__dirname, '..', 'dist', '**', '*.{js,css}') return true; }); +// map all files that we found into an array of +// table entries the filepath, file size, and gzip size. Promise.all(filepaths.map(function(filepath) { - // gzip and stat return new Promise(function(resolve, reject) { const readStream = fs.createReadStream(filepath); const writeStream = fs.createWriteStream(filepath + '.gz'); @@ -25,36 +28,25 @@ Promise.all(filepaths.map(function(filepath) { const gzStat = fs.statSync(filepath + '.gz'); const fileStat = fs.statSync(filepath); - resolve({filepath, gzStat, fileStat}); + fs.unlinkSync(filepath + '.gz'); + + resolve([filepath.split('dist/')[1], filesize(fileStat.size), filesize(gzStat.size)]); }) .on('error', reject); }); -})).then(function(results) { - return Promise.all(results.map(function(result) { - return new Promise(function(resolve, reject) { - const {fileStat, gzStat, filepath} = result; +})).then(function(lines) { + // log all the files and there sizes using a cli table + const table = new Table({ + head: ['filename', 'size', 'gzipped'], + colAligns: ['left', 'right', 'right'], + style: { + border: ['white'] + } + }); - resolve([filepath.split('dist/')[1], filesize(fileStat.size), filesize(gzStat.size)]); - }); - })); -}) - .then(function(lines) { - const table = new Table({ - head: ['filename', 'size', 'gzipped'], - colAligns: ['left', 'right', 'right'], - style: { - border: ['white'] - } - }); - - table.push.apply(table, lines); - console.log(table.toString()); - - filepaths.forEach(function(filepath) { - fs.unlinkSync(filepath + '.gz'); - }); + table.push.apply(table, lines); + console.log(table.toString()); - }) - .catch(function(err) { - console.error(err.stack); - }); +}).catch(function(err) { + console.error(err.stack); +});