@@ -7,6 +7,7 @@ const fs = require('fs');
77const Jimp = require ( 'jimp' ) ;
88const Nightmare = require ( 'nightmare' ) ;
99const path = require ( 'path' ) ;
10+ const prettyHrtime = require ( 'pretty-hrtime' ) ;
1011const tmp = require ( 'tmp' ) ;
1112
1213const defaults = require ( './components-build-defaults' ) ;
@@ -38,6 +39,7 @@ const formatFromSizeToSize = (from, to) => `(${filesize(from)} => ${filesize(to)
3839
3940module . exports = _options => new Promise ( ( resolve , reject ) => {
4041 const options = _ . assign ( { } , defaults , _options ) ;
42+ const startTime = process . hrtime ( ) ;
4143 console . log ( chalk . magenta ( 'Working on components screenshots...' ) ) ;
4244 if ( options . componentsForNavPath === undefined || ! fs . existsSync ( options . componentsForNavPath ) ) {
4345 reject ( 'Can not find components nav JSON file' ) ;
@@ -74,7 +76,7 @@ module.exports = _options => new Promise((resolve, reject) => {
7476 // Grab the size of the component enclosing rectangle
7577 // https://github.com/segmentio/nightmare/issues/498#issuecomment-189156529
7678 const componentRect = yield nightmare
77- . viewport ( options . screenshotViewportWidth , options . screenshotViewportMaxHeight )
79+ . viewport ( options . screenshotViewportWidth , options . screenshotViewportHeight )
7880 // .wait(1000)
7981 . goto ( `http://localhost:${ options . serverPort } ${ component . href } ` )
8082 . wait ( selector )
@@ -101,12 +103,12 @@ module.exports = _options => new Promise((resolve, reject) => {
101103 continue ; // eslint-disable-line
102104 }
103105 const tmpObj = tmp . fileSync ( { dir : path . dirname ( component . screenshot . path ) } ) ;
104- componentRect . height = Math . min ( componentRect . height , options . screenshotViewportMaxHeight ) ;
106+ componentRect . height = Math . min ( componentRect . height , options . screenshotViewportHeight ) ;
105107 yield nightmare
106108 // we can not use .screenshot() with componentRect, so constrain the viewport instead
107109 . viewport (
108110 componentRect . width || options . screenshotViewportWidth ,
109- componentRect . height || options . screenshotViewportMaxHeight
111+ componentRect . height || options . screenshotViewportHeight
110112 ) . scrollTo ( componentRect . y , componentRect . x )
111113 // .wait(1000)
112114 // do *not* use componentRect in .screenshot() below or risk distortions
@@ -119,13 +121,13 @@ module.exports = _options => new Promise((resolve, reject) => {
119121 yield new Promise ( ( write_resolve , write_reject ) => {
120122 if ( component . frontMatter . screenshot === undefined ||
121123 component . frontMatter . screenshot . autocrop !== false ) {
122- screenshot . autocrop ( 0.0 , false ) ;
124+ screenshot . autocrop ( false ) ;
123125 }
124126 // Allow shrinking, up to a point
125- const scaleHeight = screenshot . bitmap . height <= options . screenshotFinalMinHeight
126- ? 0.0 : options . screenshotFinalMinHeight / screenshot . bitmap . height ;
127- const scaleWidth = screenshot . bitmap . width <= options . screenshotFinalMinWidth
128- ? 0.0 : options . screenshotFinalMinWidth / screenshot . bitmap . width ;
127+ const scaleHeight = screenshot . bitmap . height <= options . screenshotTargetMinHeight
128+ ? 0.0 : options . screenshotTargetMinHeight / screenshot . bitmap . height ;
129+ const scaleWidth = screenshot . bitmap . width <= options . screenshotTargetMinWidth
130+ ? 0.0 : options . screenshotTargetMinWidth / screenshot . bitmap . width ;
129131 const scale = Math . max ( scaleHeight , scaleWidth ) ;
130132 screenshot
131133 . scale ( scale > 0 ? scale : 1.0 )
@@ -152,9 +154,11 @@ module.exports = _options => new Promise((resolve, reject) => {
152154 yield nightmare . end ( ) ;
153155 server . close ( ) ;
154156 console . log ( '- Closed static HTML server' ) ;
157+ const elapsed = process . hrtime ( startTime ) ;
155158 console . log (
156159 chalk . magenta ( 'Done with components screenshots!' ) ,
157- chalk . dim ( formatFromSizeToSize ( tmpTotalFileSize , screenshotTotalFileSize ) )
160+ chalk . dim ( formatFromSizeToSize ( tmpTotalFileSize , screenshotTotalFileSize ) ) ,
161+ chalk . dim ( prettyHrtime ( elapsed ) )
158162 ) ;
159163 } ) ;
160164
0 commit comments