-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #181 from lonelyghost/ms-show-addon-sizes
Show addon dependency sizes
- Loading branch information
Showing
19 changed files
with
719 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action, get } from '@ember/object'; | ||
|
||
export default class DependencySizeComponent extends Component { | ||
@tracked isViewingDetails; | ||
@tracked isViewingOtherAssets; | ||
@tracked addonSize; | ||
|
||
get shouldShow() { | ||
let addonSize = this.args.addonSize; | ||
return addonSize && get(addonSize, 'totalSize') > 0; | ||
} | ||
|
||
@action | ||
toggleDetail(e) { | ||
e.preventDefault(); | ||
this.isViewingDetails = !this.isViewingDetails; | ||
if (!this.isViewingDetails) { | ||
this.isViewingOtherAssets = false; | ||
} | ||
} | ||
|
||
@action | ||
toggleOtherAssets(e) { | ||
e.preventDefault(); | ||
this.isViewingOtherAssets = !this.isViewingOtherAssets; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { helper } from '@ember/component/helper'; | ||
import { isEmpty } from '@ember/utils'; | ||
|
||
export function formatBytes([number]/*, hash*/) { | ||
if (isEmpty(number)) { | ||
return ''; | ||
} | ||
if (number >= Math.pow(1024, 3)) { | ||
return format(number, Math.pow(1024, 3), 'GB'); | ||
} | ||
if (number >= Math.pow(1024, 2)) { | ||
return format(number, Math.pow(1024, 2), 'MB'); | ||
} | ||
if (number >= 1024) { | ||
return format(number, 1024, 'KB'); | ||
} | ||
return `${number} B`; | ||
} | ||
|
||
function format(number, denominator, unit) { | ||
return `${parseFloat((number / denominator).toFixed(2))} ${unit}` | ||
} | ||
|
||
export default helper(formatBytes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.dependency-size { | ||
|
||
.toggle-detail { | ||
margin-left: 4px; | ||
cursor: pointer; | ||
font-family: monospace; | ||
} | ||
|
||
.size-detail { | ||
font-family: monospace; | ||
margin: 6px 0; | ||
|
||
@include media($small-screen) { | ||
margin: 10px; | ||
} | ||
} | ||
|
||
.totals { | ||
font-weight: bold; | ||
} | ||
|
||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
flex-wrap: wrap; | ||
width: 100%; | ||
margin: 8px 0; | ||
|
||
@include media($small-screen) { | ||
margin: 2px 0; | ||
|
||
&.other-assets { | ||
padding-left: 10px; | ||
} | ||
} | ||
} | ||
|
||
.column-1 { | ||
display: flex; | ||
flex-basis: 120px; | ||
} | ||
|
||
.column-2 { | ||
display: flex; | ||
flex-basis: 100%; | ||
flex-direction: column; | ||
flex: 1; | ||
|
||
@include media($small-screen) { | ||
flex-direction: row; | ||
.asset-size { | ||
padding-left: .5rem; | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{{#if this.shouldShow}} | ||
<span class="dependency-size"> | ||
<a role="button" href="#" {{on "click" this.toggleDetail}} class="test-size-summary toggle-detail"> | ||
{{format-bytes @addonSize.totalSize}} ({{format-bytes @addonSize.totalGzipSize}} gzipped) {{svg-icon (if this.isViewingDetails "expand-less" "expand-more")}} | ||
</a> | ||
|
||
{{#if this.isViewingDetails}} | ||
<div class="size-detail test-size-detail"> | ||
{{#if @addonSize.appJsSize}} | ||
<div class="row"> | ||
<div class="column-1">App JS:</div> | ||
<div class="column-2 test-app-js">{{format-bytes @addonSize.appJsSize}} <span class="asset-size">({{format-bytes @addonSize.appJsGzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/if}} | ||
{{#if @addonSize.appCssSize}} | ||
<div class="row"> | ||
<div class="column-1">App CSS:</div> | ||
<div class="column-2 test-app-css">{{format-bytes @addonSize.appCssSize}} <span class="asset-size">({{format-bytes @addonSize.appCssGzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/if}} | ||
{{#if @addonSize.vendorJsSize}} | ||
<div class="row"> | ||
<div class="column-1">Vendor JS:</div> | ||
<div class="column-2 test-vendor-js">{{format-bytes @addonSize.vendorJsSize}} <span class="asset-size">({{format-bytes @addonSize.vendorJsGzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/if}} | ||
{{#if @addonSize.vendorCssSize}} | ||
<div class="row"> | ||
<div class="column-1">Vendor CSS:</div> | ||
<div class="column-2 test-vendor-css">{{format-bytes @addonSize.vendorCssSize}} <span class="asset-size">({{format-bytes @addonSize.vendorCssGzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/if}} | ||
{{#if @addonSize.otherAssetsSize}} | ||
<div class="row"> | ||
<div class="column-1">Other Assets:</div> | ||
<div class="column-2 test-other-assets">{{format-bytes @addonSize.otherAssetsSize}} | ||
<span class="asset-size"> | ||
({{format-bytes @addonSize.otherAssetsGzipSize}} gzipped) | ||
{{#if @addonSize.hasOtherAssetsFiles}} | ||
<a role="button" href="#" class="test-other-assets-toggle toggle-detail" {{on "click" this.toggleOtherAssets}}> | ||
{{svg-icon (if this.isViewingOtherAssets "expand-less" "expand-more")}} | ||
</a> | ||
{{/if}} | ||
</span> | ||
</div> | ||
</div> | ||
{{/if}} | ||
{{#if this.isViewingOtherAssets}} | ||
{{#each @addonSize.normalizedOtherAssetFiles as |file|}} | ||
<div class="row other-assets test-other-assets-details"> | ||
<div class="column-1 test-asset-name">- {{file.name}}:</div> | ||
<div class="column-2 test-asset-size">{{format-bytes file.size}} <span class="asset-size">({{format-bytes file.gzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/each}} | ||
{{/if}} | ||
{{#if @addonSize.totalJsSize}} | ||
<div class="row totals"> | ||
<div class="column-1">Total JS:</div> | ||
<div class="column-2 test-total-js">{{format-bytes @addonSize.totalJsSize}} <span class="asset-size">({{format-bytes @addonSize.totalJsGzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/if}} | ||
{{#if @addonSize.totalCssSize}} | ||
<div class="row totals"> | ||
<div class="column-1">Total CSS:</div> | ||
<div class="column-2 test-total-css">{{format-bytes @addonSize.totalCssSize}} <span class="asset-size">({{format-bytes @addonSize.totalCssGzipSize}} gzipped)</span></div> | ||
</div> | ||
{{/if}} | ||
</div> | ||
{{/if}} | ||
</span> | ||
{{/if}} |
Oops, something went wrong.