1- const { basename, normalize } = require ( 'path' )
2- const { readFile : readFileCb } = require ( 'fs' )
3- const { promisify } = require ( 'util' )
4- const readFile = promisify ( readFileCb )
1+ const { basename, normalize } = require ( 'path' ) ;
2+ const { readFile : readFileCb } = require ( 'fs' ) ;
3+ const { promisify } = require ( 'util' ) ;
4+ const readFile = promisify ( readFileCb ) ;
55
6- const kolor = require ( 'kleur' )
7- const prettyBytes = require ( 'pretty-bytes' )
8- const brotliSize = require ( 'brotli-size' )
9- const gzipSize = require ( 'gzip-size' )
10- const { log } = console
11- const pkg = require ( '../package.json' )
6+ const kolor = require ( 'kleur' ) ;
7+ const prettyBytes = require ( 'pretty-bytes' ) ;
8+ const brotliSize = require ( 'brotli-size' ) ;
9+ const gzipSize = require ( 'gzip-size' ) ;
10+ const { log } = console ;
11+ const pkg = require ( '../package.json' ) ;
1212
13- main ( )
13+ main ( ) ;
1414
1515async function main ( ) {
16- const args = process . argv . splice ( 2 )
17- const filePaths = [ ...args . map ( normalize ) ]
16+ const args = process . argv . splice ( 2 ) ;
17+ const filePaths = [ ...args . map ( normalize ) ] ;
1818 const fileMetadata = await Promise . all (
1919 filePaths . map ( async ( filePath ) => {
2020 return {
2121 path : filePath ,
2222 blob : await readFile ( filePath , { encoding : 'utf8' } ) ,
23- }
24- } )
25- )
23+ } ;
24+ } ) ,
25+ ) ;
2626
2727 const output = await Promise . all (
28- fileMetadata . map ( ( metadata ) => getSizeInfo ( metadata . blob , metadata . path ) )
29- )
28+ fileMetadata . map ( ( metadata ) => getSizeInfo ( metadata . blob , metadata . path ) ) ,
29+ ) ;
3030
31- log ( getFormatedOutput ( pkg . name , output ) )
31+ log ( getFormatedOutput ( pkg . name , output ) ) ;
3232}
3333
3434/**
3535 * @param {string } pkgName
3636 * @param {string[] } filesOutput
3737 */
3838function getFormatedOutput ( pkgName , filesOutput ) {
39- const MAGIC_INDENTATION = 3
40- const WHITE_SPACE = ' ' . repeat ( MAGIC_INDENTATION )
39+ const MAGIC_INDENTATION = 3 ;
40+ const WHITE_SPACE = ' ' . repeat ( MAGIC_INDENTATION ) ;
4141
4242 return (
4343 kolor . blue ( `${ pkgName } bundle sizes: 📦` ) +
4444 `\n${ WHITE_SPACE } ` +
4545 readFile . name +
4646 filesOutput . join ( `\n${ WHITE_SPACE } ` )
47- )
47+ ) ;
4848}
4949
5050/**
@@ -54,13 +54,13 @@ function getFormatedOutput(pkgName, filesOutput) {
5454 * @param {boolean } raw
5555 */
5656function formatSize ( size , filename , type , raw ) {
57- const pretty = raw ? `${ size } B` : prettyBytes ( size )
58- const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow'
59- const MAGIC_INDENTATION = type === 'br' ? 13 : 10
57+ const pretty = raw ? `${ size } B` : prettyBytes ( size ) ;
58+ const color = size < 5000 ? 'green' : size > 40000 ? 'red' : 'yellow' ;
59+ const MAGIC_INDENTATION = type === 'br' ? 13 : 10 ;
6060
6161 return `${ ' ' . repeat ( MAGIC_INDENTATION - pretty . length ) } ${ kolor [ color ] (
62- pretty
63- ) } : ${ kolor . white ( basename ( filename ) ) } .${ type } `
62+ pretty ,
63+ ) } : ${ kolor . white ( basename ( filename ) ) } .${ type } `;
6464}
6565
6666/**
@@ -69,8 +69,8 @@ function formatSize(size, filename, type, raw) {
6969 * @param {boolean } [raw=false] Default is `false`
7070 */
7171async function getSizeInfo ( code , filename , raw = false ) {
72- const isRaw = raw || code . length < 5000
73- const gzip = formatSize ( await gzipSize ( code ) , filename , 'gz' , isRaw )
74- const brotli = formatSize ( await brotliSize . sync ( code ) , filename , 'br' , isRaw )
75- return gzip + '\n' + brotli
72+ const isRaw = raw || code . length < 5000 ;
73+ const gzip = formatSize ( await gzipSize ( code ) , filename , 'gz' , isRaw ) ;
74+ const brotli = formatSize ( await brotliSize . sync ( code ) , filename , 'br' , isRaw ) ;
75+ return gzip + '\n' + brotli ;
7676}
0 commit comments