-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@angular/cli): rewrite stats output to properly show the asset size
This is a feature in principle; the output is changed. The stats themselves dont though.
- Loading branch information
Showing
4 changed files
with
70 additions
and
9 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
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,45 @@ | ||
import { bold, green, reset, white, yellow } from 'chalk'; | ||
import { stripIndents } from 'common-tags'; | ||
|
||
|
||
function _formatSize(size: number): string { | ||
if (size <= 0) { | ||
return '0 bytes'; | ||
} | ||
|
||
const abbreviations = ['bytes', 'kB', 'MB', 'GB']; | ||
const index = Math.floor(Math.log(size) / Math.log(1000)); | ||
|
||
return `${+(size / Math.pow(1000, index)).toPrecision(3)} ${abbreviations[index]}`; | ||
} | ||
|
||
|
||
export function statsToString(json: any, statsConfig: any) { | ||
const colors = statsConfig.colors; | ||
const r = (x: string) => colors ? reset(x) : x; | ||
const w = (x: string) => colors ? bold(white(x)) : x; | ||
const g = (x: string) => colors ? bold(green(x)) : x; | ||
const y = (x: string) => colors ? bold(yellow(x)) : x; | ||
|
||
return r(stripIndents` | ||
Date: ${w(new Date().toISOString())} | ||
Hash: ${w(json.hash)} | ||
Time: ${w('' + json.time)}ms | ||
${json.chunks.map((chunk: any) => { | ||
const asset = json.assets.filter((x: any) => x.name == chunk.files[0])[0]; | ||
const size = asset ? ` ${_formatSize(asset.size)}` : ''; | ||
const files = chunk.files.join(', '); | ||
const names = chunk.names ? ` (${chunk.names.join(', ')})` : ''; | ||
const parents = chunk.parents.map((id: string) => ` {${y(id)}}`).join(''); | ||
const initial = y(chunk.entry ? '[entry]' : chunk.initial ? '[initial]' : ''); | ||
const flags = ['rendered', 'recorded'] | ||
.map(f => f && chunk[f] ? g(` [${f}]`) : '') | ||
.join(''); | ||
return `chunk {${y(chunk.id)}} ${g(files)}${names}${size}${parents} ${initial}${flags}`; | ||
}).join('\n')} | ||
${json.warnings.map((warning: any) => y(`WARNING in ${warning}`)).join('\n\n')} | ||
${json.errors.map((error: any) => r(`ERROR in ${error}`)).join('\n')} | ||
`); | ||
} |