Repository: ember-cli/ember-cli
Pull request #7273 (2017-07-31 12:27:08)

Asset sizes
This is a backport of #7266 so it's hotfix-releasable.


Patch:
diff --git a/lib/commands/asset-sizes.js b/lib/commands/asset-sizes.js
index 856df9658..89c01a90e 100644
--- a/lib/commands/asset-sizes.js
+++ b/lib/commands/asset-sizes.js
@@ -7,7 +7,8 @@ module.exports = Command.extend({
   description: 'Shows the sizes of your asset files.',
 
   availableOptions: [
-    { name: 'output-path', type: 'Path', default: 'dist/', aliases: ['o'] },
+    { name: 'output-path', type: 'Path',  default: 'dist/', aliases: ['o'] },
+    { name: 'json',        type: Boolean, default: false },
   ],
 
   run(commandOptions) {
diff --git a/lib/models/asset-size-printer.js b/lib/models/asset-size-printer.js
index 4e95943c0..3832c92ab 100644
--- a/lib/models/asset-size-printer.js
+++ b/lib/models/asset-size-printer.js
@@ -36,7 +36,12 @@ class AssetPrinterSize {
     let ui = this.ui;
     return this.makeAssetSizesObject().then(files => {
       if (files.length !== 0) {
-        ui.writeLine(JSON.stringify({ files }));
+        let entries = files.map(file => ({
+          name: file.name,
+          size: file.size,
+          gzipSize: file.gzipSize,
+        }));
+        ui.writeLine(JSON.stringify({ files: entries }));
       } else {
         ui.writeLine(chalk.red(`No asset files found in the path provided: ${this.outputPath}`));
       }


Test patch:
diff --git a/tests/fixtures/help/help-with-addon.txt b/tests/fixtures/help/help-with-addon.txt
index 56aecaa35..089fcb1ea 100644
--- a/tests/fixtures/help/help-with-addon.txt
+++ b/tests/fixtures/help/help-with-addon.txt
@@ -24,6 +24,7 @@ ember asset-sizes \u001b[36m<options...>\u001b[39m
   Shows the sizes of your asset files.
   \u001b[36m--output-path\u001b[39m \u001b[36m(Path)\u001b[39m \u001b[36m(Default: dist/)\u001b[39m
     \u001b[90maliases: -o <value>\u001b[39m
+  \u001b[36m--json\u001b[39m \u001b[36m(Boolean)\u001b[39m \u001b[36m(Default: false)\u001b[39m
 
 ember build \u001b[36m<options...>\u001b[39m
   Builds your app and places it into the output path (dist/ by default).
diff --git a/tests/fixtures/help/help.js b/tests/fixtures/help/help.js
index ed57ebe13..da516a99b 100644
--- a/tests/fixtures/help/help.js
+++ b/tests/fixtures/help/help.js
@@ -88,6 +88,12 @@ module.exports = {
           required: false,
           aliases: ['o'],
           type: 'Path'
+        },
+        {
+          default: false,
+          key: 'json',
+          name: 'json',
+          required: false
         }
       ]
     },
diff --git a/tests/fixtures/help/help.txt b/tests/fixtures/help/help.txt
index b5fdeb081..28e387401 100644
--- a/tests/fixtures/help/help.txt
+++ b/tests/fixtures/help/help.txt
@@ -24,6 +24,7 @@ ember asset-sizes \u001b[36m<options...>\u001b[39m
   Shows the sizes of your asset files.
   \u001b[36m--output-path\u001b[39m \u001b[36m(Path)\u001b[39m \u001b[36m(Default: dist/)\u001b[39m
     \u001b[90maliases: -o <value>\u001b[39m
+  \u001b[36m--json\u001b[39m \u001b[36m(Boolean)\u001b[39m \u001b[36m(Default: false)\u001b[39m
 
 ember build \u001b[36m<options...>\u001b[39m
   Builds your app and places it into the output path (dist/ by default).
diff --git a/tests/fixtures/help/with-addon-blueprints.js b/tests/fixtures/help/with-addon-blueprints.js
index c9addaab7..4cda3a9f8 100644
--- a/tests/fixtures/help/with-addon-blueprints.js
+++ b/tests/fixtures/help/with-addon-blueprints.js
@@ -88,6 +88,12 @@ module.exports = {
           required: false,
           aliases: ['o'],
           type: 'Path'
+        },
+        {
+          default: false,
+          key: 'json',
+          name: 'json',
+          required: false
         }
       ]
     },
diff --git a/tests/fixtures/help/with-addon-commands.js b/tests/fixtures/help/with-addon-commands.js
index 9e967f1e6..20ac2e2cc 100644
--- a/tests/fixtures/help/with-addon-commands.js
+++ b/tests/fixtures/help/with-addon-commands.js
@@ -88,6 +88,12 @@ module.exports = {
           required: false,
           aliases: ['o'],
           type: 'Path'
+        },
+        {
+          default: false,
+          key: 'json',
+          name: 'json',
+          required: false
         }
       ]
     },
diff --git a/tests/unit/models/asset-size-printer-test.js b/tests/unit/models/asset-size-printer-test.js
index e79ab2af7..7b18259b5 100644
--- a/tests/unit/models/asset-size-printer-test.js
+++ b/tests/unit/models/asset-size-printer-test.js
@@ -123,6 +123,7 @@ describe('models/asset-size-printer', function() {
         expect(output.files[1].name).to.include('nested-asset.js');
         expect(output.files[1].size).to.equal(32);
         expect(output.files[1].gzipSize).to.equal(52);
+        expect(output.files[0]).to.not.have.property('showGzipped');
       });
   });